From be58eedc64555136d1a1d5bd14a1e28422f0412f Mon Sep 17 00:00:00 2001 From: ZacharyH777 <93843297+ZacharyH777@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:53:54 -0800 Subject: [PATCH] Camera(sorta) and physics working on screen! (#73) * Connected the physics to the renderer. * Got the physics running with the visuals, correctly this time! * Failed to get camera working but am on the right track! --------- Co-authored-by: ZacharyH777 <143478753+ZHowe1@users.noreply.github.com> --- CMakeLists.txt | 2 +- Editor/Editor/EditorScene.cpp | 19 +- TestApp/CMakeLists.txt | 4 + .../Components/Bodies/BodyContainer.hpp | 29 ++- .../Components/Bodies/Shapes/BoxShaper.hpp | 4 +- .../Components/Bodies/Shapes/SphereShaper.hpp | 4 +- .../Assets/Components/Camera/CameraFollow.hpp | 16 ++ .../Components/Physics/PhysicsBody3D.hpp | 6 +- .../WorldInstances/ShowCaseWorldInstance.hpp | 2 + .../Components/Bodies/BodyContainer.cpp | 72 +++++++- .../Components/Bodies/Shapes/BoxShaper.cpp | 24 +-- .../Components/Bodies/Shapes/SphereShaper.cpp | 24 +-- .../Assets/Components/Camera/CameraFollow.cpp | 81 ++++++++ .../Components/Physics/PhysicsBody3D.cpp | 62 +++---- .../src/Scenes/Assets/Components/testComp.cpp | 36 ++++ .../WorldInstances/ShowCaseWorldInstance.cpp | 174 ++++++++++-------- .../Components/GameComponent.hpp | 3 +- .../Components/SPComps/Transform.hpp | 174 +++++++++++++++++- engine3d/Physics/JoltHandler.hpp | 5 - sim_shader_transforms/simple_shader.vert | 5 +- sim_shader_transforms/simple_shader.vert.spv | Bin 2356 -> 2616 bytes .../Components/SPComps/Transform.cpp | 37 ---- .../SceneObjects/SceneObject.cpp | 18 +- src/engine3d/Physics/JoltHandler.cpp | 12 -- 24 files changed, 583 insertions(+), 230 deletions(-) create mode 100644 TestApp/Scenes/Assets/Components/Camera/CameraFollow.hpp create mode 100644 TestApp/src/Scenes/Assets/Components/Camera/CameraFollow.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 661df3a..60611d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,6 @@ set(ENGINE_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/engine3d) find_package(tinyobjloader REQUIRED) build_library( - DIRECTORIES src Editor TestApp + DIRECTORIES src TestApp #Editor LINK_LIBRARIES tinyobjloader::tinyobjloader ) \ No newline at end of file diff --git a/Editor/Editor/EditorScene.cpp b/Editor/Editor/EditorScene.cpp index 62ec118..4c82c30 100644 --- a/Editor/Editor/EditorScene.cpp +++ b/Editor/Editor/EditorScene.cpp @@ -33,7 +33,7 @@ namespace engine3d{ SceneObject* m_CameraObject = new SceneObject(m_Scene); m_CameraObject->AddComponent(); auto& camera_transform = m_CameraObject->GetComponent(); - camera_transform.m_Position = {-1.f, 5.f, -20.f}; + camera_transform.SetPos( {-1.f, 5.f, -20.f}); // camera_transform.m_AxisRotation = {glm::radians(180.0f), 0.f, 0.f}; auto camera = m_CameraObject->GetComponent(); m_CameraObjects.push_back(m_CameraObject); @@ -44,7 +44,7 @@ namespace engine3d{ // ----------------------------- SceneObject* cube1 = new SceneObject(m_Scene); auto& cube1_transform = cube1->GetComponent(); - cube1_transform.m_Position = {.0f, .0f, 2.5}; + cube1_transform.SetPos( {.0f, .0f, 2.5}); cube1_transform.m_Scale = {10.5f, 10.5f, 10.5f}; // cube1_transform.m_AxisRotation = ToQuat(glm::vec3(glm::radians(180.0f), 0.f, 0.f)); cube1_transform.m_AxisRotation = { @@ -59,7 +59,7 @@ namespace engine3d{ SceneObject* cube2 = new SceneObject(m_Scene); auto& cube2_transform = cube2->GetComponent(); // auto aspect_ratio = ApplicationInstance::GetWindow().GetAspectRatio(); - cube2_transform.m_Position = {5.f, .0f, -7.f}; + cube2_transform.SetPos( {5.f, .0f, -7.f}); cube2_transform.m_Scale = {5.5f, 5.5f, 5.5}; cube2->SetMesh(cube_mesh); @@ -67,7 +67,7 @@ namespace engine3d{ SceneObject* sphere_point_light = new SceneObject(m_Scene); Mesh mesh = Mesh::LoadModel("3d_models/tutorial/sphere.obj"); auto& sphere_transform = sphere_point_light->GetComponent(); - sphere_transform.m_Position = {-10.0, 3.0, -1.0}; + sphere_transform.SetPos( {-10.0, 3.0, -1.0}); sphere_transform.m_Scale = {1.f, 1.f, 1.f}; sphere_point_light->SetMesh(mesh); @@ -134,11 +134,16 @@ namespace engine3d{ pos_sensitivity += (m_MousePosition.y - InputPoll::GetMouseY()) * invert_pos.x; } - if(glm::dot(move_dir, move_dir) > std::numeric_limits::epsilon()){ - transform.m_Position += m_MoveSpeed * (SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime) * glm::normalize(move_dir) * pos_sensitivity; + if(glm::dot(move_dir, move_dir) > std::numeric_limits::epsilon()) + { + transform.SetPos( + transform.GetPos() + + m_MoveSpeed * + (SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime) * + glm::normalize(move_dir) * pos_sensitivity); } - camera.SetViewXYZ(transform.m_Position, transform.m_AxisRotation); + camera.SetViewXYZ(transform.GetPos(), transform.m_AxisRotation); camera.SetPerspectiveProjection(glm::radians(50.f), ApplicationInstance::GetWindow().GetAspectRatio(), 1.f, 1000.f); diff --git a/TestApp/CMakeLists.txt b/TestApp/CMakeLists.txt index e67064a..fc69316 100644 --- a/TestApp/CMakeLists.txt +++ b/TestApp/CMakeLists.txt @@ -30,6 +30,10 @@ build_demos( Scenes/Assets/WorldInstances/ShowCaseWorldInstance.hpp src/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.cpp + #Camera + Scenes/Assets/Components/Camera/CameraFollow.hpp + src/Scenes/Assets/Components/Camera/CameraFollow.cpp + #Graphics Scenes/Assets/Components/Graphics/SpriteRender3D.hpp src/Scenes/Assets/Components/Graphics/SpriteRender3D.cpp diff --git a/TestApp/Scenes/Assets/Components/Bodies/BodyContainer.hpp b/TestApp/Scenes/Assets/Components/Bodies/BodyContainer.hpp index 8b13b3e..78dbc16 100644 --- a/TestApp/Scenes/Assets/Components/Bodies/BodyContainer.hpp +++ b/TestApp/Scenes/Assets/Components/Bodies/BodyContainer.hpp @@ -1,12 +1,37 @@ +#pragma once // #include +#include "Physics/Interfaces/BPLayerInterfaceHandler.hpp" +#include +#include #include // Jolt Includes +#include +#include +#include +#include +#include +//Other includes +#include class BodyContainer { public: - BodyContainer(); + BodyContainer() = default; + ~BodyContainer(); operator JPH::BodyID() { return m_BodyID; } - JPH::BodyCreationSettings m_BodySettings; + JPH::BodyCreationSettings* m_BodySettings = nullptr; JPH::BodyID m_BodyID; + + void CreateRotatedType(JPH::Vec3 p_Rot); + void CreateScaledType(JPH::Vec3 p_Scale); + void CreateCompoundType(JPH::Vec3 p_Rot, JPH::Vec3 p_Scale); + JPH::BodyID CreateBody(EActivation p_ActivationType ,JPH::RVec3 p_Position); + + protected: + Shape* BaseShape = nullptr; + Shape* ParentShape = nullptr; + JPH::EMotionType m_MotionType = EMotionType::Static; + JPH::ObjectLayer m_LayerType = Engine3DLayers::Static; + + }; \ No newline at end of file diff --git a/TestApp/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp b/TestApp/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp index 5ec67a1..4dd0386 100644 --- a/TestApp/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp +++ b/TestApp/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp @@ -1,6 +1,8 @@ +#pragma once #include class BoxShaper : public BodyContainer { public: - BoxShaper(); + BoxShaper() = delete; + BoxShaper(JPH::EMotionType p_MotionType, const JPH::ObjectLayer p_LayerType); }; \ No newline at end of file diff --git a/TestApp/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp b/TestApp/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp index 472f82d..48f1427 100644 --- a/TestApp/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp +++ b/TestApp/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp @@ -1,6 +1,8 @@ +#pragma once #include class SphereShaper : public BodyContainer { public: - SphereShaper(); + SphereShaper() = delete; + SphereShaper(JPH::EMotionType p_MotionType, const JPH::ObjectLayer p_LayerType); }; \ No newline at end of file diff --git a/TestApp/Scenes/Assets/Components/Camera/CameraFollow.hpp b/TestApp/Scenes/Assets/Components/Camera/CameraFollow.hpp new file mode 100644 index 0000000..682b446 --- /dev/null +++ b/TestApp/Scenes/Assets/Components/Camera/CameraFollow.hpp @@ -0,0 +1,16 @@ +#pragma once +#include +#include + +class CameraFollow : public engine3d::GameComponent +{ + public: + CameraFollow()=delete; + CameraFollow(engine3d::Transform &p_transform); + + void OnIntegrate(); + void LateUpdate(); + private: + engine3d::Transform* m_PlayerTransform; + engine3d::Transform* m_Transform; +}; \ No newline at end of file diff --git a/TestApp/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp b/TestApp/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp index 4b4fc6c..70cf13b 100644 --- a/TestApp/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp +++ b/TestApp/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp @@ -21,9 +21,9 @@ class PhysicsBody3D: public engine3d::GameComponent void Begin(); BodyContainer* GetBody(); - void SetScale(float x, float y, float z); - void SetPosition(float x, float y, float z); - void SetRotation(Quat quaternion); + void ForcedSetScale(float x, float y, float z); + void ForcedSetPosition(float x, float y, float z); + void ForcedSetRotation(Quat quaternion); private: engine3d::Transform* m_Transform; diff --git a/TestApp/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.hpp b/TestApp/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.hpp index 122770b..0aa0dde 100644 --- a/TestApp/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.hpp +++ b/TestApp/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.hpp @@ -27,4 +27,6 @@ class ShowCaseWorldInstance glm::vec2 m_MousePosition; float m_MoveSpeed = {5.f}; float m_LookSpeed = {1.5f}; + + bool callOnce = false; }; \ No newline at end of file diff --git a/TestApp/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp b/TestApp/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp index a4284db..95eff03 100644 --- a/TestApp/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp +++ b/TestApp/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp @@ -1,6 +1,74 @@ #include +using namespace JPH::literals; -BodyContainer::BodyContainer() +JPH::BodyID BodyContainer::CreateBody(EActivation p_ActivationType,JPH::RVec3 p_Position) + { + engine3d::JoltHandler* l_Handler = engine3d::JoltHandler::GetInstance(); + auto* l_Shape = &ParentShape; + + if(m_BodySettings == nullptr) + { + // Create the type of body framework + m_BodySettings = new BodyCreationSettings( + *l_Shape, + p_Position, + Quat::sIdentity(), + m_MotionType, + m_LayerType + ); + } + else + { + m_BodySettings->SetShape(*l_Shape); + l_Handler->getInterface()->RemoveBody(m_BodyID); + l_Handler->getInterface()->DestroyBody(m_BodyID); + m_BodyID = l_Handler->getInterface()->CreateAndAddBody(*m_BodySettings, p_ActivationType); + return m_BodyID; + } + + + printf("Getting here5.3\n"); + + return m_BodyID = l_Handler->getInterface()->CreateAndAddBody( + *m_BodySettings,p_ActivationType); + } + +void BodyContainer::CreateRotatedType(JPH::Vec3 p_Rot) { - // will add more settings and configurations later + ParentShape = new RotatedTranslatedShape( + BaseShape->GetCenterOfMass(), + Quat::sEulerAngles(p_Rot), + BaseShape + ); } +void BodyContainer::CreateScaledType(JPH::Vec3 p_Scale) +{ + ParentShape = new ScaledShape( + BaseShape, + p_Scale + ); +} +void BodyContainer::CreateCompoundType(JPH::Vec3 p_Rot, JPH::Vec3 p_Scale) +{ + //In this order to prevent sheering + // Scale + ParentShape = new ScaledShape( + BaseShape, + p_Scale + ); + + // Rotate + ParentShape = new RotatedTranslatedShape( + ParentShape->GetCenterOfMass(), + Quat::sEulerAngles(p_Rot), + ParentShape + ); + + +} + +BodyContainer::~BodyContainer() +{ + delete ParentShape; + delete BaseShape; +} \ No newline at end of file diff --git a/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp b/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp index 566bb88..773ef87 100644 --- a/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp +++ b/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp @@ -1,19 +1,11 @@ #include -using namespace JPH; -using namespace JPH::literals; -using namespace engine3d; -BoxShaper::BoxShaper() +#include +BoxShaper::BoxShaper(JPH::EMotionType p_MotionType, const JPH::ObjectLayer p_LayerType) { - JoltHandler * temp = engine3d::JoltHandler::GetInstance(); - m_BodySettings = BodyCreationSettings( - temp->m_BoxShapeScaled, - RVec3(0.0_r, -1.0_r, 0.0_r), - Quat::sIdentity(), - EMotionType::Static, - Engine3DLayers::Static - ); - - m_BodyID = temp->getInterface()->CreateAndAddBody( - m_BodySettings, - EActivation::DontActivate); + printf("Getting here2\n"); + BaseShape = new JPH::BoxShape(Vec3(1.0f, 1.0f, 1.0f)); + ParentShape = BaseShape; + printf("Getting here3\n"); + m_MotionType = p_MotionType; + m_LayerType = p_LayerType; } \ No newline at end of file diff --git a/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp b/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp index eec65a1..6a3f6db 100644 --- a/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp +++ b/TestApp/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp @@ -1,21 +1,9 @@ #include -using namespace JPH; -using namespace JPH::literals; -using namespace engine3d; -SphereShaper::SphereShaper() +#include +SphereShaper::SphereShaper(JPH::EMotionType p_MotionType, const JPH::ObjectLayer p_LayerType) { - JoltHandler * temp = engine3d::JoltHandler::GetInstance(); - - - m_BodySettings = BodyCreationSettings( - temp->m_SphereShapeScaled, - RVec3(0.0_r, 4.0_r, 0.0_r), - Quat::sIdentity(), - EMotionType::Dynamic, - Engine3DLayers::Dynamic - ); - - m_BodyID = temp->getInterface()->CreateAndAddBody( - m_BodySettings, - EActivation::Activate); + BaseShape = new SphereShape(2.5f); + ParentShape = BaseShape; + m_MotionType = p_MotionType; + m_LayerType = p_LayerType; } \ No newline at end of file diff --git a/TestApp/src/Scenes/Assets/Components/Camera/CameraFollow.cpp b/TestApp/src/Scenes/Assets/Components/Camera/CameraFollow.cpp new file mode 100644 index 0000000..7f0e444 --- /dev/null +++ b/TestApp/src/Scenes/Assets/Components/Camera/CameraFollow.cpp @@ -0,0 +1,81 @@ +#include "Core/EngineLogger.hpp" +#include "Core/SceneManagment/Components/SPComps/Camera.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define GLM_ENABLE_EXPERIMENTAL +#include + +const float RADIUS = 20.0f; +const float HEIGHT = 10.0f; + + +// namespace ToPhysics +// { +// glm::vec3 FollowObject(const glm::vec3& targetPosition, const glm::vec3& velocity, float radius) { +// // Avoid division by zero by handling near-zero velocity components +// glm::vec3 adjustedVelocity = velocity; +// if (glm::length(velocity) < 0.001f) { +// adjustedVelocity = glm::vec3(0.0f, 0.0f, -1.0f); // Default fallback direction +// } + +// // Calculate the direction opposite to the velocity +// glm::vec3 normVel = -glm::normalize(glm::vec3(adjustedVelocity.x, 0.0f, adjustedVelocity.z)); + +// // Scale by the desired follow radius +// glm::vec3 followOffset = normVel * radius; + +// // Calculate the camera's new position behind the target +// return targetPosition + followOffset; +// } +// }; + +CameraFollow::CameraFollow(engine3d::Transform &p_transform) +{ + m_PlayerTransform = &p_transform; +} + +void CameraFollow::OnIntegrate() +{ + engine3d::SyncUpdateManager::GetInstance()->Subscribe + (this, &CameraFollow::LateUpdate); + + // Probably should be an event or called when activated + //! @note For now just calling Begin on integrate + m_Transform = &m_GameObjectRef->GetComponent();; +} + +void CameraFollow::LateUpdate() +{ + + engine3d::SceneObject* player = m_PlayerTransform->GetParent(); + PhysicsBody3D* rb = &player->GetComponent(); + auto l_interface = engine3d::JoltHandler::GetInstance()->getInterface(); + auto player_velocity = l_interface->GetLinearVelocity(rb->GetBody()->m_BodyID); + // glm::vec3 newPos = ToPhysics::FollowObject( + // m_PlayerTransform->GetPos(), + // glm::vec3{player_velocity.GetZ(),player_velocity.GetY(),player_velocity.GetZ()}, + // RADIUS); + + m_Transform->SetPos({ + m_PlayerTransform->m_Position.x, + m_PlayerTransform->m_Position.y + HEIGHT, + m_PlayerTransform->m_Position.z - RADIUS + }); + + m_GameObjectRef->GetComponent().SetViewTarget( + { + m_Transform->m_Position.x, + m_Transform->m_Position.y, + m_Transform->m_Position.z}, + m_PlayerTransform->m_Position); + +} \ No newline at end of file diff --git a/TestApp/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp b/TestApp/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp index c20d55d..c035a1c 100644 --- a/TestApp/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp +++ b/TestApp/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp @@ -30,65 +30,59 @@ void PhysicsBody3D::Begin() { m_interface = engine3d::JoltHandler::GetInstance()->getInterface(); m_Transform = &m_GameObjectRef->GetComponent(); + + auto position = m_Transform->GetPos(); + bodyType->CreateBody( + EActivation::Activate, + JPH::RVec3(position.x,position.y,position.z)); } void PhysicsBody3D::Update() -{ +{ //Convert Posiitons - m_Transform->m_Position.x = m_interface-> - GetCenterOfMassPosition(bodyType->m_BodyID).GetX(); - m_Transform->m_Position.y = m_interface-> - GetCenterOfMassPosition(bodyType->m_BodyID).GetY(); - m_Transform->m_Position.z = m_interface-> - GetCenterOfMassPosition(bodyType->m_BodyID).GetZ(); + m_Transform->SetPos( + m_interface->GetWorldTransform(bodyType->m_BodyID).GetTranslation()); //Convert Rotations - m_Transform->m_QuaterionRot.x = m_interface-> - GetRotation(bodyType->m_BodyID).GetX(); - m_Transform->m_QuaterionRot.y = m_interface-> - GetRotation(bodyType->m_BodyID).GetY(); - m_Transform->m_QuaterionRot.z = m_interface-> - GetRotation(bodyType->m_BodyID).GetZ(); - m_Transform->m_QuaterionRot.w = m_interface-> - GetRotation(bodyType->m_BodyID).GetW(); + m_Transform->SetQuat( + m_interface->GetRotation(bodyType->m_BodyID)); //Convert Rotations - m_Transform->m_AxisRotation.x = m_interface-> - GetRotation(bodyType->m_BodyID).GetEulerAngles().GetX(); - m_Transform->m_AxisRotation.y = m_interface-> - GetRotation(bodyType->m_BodyID).GetEulerAngles().GetY(); - m_Transform->m_AxisRotation.z = m_interface-> - GetRotation(bodyType->m_BodyID).GetEulerAngles().GetZ(); + m_Transform->SetAxisRot( + m_interface->GetRotation(bodyType->m_BodyID).GetEulerAngles()); } -void PhysicsBody3D::SetScale(float x, float y, float z) +void PhysicsBody3D::ForcedSetScale(float x, float y, float z) { - m_Transform->m_Scale = glm::vec3(x,y,z); - m_interface->GetShape(bodyType->m_BodyID)->ScaleShape(RVec3(x,y,z)); + bodyType->CreateScaledType(JPH::Vec3(x,y,z)); + bodyType->m_BodyID = bodyType->CreateBody( + JPH::EActivation::Activate, + m_Transform->GetPos() + ); + m_Transform->SetScale({x,y,z}); } -void PhysicsBody3D::SetPosition(float x, float y, float z) +void PhysicsBody3D::ForcedSetPosition(float x, float y, float z) { - m_Transform->m_Position = glm::vec3(x,y,z); m_interface->SetPosition( bodyType->m_BodyID, RVec3(x,y,z), JPH::EActivation::Activate); + m_Transform->SetPos({x,y,z}); } -void PhysicsBody3D::SetRotation(Quat quaternion) +void PhysicsBody3D::ForcedSetRotation(Quat quaternion) { m_interface->SetRotation( bodyType->m_BodyID, quaternion, JPH::EActivation::Activate); - - m_Transform->m_AxisRotation.x = m_interface->GetRotation( - bodyType->m_BodyID).GetEulerAngles().GetX(); - m_Transform->m_AxisRotation.y = m_interface->GetRotation( - bodyType->m_BodyID).GetEulerAngles().GetY(); - m_Transform->m_AxisRotation.z = m_interface->GetRotation( - bodyType->m_BodyID).GetEulerAngles().GetZ(); + + m_Transform->SetQuat( + quaternion); + + m_Transform->SetAxisRot( + m_interface->GetRotation(bodyType->m_BodyID).GetEulerAngles()); } void PhysicsBody3D::LateUpdate() diff --git a/TestApp/src/Scenes/Assets/Components/testComp.cpp b/TestApp/src/Scenes/Assets/Components/testComp.cpp index b24bdf7..a74bb00 100644 --- a/TestApp/src/Scenes/Assets/Components/testComp.cpp +++ b/TestApp/src/Scenes/Assets/Components/testComp.cpp @@ -36,6 +36,42 @@ using namespace engine3d; EActivation::Activate ); } + if(InputPoll::IsKeyPressed(KeyCode::Up)) + { + JoltHandler::GetInstance()-> + getInterface()->AddForce( + m_rb->m_BodyID, + RVec3(0.0f,0.0f,100000.0f), + EActivation::Activate + ); + } + if(InputPoll::IsKeyPressed(KeyCode::Down)) + { + JoltHandler::GetInstance()-> + getInterface()->AddForce( + m_rb->m_BodyID, + RVec3(0.0f,0.0f,-100000.0f), + EActivation::Activate + ); + } + if(InputPoll::IsKeyPressed(KeyCode::Left)) + { + JoltHandler::GetInstance()-> + getInterface()->AddForce( + m_rb->m_BodyID, + RVec3(-100000.0f,0.0f,0.0f), + EActivation::Activate + ); + } + if(InputPoll::IsKeyPressed(KeyCode::Right)) + { + JoltHandler::GetInstance()-> + getInterface()->AddForce( + m_rb->m_BodyID, + RVec3(100000.0f,0.0f,0.0f), + EActivation::Activate + ); + } } void testComp::LateUpdate() diff --git a/TestApp/src/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.cpp b/TestApp/src/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.cpp index 2d7c01f..51573bc 100644 --- a/TestApp/src/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.cpp +++ b/TestApp/src/Scenes/Assets/WorldInstances/ShowCaseWorldInstance.cpp @@ -1,9 +1,12 @@ -#include "Core/Event/InputPoll.hpp" -#include "Core/Renderer/Renderer.hpp" +#include "Core/EngineLogger.hpp" +#include +#include +#include #include #include #include #include +#include #include #include #include @@ -16,6 +19,7 @@ #include #include #include +#include #include #include using namespace engine3d; @@ -28,7 +32,6 @@ ShowCaseWorldInstance::ShowCaseWorldInstance() Subscribe(this,&ShowCaseWorldInstance::RenderScenes); m_Scenes.push_back(new engine3d::Scene()); - CreateObjects(); } @@ -36,58 +39,75 @@ void ShowCaseWorldInstance::CreateObjects() { //Platform engine3d::SceneObject* platform = new engine3d::SceneObject(m_Scenes[0]); - BodyContainer * l_Body = new BoxShaper(); + printf("Getting here\n"); + BodyContainer * l_Body = new BoxShaper(JPH::EMotionType::Static, Engine3DLayers::Static); platform->AddComponent(l_Body); + printf("Getting here4\n"); auto& platformPhysicsBody = platform->GetComponent(); - platformPhysicsBody.SetScale(10.0f, .5f, 10.0f); + printf("Getting here5\n"); + platformPhysicsBody.ForcedSetScale(100.0f, .50f, 100.0f); + platformPhysicsBody.ForcedSetPosition(0.0f, 0.0f, 0.0f); + printf("Getting here6\n"); platform->name = "Platform1"; platform->AddComponent("3d_models/tutorial/cube.obj", platform); m_RenderedObjectList.push_back(platform); - - //Platform - engine3d::SceneObject* platform1 = new engine3d::SceneObject(m_Scenes[0]); - BodyContainer * l_Body1 = new BoxShaper(); - platform1->AddComponent(l_Body1); - auto& platformPhysicsBody1 = platform1->GetComponent(); - platformPhysicsBody1.SetPosition(0.0f, 5.f, 0.0f); - platformPhysicsBody1.SetScale(10.0f, 2.0f, 2.0f); - JPH::Vec3 eulerangles(glm::radians(45.f),0.f,0.f); - platformPhysicsBody1.SetRotation(Quat::sEulerAngles(eulerangles)); - platform1->name = "Platform1"; - platform1->AddComponent("3d_models/tutorial/cube.obj", platform1); - m_RenderedObjectList.push_back(platform1); + // //Platform + // engine3d::SceneObject* platform1 = new engine3d::SceneObject(m_Scenes[0]); + // BodyContainer * l_Body1 = new BoxShaper(JPH::EMotionType::Static, Engine3DLayers::Static); + // platform1->AddComponent(l_Body1); + // auto& platformPhysicsBody1 = platform1->GetComponent(); + // platformPhysicsBody1.ForcedSetPosition(0.0f, 5.f, 0.0f); + // platformPhysicsBody1.ForcedSetScale(10.0f, 2.0f, 2.0f); + // JPH::Vec3 eulerangles(glm::radians(45.f),0.f,0.f); + // platformPhysicsBody1.ForcedSetRotation(JPH::Quat::sEulerAngles(eulerangles)); + // platform1->name = "Platform1"; + // platform1->AddComponent("3d_models/tutorial/cube.obj", platform1); + // m_RenderedObjectList.push_back(platform1); //Sphere engine3d::SceneObject* player = new engine3d::SceneObject(m_Scenes[0]); - l_Body = new SphereShaper(); + l_Body = new SphereShaper(JPH::EMotionType::Dynamic, Engine3DLayers::Dynamic); player->AddComponent(l_Body); auto& player_physicsBody = player->GetComponent(); - player_physicsBody.SetScale(.5f, .5f, .5f); - player_physicsBody.SetPosition(0.0f, 10.0f, 0.0f); + player_physicsBody.ForcedSetScale(.5f, .5f, .5f); + player_physicsBody.ForcedSetPosition(0.0f, 10.0f, 0.0f); player->AddComponent("3d_models/tutorial/sphere.obj", player); player->AddComponent(); player->name = "Player"; m_RenderedObjectList.push_back(player); - //Main Game Camera engine3d::SceneObject* MainCamera = new engine3d::SceneObject(m_Scenes[0]); auto& camera_transform = MainCamera->GetComponent(); - camera_transform.m_Position = {-.2f,-.2f,20.f}; - camera_transform.m_AxisRotation = {0.f,180.f,0.f}; + camera_transform.m_Position = {2.f,3.f,0.f}; + camera_transform.m_AxisRotation = {0.f,0.f,0.f}; MainCamera->AddComponent(); m_CameraObjectList.push_back(MainCamera); + MainCamera->AddComponent(player->GetComponent()); + m_AllSceneObjecs.insert({"PointLights", m_PointLightObjectList}); m_AllSceneObjecs.insert({"RadiusLights", m_PointRadiusLightList}); m_AllSceneObjecs.insert({"SceneObjects", m_SceneObjectList}); m_AllSceneObjecs.insert({"RenderedObjects", m_RenderedObjectList}); m_AllSceneObjecs.insert({"Cameras", m_CameraObjectList}); + + + //Set camera perspective + auto& camera = m_AllSceneObjecs["Cameras"].at(0)->GetComponent(); + camera.SetPerspectiveProjection(glm::radians(50.f), engine3d::ApplicationInstance::GetWindow().GetAspectRatio(), 1.f, 1000.f); + + } void ShowCaseWorldInstance::RenderScenes() { + if(!callOnce) + { + CreateObjects(); + callOnce = true; + } // auto& cameraObj = m_AllSceneObjecs["Cameras"][0]; // auto& camera = cameraObj->GetComponent(); // for(const auto& m_RenderedObjects : m_RenderedObjectList) @@ -97,60 +117,68 @@ void ShowCaseWorldInstance::RenderScenes() // } // auto& camera_transform = cameraObj->GetComponent(); -auto& cameraObject = m_AllSceneObjecs["Cameras"].at(0); + auto& cameraObject = m_AllSceneObjecs["Cameras"].at(0); auto& transform = cameraObject->GetComponent(); auto& camera = cameraObject->GetComponent(); - // float tempDt_Y; - glm::vec2 temp_position = {0.f, 0.f}; - constexpr float sensitivity = 2.0f; - float pos_sensitivity = 2.f; - constexpr glm::vec2 invert_pos = {-1, -1}; - glm::vec3 rotate{0}; - - //! @note Make sure that our mouse controls how camera rotates. - if(InputPoll::IsMousePressed(Mouse::ButtonRight)){ - // temp_position.x = m_MousePosition.x - InputPoll::GetMouseX(); - rotate.y += (m_MousePosition.x - InputPoll::GetMouseX()) * invert_pos.y; - rotate.x += (m_MousePosition.y - InputPoll::GetMouseY()) * invert_pos.x; - } - - m_MousePosition = InputPoll::GetMousePosition(); +// // float tempDt_Y; +// glm::vec2 temp_position = {0.f, 0.f}; +// constexpr float sensitivity = 2.0f; +// float pos_sensitivity = 2.f; +// constexpr glm::vec2 invert_pos = {-1, -1}; +// glm::vec3 rotate{0}; + +// ConsoleLogWarn("SphereCords: {}", m_AllSceneObjecs["RenderedObjects"][1]->GetComponent().GetPos().x); +// ConsoleLogWarn("SphereCords: {}", m_AllSceneObjecs["RenderedObjects"][1]->GetComponent().GetPos().y); +// ConsoleLogWarn("SphereCords: {}", m_AllSceneObjecs["RenderedObjects"][1]->GetComponent().GetPos().z); +// ConsoleLogWarn("SphereRot: {}", m_AllSceneObjecs["RenderedObjects"][1]->GetComponent().GetAxisRot().x); +// ConsoleLogWarn("SphereRot: {}", m_AllSceneObjecs["RenderedObjects"][1]->GetComponent().GetAxisRot().y); +// ConsoleLogWarn("SphereRot: {}", m_AllSceneObjecs["RenderedObjects"][1]->GetComponent().GetAxisRot().z); +// // ConsoleLogError("SphereCords: {},{},{}", transform.GetAxisRot().x,transform.GetAxisRot().y,transform.GetAxisRot().z); - //! @note Utilize linear interpolation to get smooth camera rotation. - if(glm::dot(rotate, rotate) > std::numeric_limits::epsilon()){ - float dt = SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime; - auto temp_rotation = (m_LookSpeed * glm::normalize(rotate) * sensitivity) + transform.m_AxisRotation; - transform.m_AxisRotation = engine3d::Interpolation::LinearInterpolate(transform.m_AxisRotation, temp_rotation, nullptr, dt); - } - - transform.m_AxisRotation.x = glm::clamp(transform.m_AxisRotation.x, -1.5f, 1.5f); - transform.m_AxisRotation.y = glm::mod(transform.m_AxisRotation.y, glm::two_pi()); - float yaw = transform.m_AxisRotation.y; - const glm::vec3 forward_dir{sin(yaw), 0.f, cos(yaw)}; - const glm::vec3 right_dir{forward_dir.z, 0.f, -forward_dir.x}; - const glm::vec3 up_dir{0.f, -1.f, 0.f}; +// //! @note Make sure that our mouse controls how camera rotates. +// if(InputPoll::IsMousePressed(Mouse::ButtonRight)){ +// // temp_position.x = m_MousePosition.x - InputPoll::GetMouseX(); +// rotate.y += (m_MousePosition.x - InputPoll::GetMouseX()) * invert_pos.y; +// rotate.x += (m_MousePosition.y - InputPoll::GetMouseY()) * invert_pos.x; +// } - glm::vec3 move_dir{0.f}; - - if(InputPoll::IsKeyPressed(ENGINE_KEY_W)) move_dir += forward_dir; // FORWARD - 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_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::epsilon()){ - transform.m_Position += m_MoveSpeed * (SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime) * glm::normalize(move_dir) * pos_sensitivity; - } - - //auto& sphere_transform = m_AllSceneObjecs["RenderedObjects"][0]->GetComponent(); - camera.SetViewXYZ(transform.m_Position, transform.m_AxisRotation); - camera.SetPerspectiveProjection(glm::radians(50.f), engine3d::ApplicationInstance::GetWindow().GetAspectRatio(), 1.f, 1000.f); +// m_MousePosition = InputPoll::GetMousePosition(); + +// //! @note Utilize linear interpolation to get smooth camera rotation. +// if(glm::dot(rotate, rotate) > std::numeric_limits::epsilon()){ +// float dt = SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime; +// auto temp_rotation = (m_LookSpeed * glm::normalize(rotate) * sensitivity) + transform.m_AxisRotation; +// transform.m_AxisRotation = engine3d::Interpolation::LinearInterpolate(transform.m_AxisRotation, temp_rotation, nullptr, dt); +// } + +// transform.m_AxisRotation.x = glm::clamp(transform.m_AxisRotation.x, -1.5f, 1.5f); +// transform.m_AxisRotation.y = glm::mod(transform.m_AxisRotation.y, glm::two_pi()); + +// float yaw = transform.m_AxisRotation.y; +// const glm::vec3 forward_dir{sin(yaw), 0.f, cos(yaw)}; +// const glm::vec3 right_dir{forward_dir.z, 0.f, -forward_dir.x}; +// const glm::vec3 up_dir{0.f, -1.f, 0.f}; + +// glm::vec3 move_dir{0.f}; + +// if(InputPoll::IsKeyPressed(ENGINE_KEY_W)) move_dir += forward_dir; // FORWARD +// 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_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::epsilon()){ +// transform.m_Position += m_MoveSpeed * (SyncUpdateManager::GetInstance()->m_SyncLocalDeltaTime) * glm::normalize(move_dir) * pos_sensitivity; +// } + +// //auto& sphere_transform = m_AllSceneObjecs["RenderedObjects"][0]->GetComponent(); + //camera.SetViewXYZ(transform.m_Position, transform.m_AxisRotation); engine3d::Renderer::RecordSceneGameObjects(m_AllSceneObjecs); } diff --git a/engine3d/Core/SceneManagment/Components/GameComponent.hpp b/engine3d/Core/SceneManagment/Components/GameComponent.hpp index 3fe4dcb..f846f05 100644 --- a/engine3d/Core/SceneManagment/Components/GameComponent.hpp +++ b/engine3d/Core/SceneManagment/Components/GameComponent.hpp @@ -1,11 +1,10 @@ #pragma once -// #include +#include #include namespace engine3d { - class SceneObject; class GameComponent { public: diff --git a/engine3d/Core/SceneManagment/Components/SPComps/Transform.hpp b/engine3d/Core/SceneManagment/Components/SPComps/Transform.hpp index f1a187b..11f5ed0 100644 --- a/engine3d/Core/SceneManagment/Components/SPComps/Transform.hpp +++ b/engine3d/Core/SceneManagment/Components/SPComps/Transform.hpp @@ -1,25 +1,183 @@ +#pragma once +#include #include +#include +#include #include #include +namespace VectorConversion { + template + concept IsVec3 = requires(Vector3 vector) + { + vector.x; + vector.y; + vector.z; + }; + + template + concept IsVec4 = IsVec3 && requires(Vector4 vector) + { + vector.w; + }; + + template + concept IsGetterVec3 = requires(Vector3 vector) + { + vector.GetX(); + vector.GetY(); + vector.GetZ(); + }; + + template + concept IsGetterVec4 = IsGetterVec3 && requires(Vector4 vector) + { + vector.GetW(); + }; +} + + namespace engine3d { class Transform : public GameComponent { public: Transform(); - glm::vec3 m_Position; - glm::vec4 m_QuaterionRot; - glm::vec3 m_AxisRotation; - glm::vec3 m_Scale; + //Getters + template + T GetPos() + { + T position(m_Position.x,m_Position.y,m_Position.z); + return position; + } + + template + Q GetQuat() + { + Q quat(m_QuaterionRot.x,m_QuaterionRot.y,m_QuaterionRot.z,m_QuaterionRot.w); + return quat; + } + + template + T GetAxisRot() + { + T axisRotation(m_AxisRotation.x,m_AxisRotation.y,m_AxisRotation.z); + return axisRotation; + } + + template + T GetScale() + { + T scale(m_Scale.x,m_Scale.y,m_Scale.z); + return scale; + } + + //JPH Getters + template + T GetPos() + { + T position(m_Position.x,m_Position.y,m_Position.z); + return position; + } + + template + Q GetQuat() + { + Q quat(m_QuaterionRot.x,m_QuaterionRot.y,m_QuaterionRot.z,m_QuaterionRot.w); + return quat; + } + + template + T GetAxisRot() + { + T axisRotation(m_AxisRotation.x,m_AxisRotation.y,m_AxisRotation.z); + return axisRotation; + } - glm::lowp_vec3 GetLPPos(); - glm::lowp_vec4 GetLPQuat(); - glm::lowp_vec3 GetLPAxisRot(); - glm::lowp_vec3 GetLPSclae(); + template + T GetScale() + { + T scale(m_Scale.x,m_Scale.y,m_Scale.z); + return scale; + } + + //Setters + template + void SetPos(T position) + { + m_Position.x = position.x; + m_Position.y = position.y; + m_Position.z = position.z; + } + + template + void SetQuat(Q quat) + { + m_QuaterionRot.x = quat.x; + m_QuaterionRot.y = quat.y; + m_QuaterionRot.z = quat.z; + m_QuaterionRot.w = quat.w; + } + + template + void SetAxisRot(T axisRotation) + { + m_AxisRotation.x = axisRotation.x; + m_AxisRotation.y = axisRotation.y; + m_AxisRotation.z = axisRotation.z; + } + + template + void SetScale(T scale) + { + m_Scale.x = scale.x; + m_Scale.y = scale.y; + m_Scale.z = scale.z; + } + + //Setters JPH + template + void SetPos(T position) + { + m_Position.x = position.GetX(); + m_Position.y = position.GetY(); + m_Position.z = position.GetZ(); + } + + template + void SetQuat(Q quat) + { + m_QuaterionRot.x = quat.GetX(); + m_QuaterionRot.y = quat.GetY(); + m_QuaterionRot.z = quat.GetZ(); + m_QuaterionRot.w = quat.GetW(); + } + + template + void SetAxisRot(T axisRotation) + { + m_AxisRotation.x = axisRotation.GetX(); + m_AxisRotation.y = axisRotation.GetY(); + m_AxisRotation.z = axisRotation.GetZ(); + } + + template + void SetScale(T scale) + { + m_Scale.x = scale.GetX(); + m_Scale.y = scale.GetY(); + m_Scale.z = scale.GetZ(); + } void OnIntegrate(); + glm::highp_vec3 m_Position; + glm::highp_vec4 m_QuaterionRot; + glm::highp_vec3 m_AxisRotation; + glm::highp_vec3 m_Scale; + + SceneObject* GetParent() {return m_GameObjectRef;} + }; }; \ No newline at end of file diff --git a/engine3d/Physics/JoltHandler.hpp b/engine3d/Physics/JoltHandler.hpp index 0d58de9..3e225f3 100644 --- a/engine3d/Physics/JoltHandler.hpp +++ b/engine3d/Physics/JoltHandler.hpp @@ -37,11 +37,6 @@ namespace engine3d } BodyInterface* getInterface(); - JPH::Shape* m_BoxShape; - JPH::Shape* m_SphereShape; - - JPH::ScaledShape* m_BoxShapeScaled; - JPH::ScaledShape* m_SphereShapeScaled; // Actuall physics part JPH::PhysicsSystem physics_system; diff --git a/sim_shader_transforms/simple_shader.vert b/sim_shader_transforms/simple_shader.vert index 4978d1c..61b06c7 100644 --- a/sim_shader_transforms/simple_shader.vert +++ b/sim_shader_transforms/simple_shader.vert @@ -23,8 +23,9 @@ layout(push_constant) uniform Push { vec3 dir_to_light = normalize(push.LightTransform); void main(){ - // vec4 worldPositionSpace = push.ModelMatrix * vec3(Position, 1.0); - gl_Position = push.Transform * vec4(Position, 1.0); + vec3 newPos = vec3(Position.x,Position.y-.5f,Position.z); + // vec4 worldPositionSpace = push.ModelMatrix * vec4(newPos, 1.0); + gl_Position = push.Transform * vec4(newPos,1.0); // mat3 normal_mat = transpose(inverse(mat3(push.ModelMatrix))); vec3 normalize_world_space = normalize(mat3(push.ModelMatrix) * Normals); diff --git a/sim_shader_transforms/simple_shader.vert.spv b/sim_shader_transforms/simple_shader.vert.spv index ef88cd1bb75e3adb558a60aeffaae89e2861412a..0ecaed7ae2cf3fb132133f1bcab7fe79616befc6 100644 GIT binary patch literal 2616 zcmZ9M+iz4=6o(HjQxFS?$VJ66wcgQs1FRynSa7IL=|Br!UM7>yp`7F}GnqN%;uDE4 zKAD*K2O0k=UrhYIGiS9E_vDwo)^A<*+H0>f(^CtFlH@@0VsbS3IT^1L$rMZiH&gD7 z=4NwoRCE_FUiw6jW65;ssLye{TnE9UPS#UC3qAlhz+JEfegf0{rr7@`@L+NzX*Ao7 zjg3b0W_x=uXpf3#dD_miUfS+v!*sjI9;f;pp76_h+xc#H(xHaOZ9et|Pc(JuO= z+j&@^Ci=~?w{}Ml)o1vryS9d%-snMp_y{?8@3!9WrullO7-mo550(Db-!$n&khzb+ z531bir_p=qlU9G^*|oAKC|Qy9%N|+hd-&|+?N&OxpAL)kDQbDXyh~ezc)q-Km3-DK zHnU&okTGMMwP9P$v%!sQRCIdV>7LCO)3%%Ed$tB$N{I9atfy?~rua(+3|Le&5ddILw zPu1n;0c$zz3n?Y<6Nao$F${Z*cK2iaW4 zm`~k#oXqb$n%`OZf!&<(jz3m5dE?ccSN$(DJNh|CE_40^te4iGXoVSa>c>T3Imw%8~+a=)H`dFWH`UP;- ztm=y$a-98~jswr)xl7xUAbcBW4-d82N} QmebGpyXz{PByy(PBPAJW(O6Yc=XA{#6QUR zSNUS%_v@WrCibT2s;{cPs_yF1Lhn?`m>zS`95NfGvqnv?5F@PL?q20hWu~1rX70`2 zB4XGSY#=csiemLiKGwn*{j{Vkxi49lc#?{wpkJ@{-%9K=gT|})-sYxPS@-L$mfucy zqri{CIPe=`64cZ1Q$XB6E-sAg(M}^DP*g;|c2PYaPz_P|X;XCDA5xiyxFPM;o%RRp ze*LgnZ(#q`4%xhlRH?ZhAN=dpq*0LGnIG z(%_3s%MH%L*KCJr*o-YVI5jOE#_5~zt4>c&$#PLwzSSsft%dEh7T1HWk7?lBiK4Er zsJmtktfGEp?cIVF8!*$_V;#E|shIz{nM4i0-KvSXb6?EwmG!s9&~F~ewr77Hr$Mad zcRSq7cq^%GuQsD*lI1eT*AWU zPO+VzyUY8zH*9JW&v%1OjWK1BHz5lf{kXJ#?PbXc#dB_K{AJk#nGL>>*?b?w5I>md z^nOw{=K#YV&t?OLzyaqW?Qn31aANcR!H&ru(O#DHNTxHJ8PYHLquPmukN9I2*B>q7 zv5!m0KP&r$cKQVym&X0NzVRXOp3=^_@zWPJ-vF5FsvtxakG^ns#y#SMR!XIJw)KnU5U$gP-?+pZo>w*y`^U<`HzoleQYY9)CDfyDd{0z~nSjH?jLu2mVRrB^FTM$I$2%dt zEP1UQ&Nw9jV>#@Cbg-Trb}_>^YgHW$YQH2QpLqO}k{{y5cUeMhV(5=Ia8<%Pqd)q` zCeHPLLpuHQ7F_=`(!uEsUjAbRV{PiI**B20wgHC19@JGwGh>dv=cJ Q(!q!$pWea#s^YxlAH4FbYybcN diff --git a/src/engine3d/Core/SceneManagment/Components/SPComps/Transform.cpp b/src/engine3d/Core/SceneManagment/Components/SPComps/Transform.cpp index 0ef533b..1eb3f69 100644 --- a/src/engine3d/Core/SceneManagment/Components/SPComps/Transform.cpp +++ b/src/engine3d/Core/SceneManagment/Components/SPComps/Transform.cpp @@ -8,41 +8,4 @@ namespace engine3d { m_QuaterionRot(0.0f), m_AxisRotation(0.0f), m_Scale(0.0f){} - - glm::lowp_vec3 Transform::GetLPPos() - { - glm::lowp_vec3 lp_Position; - lp_Position.x = m_Position.x; - lp_Position.y = m_Position.y; - lp_Position.z = m_Position.z; - return lp_Position; - } - - glm::lowp_vec4 Transform::GetLPQuat() - { - glm::lowp_vec4 lp_Quat; - lp_Quat.x = m_QuaterionRot.x; - lp_Quat.y = m_QuaterionRot.y; - lp_Quat.z = m_QuaterionRot.z; - lp_Quat.w = m_QuaterionRot.w; - return lp_Quat; - } - - glm::lowp_vec3 Transform::GetLPAxisRot() - { - glm::lowp_vec3 lp_AxisRot; - lp_AxisRot.x = m_AxisRotation.x; - lp_AxisRot.y = m_AxisRotation.y; - lp_AxisRot.z = m_AxisRotation.z; - return lp_AxisRot; - } - - glm::lowp_vec3 Transform::GetLPSclae() - { - glm::lowp_vec3 lp_Scale; - lp_Scale.x = m_Scale.x; - lp_Scale.y = m_Scale.y; - lp_Scale.z = m_Scale.z; - return lp_Scale; - } }; \ No newline at end of file diff --git a/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp b/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp index b002448..359a9ff 100644 --- a/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp +++ b/src/engine3d/Core/SceneManagment/SceneObjects/SceneObject.cpp @@ -1,5 +1,8 @@ #include #include +#include +#include +#include namespace engine3d { SceneObject::SceneObject(entt::entity handle, Scene *scene) @@ -31,13 +34,16 @@ namespace engine3d { auto transform_component = GetComponent(); auto transform = glm::translate(glm::mat4{1.f}, transform_component.m_Position); - transform[0][0] *= transform_component.m_Scale.x; - transform[1][1] *= transform_component.m_Scale.y; - transform[2][2] *= transform_component.m_Scale.z; - 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}); - transform = glm::rotate(transform, transform_component.m_AxisRotation.z, {0.f, 0.f, 1.f}); + glm::quat quaterion{ + transform_component.m_QuaterionRot.w, + transform_component.m_QuaterionRot.x, + transform_component.m_QuaterionRot.y, + transform_component.m_QuaterionRot.z, + }; + + transform *= glm::mat4_cast(quaterion); + transform = glm::scale(transform, transform_component.m_Scale); return transform; } }; // namespace Engine3D diff --git a/src/engine3d/Physics/JoltHandler.cpp b/src/engine3d/Physics/JoltHandler.cpp index 70c82ae..3dc8922 100644 --- a/src/engine3d/Physics/JoltHandler.cpp +++ b/src/engine3d/Physics/JoltHandler.cpp @@ -3,8 +3,6 @@ #include #include -#include -#include #include #include #include @@ -100,12 +98,6 @@ namespace engine3d body_interface = &(physics_system.GetBodyInterface()); - m_BoxShape = new BoxShape(Vec3(1.0f, 1.0f, 1.0f)); - m_SphereShape = new SphereShape(1.0f); - - m_BoxShapeScaled = new ScaledShape(m_BoxShape, RVec3(1,1,1)); - m_SphereShapeScaled = new ScaledShape(m_SphereShape,RVec3(1,1,1)); - } BodyInterface* JoltHandler::getInterface() @@ -117,10 +109,6 @@ namespace engine3d { JPH::UnregisterTypes(); std::print("Deleting Physics Factory...\n"); - delete m_SphereShapeScaled; - delete m_BoxShapeScaled; - delete m_BoxShape; - delete m_SphereShape; delete JPH::Factory::sInstance; JPH::Factory::sInstance = nullptr; }