99#include " OgreBulletExports.h"
1010
1111#include " BulletCollision/CollisionDispatch/btGhostObject.h"
12+ #include " BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
1213#include " Ogre.h"
1314#include " btBulletCollisionCommon.h"
1415#include " btBulletDynamicsCommon.h"
15- #include " BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
1616
1717namespace Ogre
1818{
@@ -22,8 +22,8 @@ namespace Bullet
2222{
2323
2424/* * \addtogroup Optional
25- * @{
26- */
25+ * @{
26+ */
2727/* * \defgroup Bullet Bullet
2828 * [Bullet-Physics](https://pybullet.org) to %Ogre connection
2929 * @{
@@ -71,13 +71,14 @@ class _OgreBulletExport RigidBodyState : public btMotionState
7171};
7272
7373// / height field data
74- struct _OgreBulletExport HeightFieldData {
74+ struct _OgreBulletExport HeightFieldData
75+ {
7576 /* * the position for a center of the shape, i.e. where to place btRigidBody
7677 * or a child of btCompoundShape */
7778 Vector3 bodyPosition;
7879 /* * a heightfield pointer to be freed when
7980 * btHeightfieldTerrainShape is freed */
80- float * terrainHeights;
81+ float * terrainHeights;
8182};
8283
8384// / create sphere collider using ogre provided data
@@ -95,25 +96,26 @@ _OgreBulletExport btConvexHullShape* createConvexHullCollider(const Entity* ent)
9596// / create compound shape
9697_OgreBulletExport btCompoundShape* createCompoundShape ();
9798// / create height field collider
98- _OgreBulletExport btHeightfieldTerrainShape* createHeightfieldTerrainShape (const Terrain* terrain, struct HeightFieldData *data);
99+ _OgreBulletExport btHeightfieldTerrainShape* createHeightfieldTerrainShape (const Terrain* terrain,
100+ struct HeightFieldData * data);
99101
100102struct _OgreBulletExport CollisionListener
101103{
102104 virtual ~CollisionListener () {}
103105 /* * Called when two objects collide
104- * @param other the other object
105- * @param manifoldPoint the collision point
106- */
106+ * @param other the other object
107+ * @param manifoldPoint the collision point
108+ */
107109 virtual void contact (const MovableObject* other, const btManifoldPoint& manifoldPoint) = 0;
108110};
109111
110112struct _OgreBulletExport RayResultCallback
111113{
112114 virtual ~RayResultCallback () {}
113115 /* * Called for each object hit by the ray
114- * @param other the other object
115- * @param distance the distance from ray origin to hit point
116- */
116+ * @param other the other object
117+ * @param distance the distance from ray origin to hit point
118+ */
117119 virtual void addSingleResult (const MovableObject* other, float distance) = 0;
118120};
119121
@@ -135,7 +137,7 @@ class _OgreBulletExport CollisionWorld
135137 btCollisionObject* addCollisionObject (Entity* ent, ColliderType ct, int group = 1 , int mask = -1 );
136138
137139 void rayTest (const Ray& ray, RayResultCallback* callback, float maxDist = 1000 );
138- void attachCollisionObject (btCollisionObject * collisionObject, Entity * ent, int group = 1 , int mask = -1 );
140+ void attachCollisionObject (btCollisionObject* collisionObject, Entity* ent, int group = 1 , int mask = -1 );
139141};
140142
141143// / helper class for kinematic body motion
@@ -145,6 +147,7 @@ class _OgreBulletExport KinematicMotionSimple : public btActionInterface
145147 std::vector<btTransform> mCollisionTransforms ;
146148 btPairCachingGhostObject* mGhostObject ;
147149 btVector3 mCurrentPosition ;
150+ btVector3 mPreviousPosition ;
148151 btQuaternion mCurrentOrientation ;
149152 btManifoldArray mManifoldArray ;
150153 btScalar mMaxPenetrationDepth ;
@@ -157,6 +160,15 @@ class _OgreBulletExport KinematicMotionSimple : public btActionInterface
157160 void preStep (btCollisionWorld* collisionWorld);
158161 void playerStep (btCollisionWorld* collisionWorld, btScalar dt);
159162 void setupCollisionShapes (btCollisionObject* body);
163+ btVector3 computeReflectionDirection (const btVector3& direction, const btVector3& normal);
164+ btVector3 parallelComponent (const btVector3& direction, const btVector3& normal);
165+ btVector3 perpindicularComponent (const btVector3& direction, const btVector3& normal);
166+ void sweepTest (btCollisionWorld* world, const btTransform& start, const btTransform& end,
167+ btCollisionWorld::ClosestConvexResultCallback& callback, float margin = 0 .0f );
168+ void updateTargetPositionBasedOnCollision (bool current, btVector3& targetPosition, const btVector3& hitNormal,
169+ btScalar tangentMag = 1 .0f , btScalar normalMag = 1 .0f );
170+ void stepForwardAndStrafe (bool current, btCollisionWorld* world, const btVector3& motion, float margin = 0 .0f ,
171+ int iterations = 10 );
160172
161173public:
162174 KinematicMotionSimple (btPairCachingGhostObject* ghostObject, Node* node);
@@ -169,11 +181,9 @@ class _OgreBulletExport KinematicMotionSimple : public btActionInterface
169181 int getManifolds () const { return mManifolds ; }
170182 /* * Enable manual narrow phase
171183 * @param enable if enabled
172- */
173- void enableManualNarrowPhase (bool enable)
174- {
175- mAllowManualNarrowPhase = enable;
176- }
184+ */
185+ void enableManualNarrowPhase (bool enable) { mAllowManualNarrowPhase = enable; }
186+
177187 /* * Report manual narrow phase enabled status */
178188 bool isManualNarrowPhaseEnabled () const { return mAllowManualNarrowPhase ; }
179189};
@@ -187,13 +197,13 @@ class _OgreBulletExport DynamicsWorld : public CollisionWorld
187197 DynamicsWorld (btDynamicsWorld* btWorld) : CollisionWorld(btWorld) {}
188198
189199 /* * Add an Entity as a rigid body to the DynamicsWorld
190- * @param mass the mass of the object
191- * @param ent the entity to control
192- * @param ct the collider type
193- * @param listener a listener to call on collision with other objects
194- * @param group the collision group
195- * @param mask the collision mask
196- */
200+ * @param mass the mass of the object
201+ * @param ent the entity to control
202+ * @param ct the collider type
203+ * @param listener a listener to call on collision with other objects
204+ * @param group the collision group
205+ * @param mask the collision mask
206+ */
197207 btRigidBody* addRigidBody (float mass, Entity* ent, ColliderType ct, CollisionListener* listener = nullptr ,
198208 int group = 1 , int mask = -1 );
199209 btRigidBody* addKinematicRigidBody (Entity* ent, ColliderType ct, int group = 1 , int mask = -1 );
@@ -206,7 +216,8 @@ class _OgreBulletExport DynamicsWorld : public CollisionWorld
206216 * @param mask the collision mask
207217 * @param debugDraw allow debug drawing
208218 */
209- btRigidBody* addTerrainRigidBody (TerrainGroup* terrainGroup, long x, long y, int group = 1 , int mask = -1 , bool debugDraw = false );
219+ btRigidBody* addTerrainRigidBody (TerrainGroup* terrainGroup, long x, long y, int group = 1 , int mask = -1 ,
220+ bool debugDraw = false );
210221 /* * Add static body for Ogre terrain
211222 * @param terrain the terrain
212223 * @param group the collision group
@@ -215,8 +226,8 @@ class _OgreBulletExport DynamicsWorld : public CollisionWorld
215226 */
216227 btRigidBody* addTerrainRigidBody (Terrain* terrain, int group = 1 , int mask = -1 , bool debugDraw = false );
217228
218- void attachRigidBody (btRigidBody * rigidBody, Entity * ent, CollisionListener* listener = nullptr ,
219- int group = 1 , int mask = -1 );
229+ void attachRigidBody (btRigidBody* rigidBody, Entity* ent, CollisionListener* listener = nullptr , int group = 1 ,
230+ int mask = -1 );
220231 btDynamicsWorld* getBtWorld () const { return static_cast <btDynamicsWorld*>(mBtWorld ); }
221232};
222233
@@ -252,7 +263,10 @@ class _OgreBulletExport DebugDrawer : public btIDebugDraw
252263 drawLine (PointOnB, PointOnB + normalOnB * distance * 20 , color);
253264 }
254265
255- void reportErrorWarning (const char * warningString) override { LogManager::getSingleton ().logWarning (warningString); }
266+ void reportErrorWarning (const char * warningString) override
267+ {
268+ LogManager::getSingleton ().logWarning (warningString);
269+ }
256270
257271 void draw3dText (const btVector3& location, const char * textString) override {}
258272
0 commit comments