-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working camera rotation using interpolation
- Loading branch information
Showing
18 changed files
with
345 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ set(ENGINE_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/engine3d) | |
|
||
build_library( | ||
DIRECTORIES src Editor TestApp | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
TestApp/SceneTest/Scenes/Assets/Components/Bodies/BodyContainer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <engine3d/Physics/JoltHandler.hpp> | ||
// Jolt Includes | ||
class BodyContainer | ||
{ | ||
public: | ||
BodyContainer(); | ||
|
||
operator JPH::BodyID() { return m_BodyID; } | ||
JPH::BodyCreationSettings m_BodySettings; | ||
JPH::BodyID m_BodyID; | ||
}; |
6 changes: 6 additions & 0 deletions
6
TestApp/SceneTest/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <Scenes/Assets/Components/Physics/PhysicsBody3D.hpp> | ||
class BoxShaper : public BodyContainer | ||
{ | ||
public: | ||
BoxShaper(); | ||
}; |
6 changes: 6 additions & 0 deletions
6
TestApp/SceneTest/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <Scenes/Assets/Components/Physics/PhysicsBody3D.hpp> | ||
class SphereShaper : public BodyContainer | ||
{ | ||
public: | ||
SphereShaper(); | ||
}; |
34 changes: 34 additions & 0 deletions
34
TestApp/SceneTest/Scenes/Assets/Components/Physics/PhysicsBody3D.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
#pragma once | ||
|
||
#include "Core/SceneManagment/Components/GameComponent.hpp" | ||
#include <Scenes/Assets/Components/Bodies/BodyContainer.hpp> | ||
#include <Core/TimeManagement/UpdateManagers/SyncUpdateManager.hpp> | ||
#include <Core/SceneManagment/Components/SPComps/Transform.hpp> | ||
#include <Jolt/Math/Quat.h> | ||
|
||
#include <Jolt/Physics/Body/BodyInterface.h> | ||
// This is a test version of this class as there is to much | ||
class PhysicsBody3D: public engine3d::GameComponent | ||
{ | ||
public: | ||
PhysicsBody3D(BodyContainer * p_bodyCon); | ||
~PhysicsBody3D(); | ||
void OnIntegrate(); | ||
void Update(); | ||
void LateUpdate(); | ||
void PhysicsUpdate(); | ||
void Begin(); | ||
BodyContainer* GetBody(); | ||
|
||
void SetScale(float x, float y, float z); | ||
void SetPosition(float x, float y, float z); | ||
void SetRotation(Quat quaternion); | ||
|
||
private: | ||
engine3d::Transform* m_Transform; | ||
PhysicsBody3D() = default; | ||
BodyContainer * bodyType; | ||
JPH::BodyInterface* m_interface; | ||
bool once = false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "Scenes/Assets/Components/Physics/PhysicsBody3D.hpp" | ||
#include <Core/SceneManagment/Components/GameComponent.hpp> | ||
|
||
class testComp : public engine3d::GameComponent | ||
{ | ||
public: | ||
void OnIntegrate(); | ||
void Update(); | ||
void LateUpdate(); | ||
void PhysicsUpdate(); | ||
private: | ||
bool t_Secret = false; | ||
BodyContainer * m_rb; | ||
}; |
14 changes: 14 additions & 0 deletions
14
TestApp/SceneTest/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "Core/ApplicationManager/Scene.hpp" | ||
#include "Core/SceneManagment/SceneObjects/SceneObject.hpp" | ||
class ShowCaseSceneInstance | ||
{ | ||
public: | ||
ShowCaseSceneInstance(); | ||
~ShowCaseSceneInstance(); | ||
engine3d::Scene* m_Scene; | ||
std::vector<engine3d::SceneObject*> m_SceneObjects; | ||
engine3d::Scene* GetScene(); | ||
|
||
private: | ||
void CreateObjects(); | ||
}; |
6 changes: 6 additions & 0 deletions
6
TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/BodyContainer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <Scenes/Assets/Components/Bodies/BodyContainer.hpp> | ||
|
||
BodyContainer::BodyContainer() | ||
{ | ||
// will add more settings and configurations later | ||
} |
19 changes: 19 additions & 0 deletions
19
TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/Shapes/BoxShaper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp> | ||
using namespace JPH; | ||
using namespace JPH::literals; | ||
using namespace engine3d; | ||
BoxShaper::BoxShaper() | ||
{ | ||
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); | ||
} |
21 changes: 21 additions & 0 deletions
21
TestApp/SceneTest/src/Scenes/Assets/Components/Bodies/Shapes/SphereShaper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp> | ||
using namespace JPH; | ||
using namespace JPH::literals; | ||
using namespace engine3d; | ||
SphereShaper::SphereShaper() | ||
{ | ||
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); | ||
} |
111 changes: 111 additions & 0 deletions
111
TestApp/SceneTest/src/Scenes/Assets/Components/Physics/PhysicsBody3D.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include <Scenes/Assets/Components/Physics/PhysicsBody3D.hpp> | ||
|
||
#include <Jolt/Physics/Body/BodyCreationSettings.h> | ||
#include <Jolt/Math/Vec3.h> | ||
#include <Jolt/Physics/Body/BodyID.h> | ||
#include <Jolt/Math/Quat.h> | ||
#include <Jolt/Physics/EActivation.h> | ||
#include <glm/fwd.hpp> | ||
using namespace engine3d; | ||
PhysicsBody3D::PhysicsBody3D(BodyContainer * p_bodyCon) | ||
{ | ||
bodyType = p_bodyCon; | ||
} | ||
|
||
void PhysicsBody3D::OnIntegrate() | ||
{ | ||
SyncUpdateManager::GetInstance()->Subscribe | ||
(this, &PhysicsBody3D::Update); | ||
SyncUpdateManager::GetInstance()->Subscribe | ||
(this, &PhysicsBody3D::LateUpdate); | ||
SyncUpdateManager::GetInstance()->Subscribe | ||
(this, &PhysicsBody3D::PhysicsUpdate); | ||
|
||
// Probably should be an event or called when activated | ||
//! @note For now just calling Begin on integrate | ||
|
||
Begin(); | ||
} | ||
|
||
void PhysicsBody3D::Begin() | ||
{ | ||
m_interface = engine3d::JoltHandler::GetInstance()->getInterface(); | ||
m_Transform = &m_GameObjectRef->SceneGetComponent<Transform>(); | ||
} | ||
|
||
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(); | ||
|
||
//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(); | ||
|
||
//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(); | ||
|
||
// std::print("Rotation: (X: {0}, Y: {1}, Z: {2})\n", | ||
// m_Transform->m_AxisRotation.x, | ||
// m_Transform->m_AxisRotation.y, | ||
// m_Transform->m_AxisRotation.z); | ||
|
||
} | ||
|
||
void PhysicsBody3D::SetScale(float x, float y, float z) | ||
{ | ||
m_interface->GetShape(bodyType->m_BodyID)->ScaleShape(RVec3(x,y,z)); | ||
} | ||
|
||
void PhysicsBody3D::SetPosition(float x, float y, float z) | ||
{ | ||
m_interface->SetPosition( | ||
bodyType->m_BodyID, | ||
RVec3(x,y,z), | ||
JPH::EActivation::Activate); | ||
} | ||
|
||
void PhysicsBody3D::SetRotation(Quat quaternion) | ||
{ | ||
m_interface->SetRotation( | ||
bodyType->m_BodyID, | ||
quaternion, | ||
JPH::EActivation::Activate); | ||
} | ||
|
||
void PhysicsBody3D::LateUpdate() | ||
{ | ||
|
||
} | ||
|
||
void PhysicsBody3D::PhysicsUpdate() | ||
{ | ||
|
||
} | ||
|
||
BodyContainer* PhysicsBody3D::GetBody() | ||
{ | ||
return bodyType; | ||
} | ||
|
||
PhysicsBody3D::~PhysicsBody3D() | ||
{ | ||
delete bodyType; | ||
} |
49 changes: 49 additions & 0 deletions
49
TestApp/SceneTest/src/Scenes/Assets/Components/testComp.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// #include <engine3d/Core/EngineLogger.hpp> | ||
#include "Core/SceneManagment/Components/GameComponent.hpp" | ||
#include "Physics/JoltHandler.hpp" | ||
#include "Scenes/Assets/Components/Physics/PhysicsBody3D.hpp" | ||
#include <Jolt/Physics/EActivation.h> | ||
#include <engine3d/Core/EngineLogger.hpp> | ||
#include <engine3d/Core/Event/InputPoll.hpp> | ||
#include <engine3d/Core/Event/KeyCodes.hpp> | ||
#include <engine3d/Core/TimeManagement/UpdateManagers/SyncUpdateManager.hpp> | ||
#include <Scenes/Assets/Components/testComp.hpp> | ||
// #include "Scene" | ||
|
||
using namespace engine3d; | ||
void testComp::OnIntegrate() | ||
{; | ||
SyncUpdateManager::GetInstance()->Subscribe | ||
(this, &testComp::Update); | ||
SyncUpdateManager::GetInstance()->Subscribe | ||
(this, &testComp::LateUpdate); | ||
SyncUpdateManager::GetInstance()->Subscribe | ||
(this, &testComp::PhysicsUpdate); | ||
|
||
// Need an activation and start funciton | ||
m_rb = m_GameObjectRef->SceneGetComponent<PhysicsBody3D>().GetBody(); | ||
|
||
} | ||
|
||
void testComp::Update() | ||
{ | ||
if(InputPoll::IsKeyPressed(KeyCode::F5)) | ||
{ | ||
JoltHandler::GetInstance()-> | ||
getInterface()->AddForce( | ||
m_rb->m_BodyID, | ||
RVec3(0.0f,100000.0f,0.0f), | ||
EActivation::Activate | ||
); | ||
} | ||
} | ||
|
||
void testComp::LateUpdate() | ||
{ | ||
|
||
} | ||
|
||
void testComp::PhysicsUpdate() | ||
{ | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
TestApp/SceneTest/src/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "Core/ApplicationManager/Scene.hpp" | ||
#include "Core/SceneManagment/SceneObjects/SceneObject.hpp" | ||
#include "Scenes/Assets/Components/Physics/PhysicsBody3D.hpp" | ||
#include "Scenes/Assets/Components/testComp.hpp" | ||
#include <Scenes/Assets/Components/Bodies/Shapes/BoxShaper.hpp> | ||
#include <Scenes/Assets/Components/Bodies/Shapes/SphereShaper.hpp> | ||
#include <TestApp/SceneTest/Scenes/Assets/SceneInstances/ShowCaseSceneInstance.hpp> | ||
|
||
ShowCaseSceneInstance::ShowCaseSceneInstance() | ||
{ | ||
m_Scene = new engine3d::Scene(); | ||
printf("getting here\n"); | ||
CreateObjects(); | ||
|
||
} | ||
|
||
void ShowCaseSceneInstance::CreateObjects() | ||
{ | ||
//Platform | ||
m_SceneObjects.push_back(new engine3d::SceneObject(m_Scene)); | ||
BodyContainer * l_Body = new BoxShaper(); | ||
m_SceneObjects[0]->AddComponent<PhysicsBody3D>(l_Body); | ||
m_SceneObjects[0]->name = "Platform1"; | ||
|
||
//Sphere | ||
m_SceneObjects.push_back(new engine3d::SceneObject(m_Scene)); | ||
l_Body = new SphereShaper(); | ||
m_SceneObjects[1]->AddComponent<PhysicsBody3D>(l_Body); | ||
m_SceneObjects[1]->AddComponent<testComp>(); | ||
m_SceneObjects[1]->name = "Ball"; | ||
|
||
} | ||
|
||
ShowCaseSceneInstance::~ShowCaseSceneInstance() | ||
{ | ||
delete m_Scene; | ||
for(auto obj : m_SceneObjects) | ||
{ | ||
delete obj; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,4 +113,4 @@ add_library( | |
${ENGINE_SRC_DIR}/Math/Interpolation.cpp | ||
|
||
${ENGINE_SRC_DIR}/Physics/JoltHandler.cpp | ||
) | ||
) |
Oops, something went wrong.