2022-05-28 11:32:17 +00:00
|
|
|
#include "BarinkEngine.h"
|
2022-05-28 19:19:16 +00:00
|
|
|
#include "imgui.h"
|
2022-05-28 16:49:08 +00:00
|
|
|
using namespace BarinkEngine;
|
2022-05-28 11:32:17 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
Camera* cam;
|
|
|
|
Renderable* Cube;
|
2022-05-28 19:19:16 +00:00
|
|
|
Renderable* Cube2;
|
2022-05-28 11:32:17 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
char* code = new char[254];
|
2022-05-04 21:25:18 +00:00
|
|
|
|
2022-05-04 09:10:26 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
void PrintSceneTree(SceneNode& 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;
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
depth++;
|
|
|
|
for (auto child : node.children) {
|
|
|
|
PrintSceneTree(*child, depth);
|
|
|
|
}
|
|
|
|
}
|
2022-05-04 21:25:18 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
|
|
|
|
void Start() {
|
|
|
|
|
|
|
|
SceneNode MyCube = SceneNode();
|
|
|
|
MyCube.name = "MyCube";
|
|
|
|
|
|
|
|
SceneNode MyBaby = SceneNode();
|
|
|
|
MyBaby.name = "Baby";
|
|
|
|
|
|
|
|
SceneNode MySecondCube = SceneNode();
|
|
|
|
MySecondCube.name = "MySecondCube";
|
|
|
|
|
|
|
|
|
|
|
|
MyCube.addChild(MyBaby);
|
|
|
|
|
|
|
|
|
|
|
|
Scene scene = Scene("My awesome Game Scene");
|
|
|
|
scene.GetRoot().addChild(MyCube);
|
|
|
|
scene.GetRoot().addChild(MySecondCube);
|
|
|
|
|
|
|
|
|
|
|
|
// Walk scene graph
|
|
|
|
PrintSceneTree(scene.GetRoot(),0);
|
|
|
|
|
|
|
|
Cube = Renderable::Load();
|
|
|
|
Cube2 = Renderable::Load();
|
|
|
|
Cube->addChild(*Cube2);
|
|
|
|
|
|
|
|
cam = new Camera(glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
|
|
|
|
|
|
|
memset(code, '\0', 254);
|
2022-05-04 13:27:42 +00:00
|
|
|
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
}
|
2022-05-13 19:59:19 +00:00
|
|
|
|
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
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 ImmediateGraphicsDraw() {
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Camera");
|
|
|
|
|
|
|
|
ImGui::SliderFloat("Zoom:", &cam->Zoom, 10, 190);
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
|
|
transformWindow(Cube->transform, "Transform (Cube)");
|
|
|
|
|
|
|
|
transformWindow(Cube2->transform, "Transform (Cube2)");
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Scripting!!");
|
|
|
|
|
|
|
|
ImGui::InputTextMultiline("Lua Script", code, 255);
|
|
|
|
bool runCode = ImGui::Button("Run");
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::ShowDemoWindow();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 CalculateModelMat(Transform& transform) {
|
|
|
|
|
|
|
|
glm::mat4 tran = glm::translate(glm::mat4(), transform.Position);
|
|
|
|
glm::mat4 scale = glm::scale(glm::mat4(), transform.Scale);
|
2022-05-28 16:49:08 +00:00
|
|
|
glm::mat4 rot =
|
2022-05-28 19:19:16 +00:00
|
|
|
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));
|
2022-05-13 19:59:19 +00:00
|
|
|
|
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
return tran * rot * scale;
|
|
|
|
}
|
2022-05-04 12:39:27 +00:00
|
|
|
|
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
|
|
|
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
|
|
|
Shader shader = Shader(vertexShaderSource, fragmentShaderSource);
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2022-05-13 19:59:19 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
shader.Use();
|
|
|
|
shader.setUniformMat4("P", projection);
|
|
|
|
shader.setUniformMat4("M", CalculateModelMat(Cube->transform));
|
|
|
|
shader.setUniformMat4("V", cam->GetViewMatrix());
|
|
|
|
shader.setUniformVec3("MatColour", glm::vec3(1.0f, 0.0f, 0.0f));
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
Cube->Draw();
|
2022-05-04 09:10:26 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
shader.setUniformMat4("M", CalculateModelMat(Cube2->transform));
|
|
|
|
shader.setUniformVec3("MatColour", glm::vec3(0.0f, 1.0f, 0.0f));
|
|
|
|
|
|
|
|
Cube2->Draw();
|
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
}
|
2022-05-04 09:10:26 +00:00
|
|
|
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-28 16:49:08 +00:00
|
|
|
void Stop() {
|
2022-05-04 12:39:27 +00:00
|
|
|
// Cleanup
|
2022-05-28 16:49:08 +00:00
|
|
|
Cube->VAO.Delete();
|
|
|
|
Cube->elementBuffer.Delete();
|
2022-04-20 19:40:35 +00:00
|
|
|
|
2022-05-28 19:19:16 +00:00
|
|
|
Cube2->VAO.Delete();
|
|
|
|
Cube2->elementBuffer.Delete();
|
|
|
|
|
|
|
|
delete Cube2;
|
2022-05-28 16:49:08 +00:00
|
|
|
delete Cube;
|
|
|
|
}
|