Skip to content

Commit

Permalink
Working light and did some fixes (#70)
Browse files Browse the repository at this point in the history
* Merged mesh factory branch to main

* Working Vertex buffer class that replaces vk::VulkanModel to contains the vertices of the mesh

* Working index buffers and added mesh class that contains both the vertex and index buffers

* Working mesh class can also now load 3D models and work with new vertex and index buffers as well

* Working diffuse shading and fake point lighting working, with some modifications to the renderer instead of taking a vector, it takes in an unordered_map for ease of use when rendering

* Fixed error with float, small fix

* Udating editor scene and a bit of the renderer

---------

Co-authored-by: ZacharyH777 <[email protected]>
  • Loading branch information
SpinnerX and ZacharyH777 authored Nov 24, 2024
1 parent cd93009 commit 403996f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
26 changes: 19 additions & 7 deletions Editor/Editor/EditorScene.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "EditorScene.hpp"
#include "Core/GraphicDrivers/VertexBuffer.hpp"
#include "Math/Math.hpp"
#include <Core/SceneManagment/Components/SPComps/Transform.hpp>
#include <Core/EngineLogger.hpp>
#include <Core/SceneManagment/Components/SPComps/EditorCamera.hpp>
#include <Core/TimeManagement/UpdateManagers/SyncUpdateManager.hpp>
#include <Math/Interpolation.hpp>
#include <Core/ApplicationInstance.hpp>
#include <Core/Event/InputPoll.hpp>
#include <glm/trigonometric.hpp>

namespace engine3d{
EditorScene::EditorScene(){
Expand All @@ -17,7 +19,10 @@ namespace engine3d{
// auto cube_mesh = CreateCubeMesh({.0f, .0f, .0f});

//! @note Instead of loading in primitive cubes by hand, we load in .obj's instead.
auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/smooth_vase.obj");
// auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/smooth_vase.obj");
// auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/FinalBaseMesh.obj");
// auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/Castelia City.obj");
auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/bugatti.obj");
// auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/colored_cube.obj");
// auto cube_mesh = Mesh::LoadModel("3d_models/tutorial/sphere.obj");
//! @note Make this scene object as part of our current scene.
Expand All @@ -29,6 +34,7 @@ namespace engine3d{
m_CameraObject->AddComponent<EditorCamera>();
auto& camera_transform = m_CameraObject->SceneGetComponent<Transform>();
camera_transform.m_Position = {-1.f, -2.f, -20.f};
// camera_transform.m_AxisRotation = {glm::radians(180.0f), 0.f, 0.f};
auto camera = m_CameraObject->SceneGetComponent<EditorCamera>();
m_CameraObjects.push_back(m_CameraObject);

Expand All @@ -39,7 +45,9 @@ namespace engine3d{
SceneObject* cube1 = new SceneObject(m_Scene);
auto& cube1_transform = cube1->SceneGetComponent<Transform>();
cube1_transform.m_Position = {.0f, .0f, 2.5};
cube1_transform.m_Scale = {10.5f, 10.5f, 10.5};
cube1_transform.m_Scale = {.5f, .5f, .5f};
// cube1_transform.m_AxisRotation = ToQuat(glm::vec3(glm::radians(180.0f), 0.f, 0.f));
cube1_transform.m_AxisRotation = {glm::radians(180.0f), 0.0f, 0.0f};
cube1->SetMesh(cube_mesh);

// -----------------------------
Expand All @@ -63,7 +71,7 @@ namespace engine3d{

//! @note Then we add them to our vector.
m_SceneObjects.push_back(cube1);
m_SceneObjects.push_back(cube2);
// m_SceneObjects.push_back(cube2);
m_PointLightObjects.push_back(sphere_point_light);

m_AllSceneObjecs.insert({"SceneObjects", m_SceneObjects});
Expand All @@ -82,7 +90,7 @@ namespace engine3d{
// float tempDt_Y;
glm::vec2 temp_position = {0.f, 0.f};
constexpr float sensitivity = 2.0f;
constexpr float pos_sensitivity = 2.f;
float pos_sensitivity = 2.f;
constexpr glm::vec2 invert_pos = {1, -1};
glm::vec3 rotate{0};

Expand Down Expand Up @@ -116,8 +124,12 @@ namespace engine3d{
if(InputPoll::IsKeyPressed(ENGINE_KEY_S)) move_dir -= forward_dir; // BACKWARD
if(InputPoll::IsKeyPressed(ENGINE_KEY_D)) move_dir += right_dir; // RIGHT
if(InputPoll::IsKeyPressed(ENGINE_KEY_A)) move_dir -= right_dir; // LEFT
if(InputPoll::IsKeyPressed(ENGINE_KEY_E)) move_dir += up_dir; // UP
if(InputPoll::IsKeyPressed(ENGINE_KEY_Q)) move_dir -= up_dir; // DOWN
if(InputPoll::IsKeyPressed(ENGINE_KEY_SPACE)) move_dir += up_dir; // UP
if(InputPoll::IsKeyPressed(ENGINE_KEY_LEFT_SHIFT)) move_dir -= up_dir; // DOWN

if(InputPoll::IsMousePressed(ENGINE_MOUSE_BUTTON_MIDDLE)){
pos_sensitivity += (m_MousePosition.y - InputPoll::GetMouseY()) * invert_pos.x;
}

if(glm::dot(move_dir, move_dir) > std::numeric_limits<float>::epsilon()){
transform.m_Position += m_MoveSpeed * (SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime) * glm::normalize(move_dir) * pos_sensitivity;
Expand All @@ -126,7 +138,7 @@ namespace engine3d{
camera.SetViewXYZ(transform.m_Position, transform.m_AxisRotation);


camera.SetPerspectiveProjection(glm::radians(50.f), ApplicationInstance::GetWindow().GetAspectRatio(), 0.1f, 100.f);
camera.SetPerspectiveProjection(glm::radians(50.f), ApplicationInstance::GetWindow().GetAspectRatio(), 0.1f, 1000.f);

}
};
2 changes: 1 addition & 1 deletion Editor/Editor/EditorScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace engine3d{
Scene* m_Scene;
// SceneObject* m_CameraObject;
glm::vec2 m_MousePosition;
float m_MoveSpeed = {3.f};
float m_MoveSpeed = {5.f};
float m_LookSpeed = {1.5f};
};
};
12 changes: 12 additions & 0 deletions engine3d/Math/Math.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/quaternion.hpp>

namespace engine3d{
// glm::quat<glm::vec2> ToQuat()
glm::vec4 ToQuat(glm::vec3 p_EulerAngles);
};
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ add_library(
${ENGINE_SRC_DIR}/Core/Renderer/Renderer.cpp

${ENGINE_SRC_DIR}/Math/Interpolation.cpp
${ENGINE_SRC_DIR}/Math/Math.cpp

${ENGINE_SRC_DIR}/Physics/JoltHandler.cpp
)
2 changes: 1 addition & 1 deletion src/engine3d/Core/ApplicationInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace engine3d{
g_ThisInstance = this;
g_DebugName = p_DebugName;
SetCurrentAPI(VULKAN);
m_Window = Window::Create(900, 600, p_DebugName);
m_Window = Window::Create(1960, 1080, p_DebugName);

// ImGui_ImplVulkanH_Window();
// ImGui_ImplGlfw_InitForVulkan(ApplicationInstance::GetWindow().GetNativeWindow(), true);
Expand Down
3 changes: 2 additions & 1 deletion src/engine3d/Core/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ namespace engine3d{
SimplePushConstantData push = {
.Transform = proj_view * model_matrix,
.ModelMatrix = model_matrix,
.LightTransform = position
.LightTransform = position - obj->SceneGetComponent<Transform>().m_Position
// .LightTransform = position
};

vkCmdPushConstants(
Expand Down
16 changes: 16 additions & 0 deletions src/engine3d/Math/Math.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <Math/Math.hpp>

namespace engine3d{
glm::vec4 ToQuat(glm::vec3 p_EulerAngles){
glm::vec4 quaternion;
glm::vec3 c = glm::cos(p_EulerAngles * float(0.5));
glm::vec3 s = glm::sin(p_EulerAngles * float(0.5));

quaternion.w = c.x * c.y * c.z + s.x * s.y * s.z;
quaternion.x = s.x * c.y * c.z - c.x * s.y * s.z;
quaternion.y = c.x * s.y * c.z + s.x * c.y * s.z;
quaternion.z = c.x * c.y * s.z - s.x * s.y * c.z;

return quaternion;
}
};

0 comments on commit 403996f

Please sign in to comment.