Skip to content

Commit

Permalink
Use mvp matrix for render scene
Browse files Browse the repository at this point in the history
  • Loading branch information
dorosch committed Sep 8, 2022
1 parent d6db67c commit 951d70b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 29 deletions.
6 changes: 3 additions & 3 deletions include/core/ecs/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ namespace Engine {
public:
Type type = Type::TRANSFORM;

glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 rotation = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 scale = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 position = glm::vec3(1.0f, 1.0f, 1.0f);
glm::vec3 rotation = glm::vec3(1.0f, 1.0f, 1.0f);
glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f);
};


Expand Down
46 changes: 26 additions & 20 deletions include/core/geometry/primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,34 @@ namespace Engine {
name = std::string("Cube");

mesh->vertices = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
-0.5f, 0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, -0.0f,
0.5f, -0.5f, -0.0f,
-0.5f, 0.5f, -0.0f,
0.5f, 0.5f, -0.0f
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
// back
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, -1.0
};
mesh->indices = {
2, 6, 7,
2, 3, 7,
0, 4, 5,
0, 1, 5,
0, 2, 6,
0, 4, 6,
1, 3, 7,
1, 5, 7,
0, 2, 3,
0, 1, 3,
4, 6, 7,
4, 5, 7
0, 1, 2,
2, 3, 0,
// right
1, 5, 6,
6, 2, 1,
// back
7, 6, 5,
5, 4, 7,
// left
4, 0, 3,
3, 7, 4,
// bottom
4, 5, 1,
1, 0, 4,
// top
3, 2, 6,
6, 7, 3
};
mesh->Initialize();
}
Expand Down
2 changes: 1 addition & 1 deletion include/core/render/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Engine {
void SetBackendAPI(Backend);
void Startup();
void Shutdown();
void RenderScene(Engine::Scene::Scene *);
void RenderScene(Engine::Scene::Scene *, glm::mat4);
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion include/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ namespace Engine {

app->Update();
app->editor->Update();
app->render->RenderScene(app->scene);
// TODO: Uncomment after move camera as part of scene
// app->render->RenderScene(app->scene);
app->window->Update();
}

Expand Down
2 changes: 1 addition & 1 deletion include/meta.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __META_HPP__
#define __META_HPP__

#define ENGINE_VERSION "0.0.9"
#define ENGINE_VERSION "0.1.0"
#define GLSL_VERSION "#version 330"

#endif
9 changes: 8 additions & 1 deletion src/core/render/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ void Render::Shutdown() {
}


void Render::RenderScene(Engine::Scene::Scene *scene) {
void Render::RenderScene(Engine::Scene::Scene *scene, glm::mat4 MVP) {
// TODO: Only for opengl backend

for (std::shared_ptr<Object> object : scene->root->entities) {
if (object->HasComponent(Ecs::Component::Type::MESH)) {
// TODO: If object hasn't own shader component
shader->Use();
shader->UniformPosition(
"transform_position",
object->transform->position[0],
object->transform->position[1],
object->transform->position[2]
);
shader->UniformMatrix("MVP", MVP);

object->mesh->VAO->bind();
glDrawElements(GL_TRIANGLES, object->mesh->indices.size(), GL_UNSIGNED_INT, 0);
Expand Down
8 changes: 6 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,12 @@ class UserApplication : public Engine::EngineApplication {
// this->scene->root->children.push_back(mp5);
// this->scene->root->children.push_back(tank);

std::shared_ptr<Engine::Geometry::Plane> plane = std::make_shared<Engine::Geometry::Plane>();
scene->root->entities.push_back(plane);
std::shared_ptr<Engine::Geometry::Cube> cube = std::make_shared<Engine::Geometry::Cube>();
scene->root->entities.push_back(cube);
std::shared_ptr<Engine::Geometry::Cube> cube2 = std::make_shared<Engine::Geometry::Cube>();
scene->root->entities.push_back(cube2);

GLFWwindow *window = static_cast<Engine::Window::GLFWWindowProvider*>(this->window)->object;
glfwSetMouseButtonCallback(window, mouse_button_callback);
Expand All @@ -642,6 +646,8 @@ class UserApplication : public Engine::EngineApplication {
view = camera.GetViewMatrix();
projection = glm::perspective(glm::radians(camera.Zoom), (float)screenWidth/(float)screenHeight, 0.1f, 1000.0f);

render->RenderScene(scene, projection * view);

// Draw skybox
glDepthFunc(GL_LEQUAL);
skyboxShader->Use();
Expand All @@ -668,8 +674,6 @@ class UserApplication : public Engine::EngineApplication {

void Shutdown() {
logger->trace(std::string("Shutdown"));

delete this->debugAxes;
}
};

Expand Down

0 comments on commit 951d70b

Please sign in to comment.