Skip to content

Commit

Permalink
Zephyr: Scene: require explicit function calls to modify transform sc…
Browse files Browse the repository at this point in the history
…ale and position
  • Loading branch information
fleroviux committed May 24, 2024
1 parent b6251b8 commit 58c5569
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions app/next/src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace zephyr {

const u8* key_state = SDL_GetKeyboardState(nullptr);

Vector3& camera_position = m_camera_node->GetTransform().GetPosition();
Vector3 camera_position = m_camera_node->GetTransform().GetPosition();
const f32 delta_p = 0.075f;
const f32 delta_r = 0.01f;
if(key_state[SDL_SCANCODE_W]) camera_position -= m_camera_node->GetTransform().GetLocal().Z().XYZ() * delta_p;
Expand All @@ -86,6 +86,7 @@ namespace zephyr {
if(key_state[SDL_SCANCODE_RIGHT]) euler_y -= delta_r;
if(key_state[SDL_SCANCODE_UP]) euler_x += delta_r;
if(key_state[SDL_SCANCODE_DOWN]) euler_x -= delta_r;
m_camera_node->GetTransform().SetPosition(camera_position);
m_camera_node->GetTransform().GetRotation().SetFromEuler(euler_x, euler_y, 0.0f);

RenderFrame();
Expand Down Expand Up @@ -170,21 +171,21 @@ namespace zephyr {

m_camera_node = m_scene_root->CreateChild("RenderCamera");
m_camera_node->CreateComponent<PerspectiveCameraComponent>(45.0f, 16.f / 9.f, 0.01f, 100.f);
m_camera_node->GetTransform().GetPosition() = {0.f, 0.f, 5.f};
m_camera_node->GetTransform().SetPosition({0.f, 0.f, 5.f});

GLTFLoader gltf_loader{};
std::shared_ptr<SceneNode> gltf_scene_1 = gltf_loader.Parse("models/DamagedHelmet/DamagedHelmet.gltf");
gltf_scene_1->GetTransform().GetPosition() = {1.0f, 0.0f, -5.0f};
gltf_scene_1->GetTransform().SetPosition({1.0f, 0.0f, -5.0f});
gltf_scene_1->GetTransform().GetRotation().SetFromEuler(1.5f, 0.0f, 0.0f);
m_scene_root->Add(std::move(gltf_scene_1));

m_scene_root->Add(gltf_loader.Parse("models/triangleWithoutIndices/TriangleWithoutIndices.gltf"));
//m_scene_root->Add(gltf_loader.Parse("models/triangle/Triangle.gltf"));

m_behemoth_scene = gltf_loader.Parse("models/Behemoth/scene.gltf");
m_behemoth_scene->GetTransform().GetPosition() = Vector3{-1.0f, 0.0f, -5.0f};
m_behemoth_scene->GetTransform().SetPosition({-1.0f, 0.0f, -5.0f});
m_behemoth_scene->GetTransform().GetRotation().SetFromEuler(-M_PI * 0.5, M_PI, 0.0f);
m_behemoth_scene->GetTransform().GetScale() = {0.5f, 0.5f, 0.5f};
m_behemoth_scene->GetTransform().SetScale({0.5f, 0.5f, 0.5f});
m_scene_root->Add(m_behemoth_scene);
}

Expand All @@ -194,7 +195,7 @@ namespace zephyr {
// TODO(fleroviux): engine crashes when there is no camera in the scene! VERY BAD!!!
m_camera_node = m_scene_root->CreateChild("RenderCamera");
m_camera_node->CreateComponent<PerspectiveCameraComponent>(45.0f, 16.f / 9.f, 0.01f, 100.f);
m_camera_node->GetTransform().GetPosition() = {0.f, 0.f, 5.f};
m_camera_node->GetTransform().SetPosition({0.f, 0.f, 5.f});

// TODO(fleroviux): fix cube geometry is rendered incorrectly.

Expand Down Expand Up @@ -269,8 +270,8 @@ namespace zephyr {
for(int z = -grid_size / 2; z < grid_size / 2; z++) {
std::shared_ptr<SceneNode> cube = m_scene_root->CreateChild("Cube");
cube->CreateComponent<MeshComponent>(cube_geometry, std::shared_ptr<Material>{});
cube->GetTransform().GetPosition() = {(f32)x, (f32)y, (f32)-z};
cube->GetTransform().GetScale() = {0.1, 0.1, 0.1};
cube->GetTransform().SetPosition({(f32)x, (f32)y, (f32)-z});
cube->GetTransform().SetScale({0.1, 0.1, 0.1});
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions zephyr/scene/include/zephyr/scene/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ namespace zephyr {
return m_position;
}

[[nodiscard]] Vector3& GetPosition() {
return m_position;
void SetPosition(const Vector3& position) {
m_position = position;
}

[[nodiscard]] const Vector3& GetScale() const {
return m_scale;
}

[[nodiscard]] Vector3& GetScale() {
return m_scale;
void SetScale(const Vector3& scale) {
m_scale = scale;
}

[[nodiscard]] const Rotation& GetRotation() const {
Expand Down

0 comments on commit 58c5569

Please sign in to comment.