Adding / organizing the workspace into multple seperate projects
This commit is contained in:
		
							
								
								
									
										85
									
								
								SandboxApp/src/GUI.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								SandboxApp/src/GUI.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,85 @@
 | 
			
		||||
#include "GUI.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void SceneExplorer(const std::string& PanelName) {
 | 
			
		||||
    ImGui::Begin(PanelName.c_str()); 
 | 
			
		||||
        //if (ImGui::ListBoxHeader("##ObjectList")) {
 | 
			
		||||
            //Node& current = scene.GetRoot();
 | 
			
		||||
 | 
			
		||||
           //Node* next = ¤t;
 | 
			
		||||
 | 
			
		||||
           // Show first node
 | 
			
		||||
           //ImGui::Selectable(next->name.c_str(), true);
 | 
			
		||||
           // ImGui::Selectable("Scene Node", true);
 | 
			
		||||
            // ImGui::Indent();
 | 
			
		||||
 | 
			
		||||
             /*
 | 
			
		||||
 | 
			
		||||
             if (next->children.size() != 0) {
 | 
			
		||||
                 for (auto child : next->children)
 | 
			
		||||
                 {
 | 
			
		||||
                     std::string& name = child->name;
 | 
			
		||||
                     ImGui::Selectable(name.c_str(), false);
 | 
			
		||||
                 }
 | 
			
		||||
             }
 | 
			
		||||
 | 
			
		||||
             */
 | 
			
		||||
 | 
			
		||||
         //   ImGui::ListBoxFooter();
 | 
			
		||||
        // }
 | 
			
		||||
    ImGui::End();
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
void CameraTool() {
 | 
			
		||||
    static float Zoom = 0;
 | 
			
		||||
    static glm::vec3 Position = glm::vec3(0.0f, 0.0f, 0.0f);
 | 
			
		||||
    static glm::vec3 Rotation = glm::vec3(0.0f, 0.0f, 0.0f);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    ImGui::Begin("Camera");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    ImGui::SliderFloat("Zoom:", &Zoom, 10, 190);
 | 
			
		||||
 | 
			
		||||
    ImGui::InputFloat3("Position:", &Position[0]);
 | 
			
		||||
 | 
			
		||||
    ImGui::InputFloat3("Rotation:", &Rotation[0]);
 | 
			
		||||
 | 
			
		||||
    ImGui::End();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ScriptingTool(char* code) {
 | 
			
		||||
    ImGui::Begin("Scripting");
 | 
			
		||||
 | 
			
		||||
    ImGui::Text("Lua Code");
 | 
			
		||||
    ImGui::InputTextMultiline("##", code, 255);
 | 
			
		||||
    bool runCode = ImGui::Button("Run");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    ImGui::End();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SceneView(Framebuffer& framebuffer ) {
 | 
			
		||||
    ImGui::Begin("Viewport");
 | 
			
		||||
        ImGui::Image((void*)(intptr_t)framebuffer.GetColourAttachment(), ImVec2{800, 600});
 | 
			
		||||
    ImGui::End();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void transformWindow(Transform& transform, std::string PanelName) {
 | 
			
		||||
    ImGui::Begin(PanelName.c_str());
 | 
			
		||||
    ImGui::InputFloat3("Position:", (float*)&transform.Position[0]);
 | 
			
		||||
    ImGui::InputFloat3("Rotation:", (float*)&transform.Rotation[0]);
 | 
			
		||||
    ImGui::InputFloat3("Scale:", (float*)&transform.Scale[0]);
 | 
			
		||||
    ImGui::End();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void materialWindow(Material& material, std::string PanelName) {
 | 
			
		||||
    ImGui::Begin(PanelName.c_str());
 | 
			
		||||
    ImGui::ColorPicker3("Color:", &material.Color[0]);
 | 
			
		||||
    ImGui::End();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										102
									
								
								SandboxApp/src/Sandbox.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								SandboxApp/src/Sandbox.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,102 @@
 | 
			
		||||
#include "../../BarinkEngine/src/BarinkEngine.h"
 | 
			
		||||
#include "../../BarinkEngine/src/Scene/SceneManager.h"
 | 
			
		||||
#include "../../BarinkEngine/src/Scene/SceneNodeTypes.h"
 | 
			
		||||
#include "../../BarinkEngine/src/AssetManager/ModelImporter.h"
 | 
			
		||||
#include "../../BarinkEngine/src/Graphics/Framebuffer.h"
 | 
			
		||||
#include <imgui.h>
 | 
			
		||||
#include "GUI.h"
 | 
			
		||||
#include "Util.h"
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
* Define globals
 | 
			
		||||
*/
 | 
			
		||||
Shader* shader;
 | 
			
		||||
 | 
			
		||||
char* code = new char[254];
 | 
			
		||||
 | 
			
		||||
const std::string vertexShaderSource = "build/Debug/test.vs";
 | 
			
		||||
const std::string fragmentShaderSource = "build/Debug/test.fs";
 | 
			
		||||
 | 
			
		||||
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
 | 
			
		||||
Framebuffer* framebuffer;
 | 
			
		||||
Scene* Level1;
 | 
			
		||||
BarinkEngine::SceneObject* cube;
 | 
			
		||||
/*
 | 
			
		||||
* Runs once at startup 
 | 
			
		||||
* - USe to initialize the game/sandbox/demo
 | 
			
		||||
*/
 | 
			
		||||
void Start() {
 | 
			
		||||
    // Build a basic test scene 
 | 
			
		||||
    // NOTE: This will later be done through an editor 
 | 
			
		||||
 | 
			
		||||
    // Create a level and load it as the current level
 | 
			
		||||
    std::string levelName("Test Level");
 | 
			
		||||
    Level1 = SceneManager::CreateScene(levelName);
 | 
			
		||||
    SceneManager::LoadScene(*Level1);
 | 
			
		||||
    
 | 
			
		||||
    shader = new Shader(vertexShaderSource, fragmentShaderSource);
 | 
			
		||||
 | 
			
		||||
    // Create a cube node
 | 
			
		||||
   
 | 
			
		||||
    cube = MI->Import("build/Debug/Models/cube.obj");
 | 
			
		||||
    cube->renderable->material = new Material(*shader);
 | 
			
		||||
    cube->renderable->material->Color = glm::vec3(1.0f, 0.0f, 0.0f);
 | 
			
		||||
 | 
			
		||||
    // What is in cube now ??    
 | 
			
		||||
    std::cout <<  "mesh vertices: " << cube->renderable->mesh->vertices.size() << std::endl;
 | 
			
		||||
    std::cout << "mesh elements: " << cube->renderable->mesh->elements.size() << std::endl;
 | 
			
		||||
 | 
			
		||||
    Level1->GetRoot().addChild(*cube);
 | 
			
		||||
 | 
			
		||||
    memset(code, '\0', 254);
 | 
			
		||||
    framebuffer = new Framebuffer();
 | 
			
		||||
 | 
			
		||||
    std::cout << "Colour attachment id; "<< framebuffer->GetColourAttachment() << std::endl;
 | 
			
		||||
    // TODO: Move to runtime/ Engine 
 | 
			
		||||
    // NOTE: Submits should later be done through walking the sceneTree
 | 
			
		||||
   
 | 
			
		||||
    renderer.Submit(cube->renderable);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
* Runs every frame
 | 
			
		||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
 | 
			
		||||
*/
 | 
			
		||||
void ImmediateGraphicsDraw() 
 | 
			
		||||
{
 | 
			
		||||
    // Show internal BarinkEngine stats
 | 
			
		||||
    ShowStats();
 | 
			
		||||
    SceneView(*framebuffer);   
 | 
			
		||||
    
 | 
			
		||||
    // Show different tooling for this specific sandbox
 | 
			
		||||
    CameraTool();
 | 
			
		||||
    ScriptingTool(code);
 | 
			
		||||
 | 
			
		||||
    SceneExplorer( "Scene Explorer");
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
* Runs every frame
 | 
			
		||||
* - Meant for game logic ( non-physics related) 
 | 
			
		||||
*/
 | 
			
		||||
void Update()
 | 
			
		||||
{
 | 
			
		||||
   // glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GetId());
 | 
			
		||||
    
 | 
			
		||||
    renderer.Render(*framebuffer);
 | 
			
		||||
   
 | 
			
		||||
 //   glBindFramebuffer(GL_FRAMEBUFFER, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
* Runs at the end of the program
 | 
			
		||||
* - Meant for cleanup
 | 
			
		||||
*/
 | 
			
		||||
void Stop()
 | 
			
		||||
{
 | 
			
		||||
    delete framebuffer;
 | 
			
		||||
    delete MI;
 | 
			
		||||
    delete shader;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								SandboxApp/src/Util.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								SandboxApp/src/Util.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
#include "Util.h"
 | 
			
		||||
 | 
			
		||||
void PrintSceneTree(Node& node, int depth) {
 | 
			
		||||
    // Indent name based on depth
 | 
			
		||||
    std::cout << " ";
 | 
			
		||||
    for (int i = 0; i < depth; i++) {
 | 
			
		||||
        std::cout << "-";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::cout << " " << node.name << std::endl;
 | 
			
		||||
 | 
			
		||||
    depth++;
 | 
			
		||||
    for (auto child : node.children) {
 | 
			
		||||
        PrintSceneTree(*child, depth);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
glm::mat4 CalculateModelMat(Transform& transform) {
 | 
			
		||||
 | 
			
		||||
    glm::mat4 tran = glm::translate(glm::mat4(), transform.Position);
 | 
			
		||||
    glm::mat4 scale = glm::scale(glm::mat4(), transform.Scale);
 | 
			
		||||
    glm::mat4 rot =
 | 
			
		||||
        glm::rotate(glm::mat4(), glm::radians(transform.Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) *
 | 
			
		||||
        glm::rotate(glm::mat4(), glm::radians(transform.Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) *
 | 
			
		||||
        glm::rotate(glm::mat4(), glm::radians(transform.Rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    return tran * rot * scale;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user