Skip to content

Commit

Permalink
Working camera component with the cube object, and added viewport to …
Browse files Browse the repository at this point in the history
…get a perfect cube rendering added into the renderer
  • Loading branch information
SpinnerX committed Nov 22, 2024
1 parent e163e8a commit ae1c6ab
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 232 deletions.
3 changes: 2 additions & 1 deletion Editor/Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace engine3d{

void EditorApplication::OnApplicationUpdate(){
//! @note Handle Events.
// m_EditorScene->OnCameraUpdate();
m_EditorScene->OnUpdate();
// m_EditorScene->OnMoveCamUpdate();
auto& objects = m_EditorScene->GetSceneObjects();
Renderer::RecordSceneGameObjects(objects);
}
Expand Down
128 changes: 0 additions & 128 deletions Editor/Editor/EditorComponents/EditorCamera.cpp

This file was deleted.

74 changes: 0 additions & 74 deletions Editor/Editor/EditorComponents/EditorCamera.hpp

This file was deleted.

50 changes: 41 additions & 9 deletions Editor/Editor/EditorScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
#include <Core/SceneManagment/Components/SPComps/Transform.hpp>
#include <Core/internal/Vulkan2Showcase/VulkanModel.hpp>
#include <Core/EngineLogger.hpp>
#include <Core/SceneManagment/Components/SPComps/EditorCamera.hpp>
#include <Core/TimeManagement/UpdateManagers/SyncUpdateManager.hpp>
#include <Core/ApplicationInstance.hpp>
#include <Core/Event/InputPoll.hpp>

namespace engine3d{
Ref<vk::VulkanModel> CreateCubeMesh(glm::vec3 offset){
std::vector<vk::VulkanModel::Vertex> vertices{
// left face (white)
{{-.5f, -.5f, -.5f}, {.9f, .9f, .9f}},
{{-.5f, .5f, .5f}, {.9f, .9f, .9f}},
{{-.5f, -.5f, .5f}, {.9f, .9f, .9f}},
{{-.5f, -.5f, -.5f}, {.9f, .9f, .9f}},
{{-.5f, .5f, -.5f}, {.9f, .9f, .9f}},
{{-.5f, .5f, .5f}, {.9f, .9f, .9f}},
// left Face (white)
vk::VulkanModel::Vertex{.Position{-.5f, -.5f, -.5f}, .Color{.9f, .9f, .9f}},
vk::VulkanModel::Vertex{.Position{-.5f, .5f, .5f}, .Color{.9f, .9f, .9f}},
vk::VulkanModel::Vertex{.Position ={-.5f, -.5f, .5f}, .Color{.9f, .9f, .9f}},
vk::VulkanModel::Vertex{.Position ={-.5f, -.5f, -.5f},.Color {.9f, .9f, .9f}},
vk::VulkanModel::Vertex{.Position ={-.5f, .5f, -.5f}, .Color{.9f, .9f, .9f}},
vk::VulkanModel::Vertex{.Position ={-.5f, .5f, .5f}, .Color{.9f, .9f, .9f}},

// right face (yellow)
{{.5f, -.5f, -.5f}, {.8f, .8f, .1f}},
Expand Down Expand Up @@ -61,10 +65,11 @@ namespace engine3d{
return CreateRef<vk::VulkanModel>(vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
}


EditorScene::EditorScene(){
m_Scene = new Scene();

// SyncUpdateManager::GetInstance()->Subscribe(this, &EditorScene::OnUpdate);

auto cube_mesh = CreateCubeMesh({.0f, .0f, .0f});

//! @note Make this scene object as part of our current scene.
Expand All @@ -78,20 +83,47 @@ namespace engine3d{
//! @note Setting our properties
auto& transform = cube->SceneGetComponent<Transform>();

cube->AddComponent<EditorCamera>();

auto& camera = cube->SceneGetComponent<EditorCamera>();
// camera.SetInitialProperties(30.0f, 0.1f, 1000.0f);
// camera.SetView(glm::vec3(0.f), glm::vec3(0.5f, 0.f, 1.f));
auto aspect_ratio = ApplicationInstance::GetWindow().GetAspectRatio();
// camera.SetOrthoProjection(-1, 1, -1, 1, -1, 1);

//! @note Shows the actual cube in center of screen that works
//! @note Because z = -20.f your gonna want to increase the near clip by 100.0f
camera.SetViewTarget({-1.f, -2.f, -20.f}, {0.f, 0.f, 2.5f});

// negative-float closer, positive-float z further
transform.m_Position = {.0f, .0f, .75f};
// transform.m_Position = {.0f, .0f, .75f};
transform.m_Position = {.0f, .0f, 2.5f};
// transform.m_Scale = {.5f, .5f, 0.5};
transform.m_Scale = {.5f, .5f, 0.5};
// cube->SetModel(cube_mesh);
cube->SetModal(cube_mesh);

//! @note Then we add them to our vector.
m_SceneObjects.push_back(cube);

}

void EditorScene::OnCreate(){
}

void EditorScene::OnUpdate(){
// glm::vec3 m_MoveDirection{0.f};
// glm::vec3 m_Rotation{0};

for(const auto& obj : m_SceneObjects){
// auto& transform_compoent = obj->SceneGetComponent<Transform>();
auto& camera_component = obj->SceneGetComponent<EditorCamera>();
camera_component.SetPerspectiveProjection(glm::radians(50.f), ApplicationInstance::GetWindow().GetAspectRatio(), 0.1f, 100.f);
}
}

void EditorScene::OnMoveCamUpdate(){}

// void EditorScene::OnCameraUpdate(){
// for(const auto& obj : m_SceneObjects){
// obj->SceneGetComponent<EditorCamera>().OnUpdate();
Expand Down
6 changes: 6 additions & 0 deletions Editor/Editor/EditorScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ namespace engine3d{

void OnCreate();

void OnUpdate();

void OnMoveCamUpdate();

std::vector<SceneObject*>& GetSceneObjects() { return m_SceneObjects; }

private:
std::vector<SceneObject*> m_SceneObjects;
Scene* m_Scene;
float m_MoveSpeed = {3.f};
float m_LookSpeed = {1.5f};
};
};
21 changes: 21 additions & 0 deletions engine3d/Core/SceneManagment/Components/SPComps/EditorCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ namespace engine3d{
EditorCamera(const std::string& p_Tag);

void SetInitialProperties(float p_Fov, float p_NearClip, float p_FarClip);

// ---------------------
//! @note From tutorial.
// ---------------------
void SetOrthoProjection(float left, float right, float top, float bottom, float near, float far);
void SetPerspectiveProjection(float fovy, float aspect, float near, float far);

//! @note Used to get camera to view at a specific direction
void SetViewDirection(glm::vec3 Position, glm::vec3 Direction, glm::vec3 Up = glm::vec3(0.f, -1.f, 0.f));

//! @note Used to get the camera to view at a specific target.
void SetViewTarget(glm::vec3 Position, glm::vec3 Target, glm::vec3 Up = glm::vec3(0.f, -1.f, 0.f));

//! @note Euler angles to specify the rotation of transforms for orienting the camera.
void SetViewXYZ(glm::vec3 Position, glm::vec3 Rotation);
// ---------------------
//! @note From tutorial.
// ---------------------



void OnUpdate();

//! @note Eventually we will refer to OnIntegrate as OnCreate or OnPlay or something.
Expand Down
2 changes: 2 additions & 0 deletions engine3d/Core/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace engine3d{
uint32_t GetWidth() const;
uint32_t GetHeight() const;
std::string GetTitle() const;

float GetAspectRatio() const;
void OnUpdateAllFrames();

protected:
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ add_library(

# Special Component Includes
${ENGINE_INCLUDE_NAME}/Core/SceneManagment/Components/SPComps/Transform.hpp
${ENGINE_INCLUDE_NAME}/Core/SceneManagment/Components/SPComps/EditorCamera.hpp

# Renderer Includes
${ENGINE_INCLUDE_NAME}/Core/Renderer/Renderer.hpp
Expand Down Expand Up @@ -105,6 +106,7 @@ add_library(
${ENGINE_SRC_DIR}/Core/ApplicationManager/GameObjManager/UUID.cpp

${ENGINE_SRC_DIR}/Core/SceneManagment/Components/SPComps/Transform.cpp
${ENGINE_SRC_DIR}/Core/SceneManagment/Components/SPComps/EditorCamera.cpp

${ENGINE_SRC_DIR}/Core/Renderer/Renderer.cpp

Expand Down
Loading

0 comments on commit ae1c6ab

Please sign in to comment.