-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added PhysX integration #27
Conversation
Added IPhysics interface with DefaultPhysics class Added PhysXEngine which sets up top-level PhysX objects at construction and releases them on destruction Added physics to the servicelocator from the engine Fixed additional physX libraries not being included by cmake Fixed physX header files not being included by cmake
Added IPhysicsScene interface and added PhysXScene class that derives from the interface Added CreateScene function to the IPhysics and PhysXEngine classes Scene constructor calls CreateScene function from the IPhysics interface
Added cube obj Added PhysicsSync class with static function to sync from physX to transform component Added IPhysicsObject interface and PhysXObject classe which is a wrapper around a rigidactor Added IShape interface and PhysXShapes file which will hold all the PhysX shapes as different classes Modified physics engine to be able to add actors and simulate the scene Added physics to the main game loop Added BoxCollider & Rigidbody components to the main engine
Added sphere shape to PhysXShapes Added SphereCollider component
Added SetSize and SetRadius functions to the IShape class Added SetSize function to the BoxCollider component Added SetRadius function to the SphereCollider component Added sphere obj
Added base collider component, BoxCollider and SphereCollider now derive from this Collider component Rigidbody now makes sure child colliders have the same rigid actor Transforms of static colliders are now no longer being updated by the physics system, instead the physics bodies of static colliders are being updated by the transforms Fixed compile error in the GameObject GetComponentInParent class Fixed PhysicsObjects not being deleted from the scene properly when they are destroyed
When a shape is added or removed from a rigidbody, the center of mass (COM) is now being recalculated Added GetVolume and GetRelativePosition methods to the IShape interface and its derived classes
Calcualte CenterOfMass functino in the PhysXObject class now uses the PxRigidBodyExt::setMassAndUpdateIntertia function, which sets more parameters then just the COM for correct behaviour. Moved Rigidbody from inside the IPhysicsObject interface to its own file Added SetMass functino to Rigidbody component
Replaced the calculations from the glm library to convert quaterions to euler and euler to quaterions with my own implementation.
Removed the yaw rotation on the parent transform of the camera object. Each object should only do one rotation, the parent does yaw, the camera itself does pitch.
Moved all the quaternion/euler angles calculations to a Quaternion class inside the utils engine, it is non constructable and has some static helper functions to correctly convert from euler to quaternion and from quaternion to euler
Added overloads for functions like SetSize and SetVelocity to also take the seperate floats instead of a glm::vec3 object
Added Visual Leak Detector to the 3rdParty folder and included it only into the game project Included vld into main.cpp of the game project Fixed memory leaks in PhysXEngine.cpp
… capsule collider Added rule of 5 to IPhysXShape Added PhysXCapsuleShape Added GetPosition and GetRotation to IPhysicsObject and PhysXObject Fixed order of PhysXObject updates (Rigidbody was being updated after the transform was updated) Added SetPosition, Translate, SetRotation and Rotate functions to the Rigidbody component Fixed direction vectors of child transform not being updated after rotation has changed in parent
Added IPhysicsMaterial interface and PhysXMaterial class Added CreateMaterial function to the IPhysics interface and PhysXEngine class Added SetMaterial function to the Collider base class Colliders that get created without a physics collider set will be created using a default material created by the physics engine
Added PhysXSimulationCallbacks & PhysXSimulationFilterShader which are owned by the PhysXEngine and passed to the PxScene on creation. PhysXSimulationFilterShader currently lets all the collisions succeed and notify A pointer to the component collider is now stored inside the userdata of the corresponding PxShape Added static OnCollision method to the PhysicsSync class to handle incoming collision events from the physics engine Added Subject to the Collider component which gets called when that collider receives a collision event Added PrintCollision component which subscribes to the OnCollision subject of the collider on the same gameobject and prints the names of the gameobjects that are colliding
Moved temporary rigidbody creation to a CheckExistence function instead of copy pasting the code in each function Added Force struct, which stores the value, if it is a torque or not, and the force mode Added AddForce and AddTorque to the Rigidbody class and the Rigidbody component PhysXObject now applies forces stored in the rigidbody class Added ApplyForces component to test force functions
Moved some logic to IPhysXShape and added SetTrigger function to IShape and IPhysXShape Added SetTrigger function to base collider component Added trigger checking to the PhysXSimulationFilterShader
Renamed OnCollision to OnCollisionEnter, Added OnCollisionStay and OnCollisionExit Added PhysXSimulationfilterCallback class which gives us more control Added setup for OnTriggerEnter, OnTriggerStay and OnTriggerExit but the SimulationfilterCallback isn't being called for trigger shapes yet, that's the next step.
SimulationFilterShader now returns default filter flag for triggers Moved SimulationEvent and SimulationEventType from PhysXSimulationFilterCallback.h to PhysXSimulationData.h and SimulationEventData.h Moved SimulationPair from PhysXSimulationFilterCallback.h to PhysXSimulationData.h Trigger events are now being handled by the PhysxSimulationCallbacks class instead of by the PhysXSimulationFilterCallback class
Added RescaleShape pure virtual method to the base collider and added overrides to all the collider components RescaleShape is now being called when scale has changed on the transform of the component Added capsule.obj Renamed Observer and Subject to TObserver and TSubject and added a non-templated Observer & Subject class
|
||
#include <vec3.hpp> | ||
|
||
#include <Observer.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused include in header file
Base class uses it (Collider) but BoxCollider doesnt
#include "../../SceneGraph/GameObject.h" | ||
|
||
#include "../Transform/Transform.h" | ||
#include "Rigidbody.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused include
|
||
void leap::Collider::SetMaterial(std::shared_ptr<physics::IPhysicsMaterial> pMaterial) | ||
{ | ||
m_pMaterial = pMaterial; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing copy from std::shared_ptr. Should be const ref
Rigidbody& operator=(Rigidbody&& other) = delete; | ||
|
||
void SetKinematic(bool isKinematic); | ||
void SetVelocity(const glm::vec3& velocity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set angular velocity is missing
LeapEngine/Utils/PhysicsSync.cpp
Outdated
|
||
leap::PhysicsSync::ColliderPair leap::PhysicsSync::GetColliders(const physics::CollisionData& collision) | ||
{ | ||
Collider* pFirstCollider{ reinterpret_cast<Collider*>(collision.pFirst) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use static cast
Removed redundant includes shared_ptr parameter in the SetMaterial function of the Collider class is now passed by reference instead of copy GetColliders function in the PhysicsSync class now uses static_cast to convert void* to Collider* instead of reinterpret_cast
Physics/PhysX/PhysXMaterial.cpp
Outdated
#include <PxPhysics.h> | ||
#include <PxMaterial.h> | ||
|
||
#include <Debug.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug include is unused
Physics/PhysX/PhysXEngine.h
Outdated
#pragma once | ||
|
||
#include "../Interfaces/IPhysics.h" | ||
#include "../Interfaces/IPhysicsObject.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused include
Physics/PhysX/PhysXObject.cpp
Outdated
#include <PxRigidActor.h> | ||
#include <PxRigidStatic.h> | ||
#include <PxRigidDynamic.h> | ||
#include <PxRigidActor.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Included twice
Physics/PhysX/PhysXObject.cpp
Outdated
#include "PhysXScene.h" | ||
|
||
#include "../Data/Rigidbody.h" | ||
#include "../Data/ForceMode.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused include
Physics/PhysX/PhysXObject.cpp
Outdated
#include <PxRigidStatic.h> | ||
#include <PxRigidDynamic.h> | ||
#include <PxRigidActor.h> | ||
#include <PxScene.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused include
Physics/PhysX/PhysXObject.cpp
Outdated
if (!IsValid()) static_cast<PhysXScene*>(pScene)->RemoveActor(m_pActor); | ||
} | ||
|
||
void leap::physics::PhysXObject::Apply(const std::function<void(void*, const glm::vec3&, const glm::quat&)>& setFunc, const std::function<std::pair<const glm::vec3&, const glm::quat&>(void*)> getFunc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function can be made const
Physics/PhysX/PhysXObject.cpp
Outdated
{ | ||
if (m_pRigidbody == nullptr) | ||
{ | ||
auto transformPair{ getFunc(m_pOwner) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be made const
Physics/PhysX/PhysXObject.h
Outdated
|
||
#include "../Interfaces/IPhysicsObject.h" | ||
|
||
#include <Subject.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused include
Physics/PhysX/PhysXScene.cpp
Outdated
for (physx::PxU32 i = 0; i < rb.getNbLines(); i++) | ||
{ | ||
const physx::PxDebugLine& line = pLines[i]; | ||
debugDrawings.emplace_back(std::make_pair( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::make_pair is not needed for emplace_back
Physics/PhysX/PhysXScene.cpp
Outdated
return debugDrawings; | ||
} | ||
|
||
void leap::physics::PhysXScene::AddActor(physx::PxRigidActor* pActor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function can be const
Physics/PhysX/PhysXScene.cpp
Outdated
m_pScene->addActor(*pActor); | ||
} | ||
|
||
void leap::physics::PhysXScene::RemoveActor(physx::PxRigidActor* pActor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function can be const
physx::PxShape* m_pShape{}; | ||
}; | ||
|
||
class PhysXBoxShape final : public IPhysXShape |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing rule of 5 (destructor is not default)
virtual glm::vec3 GetRelativePosition() override; | ||
}; | ||
|
||
class PhysXSphereShape final : public IPhysXShape |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing rule of 5 (destructor is not default)
virtual glm::vec3 GetRelativePosition() override; | ||
}; | ||
|
||
class PhysXCapsuleShape final : public IPhysXShape |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing rule of 5 (destructor is not default)
#include "PhysXSimulationCallbacks.h" | ||
|
||
#include <Debug.h> | ||
#include <thread> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused include
@@ -0,0 +1,41 @@ | |||
#include "PhysXSimulationFilterCallback.h" | |||
|
|||
#include <Debug.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused include
UnnamedAdventureGame/CMakeLists.txt
Outdated
) | ||
"Components/PrintCollision.cpp" | ||
"Components/ApplyForces.cpp" | ||
"Components/ColliderScaler.cpp" "Components/PrintVelocity.h" "Components/PrintVelocity.cpp") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Header in CMake and on same line
Utils/Quaternion.h
Outdated
// Quaternion is constructable because it is NOT the object representation for a quaternion, | ||
// use glm::quat for this | ||
// This class exists to give some helper functions to generate correct quaternions/eulerangles | ||
Quaternion() = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constructor can be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied feedback (some you already did live)
Request again after the components have the physics calls to derive from.
Added OnCollision/OnTrigger methods to the Component class Added OnCollision/OnTrigger methods to the GameObject class which calls the component versions of the methods PhysicsSync now calls the gameobject oncollision/ontrigger methods instead of the collider methods
Instead of having private Quaternion constructor/destructor, I changed it so the class deletes its constructor
Instead of having to recreate a CustomMesh object every frame, it can now be cleared which keeps the capacity
Const correctness in PhysXObject & PhysXScene Removed redundant includes in PhysXEngine, PhysXMaterial, PhysXObject and PhysXSimulationCallbacks GetConstraints function in the Rigidbody class now returns a const reference instead of a copy Removed make_pair call for more readable code in the GetDebugDrawings function in the PhysXScene Refactored IPhysxShape so it deletes the PxShape in its own destructors instead of the derived destructor and made the GetShape method non-virtual. Cleaned unag CMakeLists
SetEnabledDebugDrawing is now being called in the main.cpp instead of the Leap.cpp Removed m_Renderer variable in the Leap class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feedback has been applied
Added physics integration with a PhysX service.
Features: