YoggieEngine/SandboxApplication/Sandbox.cpp

119 lines
2.9 KiB
C++

#include "BarinkEngine.h"
#include "Scene\SceneManager.h"
#include "Scene\SceneNodeTypes.h"
#include "AssetManager/ModelImporter.h"
#include "imgui.h"
#include "GUI.h"
#include "Util.h"
/*
* Define globals
*/
Camera* cam;
Shader* shader;
char* code = new char[254];
const std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
const std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
BarinkEngine::ModelImporter* MI = new BarinkEngine::ModelImporter();
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);
// Create a cube node
// Load a model
//cube = MI->Import("build/SandboxApplication/Debug/Models/Cube.obj");
//Level1->GetRoot().addChild(*cube);
std::string groupName("Nested-Group");
auto testGroup = new Group(groupName);
Level1->GetRoot().addChild( *testGroup);
std::string group2Name("Nested-Group2");
auto testGroup2 = new Group(group2Name);
Level1->GetRoot().addChild(*testGroup2);
// Walk scene graph
PrintSceneTree(Level1->GetRoot(),0);
shader = new Shader(vertexShaderSource, fragmentShaderSource);
cam = new Camera(glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
memset(code, '\0', 254);
}
/*
* Runs every frame
* - Use to draw Immediate mode graphics (Not meant for HUD's )
*/
void ImmediateGraphicsDraw() {
ImGui::NewFrame();
// Show ImGui demo such that I can easily look
// at possible GUI elements to use
ImGui::ShowDemoWindow();
// Show internal BarinkEngine stats
ShowStats();
// Show different tooling for this specific sandbox
CameraTool(cam);
ScriptingTool(code);
SceneExplorer(*Level1, "Scene Explorer");
}
/*
* Runs every frame
* - Meant for game logic ( non-physics related)
*/
void Update()
{
/*
* NOTE: this needs to move to the renderer
* Render code should not appear in the sandbox file
*/
//glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
shader->Use();
//shader->setUniformMat4("P", projection);
//shader->setUniformMat4("M", CalculateModelMat(cube->transform));
shader->setUniformMat4("V", cam->GetViewMatrix());
//cube->renderable->material->Apply();
//Cube->Draw();
}
/*
* Runs at the end of the program
* - Meant for cleanup
*/
void Stop() {
delete MI;
delete shader;
}