1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsPhysXPrerequisites.h"
6#include "Physics/BsRigidbody.h"
7#include "Math/BsVector3.h"
8#include "Math/BsQuaternion.h"
9#include "PxPhysics.h"
10
11namespace bs
12{
13 /** @addtogroup PhysX
14 * @{
15 */
16
17 /** PhysX implementation of a Rigidbody. */
18 class PhysXRigidbody : public Rigidbody
19 {
20 public:
21 PhysXRigidbody(physx::PxPhysics* physx, physx::PxScene* scene, const HSceneObject& linkedSO);
22 ~PhysXRigidbody();
23
24 /** @copydoc Rigidbody::move */
25 void move(const Vector3& position) override;
26
27 /** @copydoc Rigidbody::rotate */
28 void rotate(const Quaternion& rotation) override;
29
30 /** @copydoc Rigidbody::getPosition */
31 Vector3 getPosition() const override;
32
33 /** @copydoc Rigidbody::getRotation */
34 Quaternion getRotation() const override;
35
36 /** @copydoc Rigidbody::setTransform */
37 void setTransform(const Vector3& pos, const Quaternion& rot) override;
38
39 /** @copydoc Rigidbody::setMass */
40 void setMass(float mass) override;
41
42 /** @copydoc Rigidbody::getMass */
43 float getMass() const override;
44
45 /** @copydoc Rigidbody::setIsKinematic */
46 void setIsKinematic(bool kinematic) override;
47
48 /** @copydoc Rigidbody::getIsKinematic */
49 bool getIsKinematic() const override;
50
51 /** @copydoc Rigidbody::isSleeping */
52 bool isSleeping() const override;
53
54 /** @copydoc Rigidbody::sleep */
55 void sleep() override;
56
57 /** @copydoc Rigidbody::wakeUp */
58 void wakeUp() override;
59
60 /** @copydoc Rigidbody::setSleepThreshold */
61 void setSleepThreshold(float threshold) override;
62
63 /** @copydoc Rigidbody::getSleepThreshold */
64 float getSleepThreshold() const override;
65
66 /** @copydoc Rigidbody::setUseGravity */
67 void setUseGravity(bool gravity) override;
68
69 /** @copydoc Rigidbody::getUseGravity */
70 bool getUseGravity() const override;
71
72 /** @copydoc Rigidbody::setVelocity */
73 void setVelocity(const Vector3& velocity) override;
74
75 /** @copydoc Rigidbody::getVelocity */
76 Vector3 getVelocity() const override;
77
78 /** @copydoc Rigidbody::setAngularVelocity */
79 void setAngularVelocity(const Vector3& velocity) override;
80
81 /** @copydoc Rigidbody::getAngularVelocity */
82 Vector3 getAngularVelocity() const override;
83
84 /** @copydoc Rigidbody::setDrag */
85 void setDrag(float drag) override;
86
87 /** @copydoc Rigidbody::getDrag */
88 float getDrag() const override;
89
90 /** @copydoc Rigidbody::setAngularDrag */
91 void setAngularDrag(float drag) override;
92
93 /** @copydoc Rigidbody::getAngularDrag */
94 float getAngularDrag() const override;
95
96 /** @copydoc Rigidbody::setInertiaTensor */
97 void setInertiaTensor(const Vector3& tensor) override;
98
99 /** @copydoc Rigidbody::getInertiaTensor */
100 Vector3 getInertiaTensor() const override;
101
102 /** @copydoc Rigidbody::setMaxAngularVelocity */
103 void setMaxAngularVelocity(float maxVelocity) override;
104
105 /** @copydoc Rigidbody::getMaxAngularVelocity */
106 float getMaxAngularVelocity() const override;
107
108 /** @copydoc Rigidbody::setCenterOfMass */
109 void setCenterOfMass(const Vector3& position, const Quaternion& rotation) override;
110
111 /** @copydoc Rigidbody::getCenterOfMassPosition */
112 Vector3 getCenterOfMassPosition() const override;
113
114 /** @copydoc Rigidbody::getCenterOfMassRotation */
115 Quaternion getCenterOfMassRotation() const override;
116
117 /** @copydoc Rigidbody::setPositionSolverCount */
118 void setPositionSolverCount(UINT32 count) override;
119
120 /** @copydoc Rigidbody::getPositionSolverCount */
121 UINT32 getPositionSolverCount() const override;
122
123 /** @copydoc Rigidbody::setVelocitySolverCount */
124 void setVelocitySolverCount(UINT32 count) override;
125
126 /** @copydoc Rigidbody::getVelocitySolverCount */
127 UINT32 getVelocitySolverCount() const override;
128
129 /** @copydoc Rigidbody::setFlags */
130 void setFlags(RigidbodyFlag flags) override;
131
132 /** @copydoc Rigidbody::addForce */
133 void addForce(const Vector3& force, ForceMode mode = ForceMode::Force) override;
134
135 /** @copydoc Rigidbody::addTorque */
136 void addTorque(const Vector3& torque, ForceMode mode = ForceMode::Force) override;
137
138 /** @copydoc Rigidbody::addForceAtPoint */
139 void addForceAtPoint(const Vector3& force, const Vector3& position,
140 PointForceMode mode = PointForceMode::Force) override;
141
142 /** @copydoc Rigidbody::getVelocityAtPoint */
143 Vector3 getVelocityAtPoint(const Vector3& point) const override;
144
145 /** @copydoc Rigidbody::addCollider */
146 void addCollider(Collider* collider) override;
147
148 /** @copydoc Rigidbody::removeCollider */
149 void removeCollider(Collider* collider) override;
150
151 /** @copydoc Rigidbody::removeColliders */
152 void removeColliders() override;
153
154 /** @copydoc Rigidbody::updateMassDistribution */
155 void updateMassDistribution() override;
156
157 /** Returns the internal PhysX dynamic actor. */
158 physx::PxRigidDynamic* _getInternal() const { return mInternal; }
159
160 private:
161 physx::PxRigidDynamic* mInternal;
162 };
163
164 /** @} */
165}