Skip to content

Commit

Permalink
Removed unecessary commented code and added back the rotation to make…
Browse files Browse the repository at this point in the history
… sure some of the transforms work properly still after these modifications
  • Loading branch information
SpinnerX committed Nov 21, 2024
1 parent 97573bc commit a13fee5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 220 deletions.
126 changes: 0 additions & 126 deletions Editor/Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,144 +7,18 @@

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}},
// right face (yellow)
{{.5f, -.5f, -.5f}, {.8f, .8f, .1f}},
{{.5f, .5f, .5f}, {.8f, .8f, .1f}},
{{.5f, -.5f, .5f}, {.8f, .8f, .1f}},
{{.5f, -.5f, -.5f}, {.8f, .8f, .1f}},
{{.5f, .5f, -.5f}, {.8f, .8f, .1f}},
{{.5f, .5f, .5f}, {.8f, .8f, .1f}},
// top face (orange, remember y axis points down)
{{-.5f, -.5f, -.5f}, {.9f, .6f, .1f}},
{{.5f, -.5f, .5f}, {.9f, .6f, .1f}},
{{-.5f, -.5f, .5f}, {.9f, .6f, .1f}},
{{-.5f, -.5f, -.5f}, {.9f, .6f, .1f}},
{{.5f, -.5f, -.5f}, {.9f, .6f, .1f}},
{{.5f, -.5f, .5f}, {.9f, .6f, .1f}},
// bottom face (red)
{{-.5f, .5f, -.5f}, {.8f, .1f, .1f}},
{{.5f, .5f, .5f}, {.8f, .1f, .1f}},
{{-.5f, .5f, .5f}, {.8f, .1f, .1f}},
{{-.5f, .5f, -.5f}, {.8f, .1f, .1f}},
{{.5f, .5f, -.5f}, {.8f, .1f, .1f}},
{{.5f, .5f, .5f}, {.8f, .1f, .1f}},
// nose face (blue)
{{-.5f, -.5f, 0.5f}, {.1f, .1f, .8f}},
{{.5f, .5f, 0.5f}, {.1f, .1f, .8f}},
{{-.5f, .5f, 0.5f}, {.1f, .1f, .8f}},
{{-.5f, -.5f, 0.5f}, {.1f, .1f, .8f}},
{{.5f, -.5f, 0.5f}, {.1f, .1f, .8f}},
{{.5f, .5f, 0.5f}, {.1f, .1f, .8f}},
// tail face (green)
{{-.5f, -.5f, -0.5f}, {.1f, .8f, .1f}},
{{.5f, .5f, -0.5f}, {.1f, .8f, .1f}},
{{-.5f, .5f, -0.5f}, {.1f, .8f, .1f}},
{{-.5f, -.5f, -0.5f}, {.1f, .8f, .1f}},
{{.5f, -.5f, -0.5f}, {.1f, .8f, .1f}},
{{.5f, .5f, -0.5f}, {.1f, .8f, .1f}},
};
for (auto& v : vertices) {
v.Position += offset;
}
return CreateRef<vk::VulkanModel>(vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
}
*/


EditorApplication::EditorApplication(const std::string& p_DebugName) : ApplicationInstance(p_DebugName) {
GlobalUpdateManager::GetInstance()->SubscribeApplicationUpdate(this, &EditorApplication::OnApplicationUpdate);
// Ref<vk::VulkanModel> m_CubeMesh = CreateCubeMesh({.0f, .0f, .0f});


// auto cube = SceneObjectTutorial::Create();
// cube.SetModel(m_CubeMesh);
// cube.GetTransform().Translation = {.0f, .0f, .5f};
// cube.GetTransform().scale = {.5f, .5f, .5f};

// m_SceneGameObjects.push_back(cube);

// ConsoleLogError("m_SceneGameObjects.size() === {}", m_SceneGameObjects.size());
m_EditorScene = new EditorScene();


// m_GravitySystem = GravityPhysicsSystem(0.81f);
// m_SquareMesh = CreateSquareMesh({0.5f, 0.5f});

// //! @note Create Physics Circle Mesh
// m_CircleMesh = CreateCircleMesh(64);

// // Creating a red circle.
// auto red = SceneObject::Create();
// red.GetTransform().scale = glm::vec2{.05f};
// red.GetTransform().Translation = {.5f, .5f};
// red.SetColor({1.f, 0.f, 0.f});
// red.RigidBodyComponent.velocity = {-.5f, .0f};
// red.SetModel(m_CircleMesh);

// m_SceneGameObjects.push_back(red);

// //! @note Creating a blue circle.
// auto blue = SceneObject::Create();
// blue.GetTransform().scale = glm::vec2{.05f};
// blue.GetTransform().Translation = {-.45f, -.25f};
// blue.SetColor({0.f, 0.f, 1.f});
// blue.RigidBodyComponent.velocity = {-.5f, .0f};
// blue.SetModel(m_CircleMesh);

// m_SceneGameObjects.push_back(blue);


// // create vector field
// // std::vector<SceneObject> vectorField{};
// int gridCount = 40;
// for (int i = 0; i < gridCount; i++) {
// for (int j = 0; j < gridCount; j++) {
// auto vf = SceneObject::Create();
// vf.GetTransform().scale = glm::vec2(0.005f);
// vf.GetTransform().Translation = {
// -1.0f + (i + 0.5f) * 2.0f / gridCount,
// -1.0f + (j + 0.5f) * 2.0f / gridCount};
// vf.SetColor(glm::vec3(1.0f));
// // vf.model = m_SquareMesh;
// vf.SetModel(m_SquareMesh);
// m_VectorFields.push_back(vf);
// }
// }
}

EditorApplication::~EditorApplication() {
}

void EditorApplication::OnApplicationUpdate(){
//! @note Handle Events.
// m_GravitySystem.update(m_SceneGameObjects, 5);
// m_VectorFieldSystem.update(m_GravitySystem, m_SceneGameObjects, m_VectorFields);
auto& objects = m_EditorScene->GetSceneObjects();
Renderer::RecordSceneGameObjects(objects);
// Renderer::RecordGameObjects(m_SceneGameObjects);
// Renderer::RecordGameObjects(m_VectorFields);


// if(InputPoll::IsKeyPressed(ENGINE_KEY_ESCAPE)){
// exit(0);
// }
}

ApplicationInstance* InitializeApplication(){
Expand Down
4 changes: 0 additions & 4 deletions Editor/Editor/EditorScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ namespace engine3d{
//! @note Setting our properties
auto& transform = cube->SceneGetComponent<Transform>();

if(cube->HasComponent<Transform>()){
ConsoleLogInfo("Transform Component found!");
}

transform.m_Position = {.0f, .0f, .5f};
transform.m_Scale = {.5f, .5f, .5f};
// cube->SetModel(cube_mesh);
Expand Down
5 changes: 5 additions & 0 deletions engine3d/Core/SceneManagment/SceneObjects/SceneObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ namespace engine3d
m_ParentScene == other.m_ParentScene;
}

glm::vec3 GetRotation();
void SetRotation(const glm::vec3& p_Rotation);

void SetPosition(const glm::vec3& p_Position);

bool operator!=(const SceneObject &other) const { return !(*this == other); }

UUID GetUUID() { return objectID; }
Expand Down
90 changes: 6 additions & 84 deletions src/engine3d/Core/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ namespace engine3d{
static VkPipelineLayout g_PipelineLayout;
static VkPipeline g_Pipeline;

// static std::vector<SceneObject> g_GameObjects;

//! @note Push Constants to apply data to the shaders.
//! @note vk::VulkanModal is how shaders are going to be
struct SimplePushConstantData{
glm::mat4 Transform{1.f};
// glm::vec2 Offsets;
glm::vec2 iResolution;
alignas(16) glm::vec3 Color;
};
Expand All @@ -57,8 +56,6 @@ namespace engine3d{
.flags = 0,
.setLayoutCount = 0,
.pSetLayouts = nullptr,
// .pushConstantRangeCount = 0,
// .pPushConstantRanges = nullptr,
.pushConstantRangeCount = 1,
.pPushConstantRanges = &push_const_range
};
Expand All @@ -77,9 +74,6 @@ namespace engine3d{
ConsoleLogError("NOT AN ERROR: Shader Loaded Successfully!");





//! @note Initializing Command buffers.
g_CommandBuffers.resize(ApplicationInstance::GetWindow().GetCurrentSwapchain()->GetImagesSize());

Expand All @@ -105,41 +99,6 @@ namespace engine3d{
vk::vk_check(vkAllocateCommandBuffers(vk::VulkanContext::GetDriver(), &cmd_buffer_alloc_info, g_CommandBuffers.data()), "vkAllocateCommandBuffers", __FILE__, __LINE__, __FUNCTION__);

ConsoleLogInfo("CommandBuffers Size === {}", g_CommandBuffers.size());

//--------------------------------------------
//! @note Loading Game Objectts Here
//--------------------------------------------
// std::vector<vk::VulkanModel::Vertex> triangle_vertices = {
// {.Position={0.0f, -0.5f}, .Color = {1.0f, 0.0f, 0.0f}},
// {.Position ={0.5f, 0.5f}, .Color = {0.0f, 1.0f, 0.0f}},
// {.Position ={-0.5f, 0.5f}, .Color = {0.0f, 0.0f, 1.0f}}
// };
// // vk::VulkanModel model = vk::VulkanModel(triangle_vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
// auto model = CreateRef<vk::VulkanModel>(triangle_vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
// auto triangle = SceneObject::Create();
// triangle.SetModel(model);

// //! @note Push Constants is pretty much how we can modify data without needing to record command buffers again.

// // g_GameObjects.push_back(std::move(triangle));
// std::vector<glm::vec3> colors{
// {1.f, .7f, .73f},
// {1.f, .87f, .73f},
// {1.f, 1.f, .73f},
// {.73f, 1.f, .8f},
// {.73, .88f, 1.f} //
// };

//! @note Loading 40 triangles.
// for(int i = 0; i < 40; i++){
// auto triangle = SceneObject::Create();
// triangle.SetModel(model);
// triangle.m_Transform2D.scale = glm::vec2(.5f) + i * 0.0025f;
// triangle.m_Transform2D.rotation = glm::pi<float>() * .00002f;
// triangle.SetColor(colors[i % colors.size()]);
// g_GameObjects.push_back(triangle);
// }

}

void Renderer::SetBackgroundColor(const std::array<float, 4>& p_Rgba){
Expand Down Expand Up @@ -178,47 +137,6 @@ namespace engine3d{
return cmd_buffer;
}

void Renderer::RecordCommandBuffers(VkCommandBuffer p_CommandBuffer){
//! @note We can probably add this into Shader::Bind()
//! @note Usage: m_Shader.Bind(m_CommandBuffers[i]);
/*
int i = 0;
for(auto& obj : g_GameObjects){
i += 1;
obj.m_Transform2D.rotation = glm::mod<float>(obj.m_Transform2D.rotation + 0.001f * i, 2.f * glm::pi<float>());
}
//! @note Essentially doing m_Pipeline->Bind(m_CommandBuffer[i])
//! @note Starts when to start rendering!!
vkCmdBindPipeline(p_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Shader->GetGraphicsPipeline());
//! @note Only for testing purposes for mesh data.
for(auto& obj : g_GameObjects){
obj.m_Transform2D.rotation = glm::mod(obj.GetTransform().rotation + 0.001f, glm::two_pi<float>());
SimplePushConstantData push = {
.Transform = obj.GetTransform().mat2(),
// .Transform = glm::mod(obj.GetTransform().rotation * 0.1f, glm::two_pi<float>()),
.Offsets = obj.GetTransform().Translation,
.Color = obj.GetColor(),
};
vkCmdPushConstants(
p_CommandBuffer,
g_PipelineLayout,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
0,
sizeof(SimplePushConstantData),
&push
);
obj.GetModel()->Bind(p_CommandBuffer);
obj.GetModel()->Draw(p_CommandBuffer);
}
*/
}

void Renderer::RecordGameObjects(std::vector<SceneObjectTutorial>& p_Objects){
auto current_cmd_buffer = GetCurrentCommandBuffer();
//! @note Essentially doing m_Pipeline->Bind(m_CommandBuffer[i])
Expand Down Expand Up @@ -257,6 +175,10 @@ namespace engine3d{
//! @note Only for testing purposes for mesh data.
for(auto& obj : p_Objects){
// obj.m_Transform2D.rotation.y = glm::mod(obj.GetTransform().rotation.y + 0.001f, glm::two_pi<float>());
float x = obj->GetRotation().x;
float y = glm::mod(obj->GetRotation().y + 0.001f, glm::two_pi<float>());
float z = obj->GetRotation().z;
obj->SetRotation({x, y, z});

SimplePushConstantData push = {
// .Transform = obj.GetTransform().mat4(),
Expand Down
18 changes: 12 additions & 6 deletions src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
#include <Core/SceneManagment/SceneObjects/SceneObject.hpp>
#include <Core/SceneManagment/Components/SPComps/Transform.hpp>
#include "EngineLogger.hpp"

namespace engine3d {
SceneObject::SceneObject(entt::entity handle, Scene *scene)
: SceneObjectHandler(handle), m_ParentScene(scene)
{
AddComponent<Transform>();
auto transform_component = SceneGetComponent<Transform>();
ConsoleLogInfo("(Init) transform_component.m_Position = ({}, {}, {})", transform_component.m_Position.x, transform_component.m_Position.y, transform_component.m_Position.z);
}

SceneObject::SceneObject(Scene *scene)
{
m_ParentScene = scene;
SceneObjectHandler = scene->m_SceneRegistry.create();
ConsoleLogInfo("Entity Registered");
AddComponent<Transform>();
}

void SceneObject::SetPosition(const glm::vec3& p_Position){
SceneGetComponent<Transform>().m_Position = p_Position;
}

void SceneObject::SetRotation(const glm::vec3& p_Rotation){
SceneGetComponent<Transform>().m_AxisRotation = p_Rotation;
}

glm::vec3 SceneObject::GetRotation(){
return SceneGetComponent<Transform>().m_AxisRotation;
}

glm::mat4 SceneObject::toMat4(){
auto transform_component = SceneGetComponent<Transform>();

ConsoleLogInfo("(toMat4) transform_component.m_Position = ({}, {}, {})", transform_component.m_Position.x, transform_component.m_Position.y, transform_component.m_Position.z);

auto transform = glm::translate(glm::mat4{1.f}, transform_component.m_Position);
transform = glm::rotate(transform, transform_component.m_AxisRotation.y, {0.f, 1.f, 0.f});
transform = glm::rotate(transform, transform_component.m_AxisRotation.x, {1.f, 0.f, 0.f});
Expand Down

0 comments on commit a13fee5

Please sign in to comment.