Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Stokes <mogurijin@gmail.com>2012-12-26 05:25:53 +0400
committerMitchell Stokes <mogurijin@gmail.com>2012-12-26 05:25:53 +0400
commit13f49f31017f40c137f16183780e1c706598ab2a (patch)
treea0dad2a6de4649f86aa876c773018ec250d00d23 /source/gameengine/Physics/Bullet
parent2c38c32661427b48e548f27f538a15ff2543b84a (diff)
BGE: Adding a maxJumps to the character controller to adjust how many jumps a character can perform before having to touch the ground. By default this is set to 1, which means a character can only jump once before having to touch the ground again. Setting this to 2 allows for double jumping.
Diffstat (limited to 'source/gameengine/Physics/Bullet')
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.cpp61
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.h23
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp16
3 files changed, 77 insertions, 23 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index a1b30ccb001..5a6e90cddd5 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -68,6 +68,48 @@ float gAngularSleepingTreshold;
btVector3 startVel(0,0,0);//-10000);
+BlenderBulletCharacterController::BlenderBulletCharacterController(btMotionState *motionState, btPairCachingGhostObject *ghost, btConvexShape* shape, float stepHeight)
+ : btKinematicCharacterController(ghost,shape,stepHeight,2),
+ m_motionState(motionState),
+ m_jumps(0),
+ m_maxJumps(1)
+{
+}
+
+void BlenderBulletCharacterController::updateAction(btCollisionWorld *collisionWorld, btScalar dt)
+{
+ btKinematicCharacterController::updateAction(collisionWorld,dt);
+ m_motionState->setWorldTransform(getGhostObject()->getWorldTransform());
+}
+
+int BlenderBulletCharacterController::getMaxJumps() const
+{
+ return m_maxJumps;
+}
+
+void BlenderBulletCharacterController::setMaxJumps(int maxJumps)
+{
+ m_maxJumps = maxJumps;
+}
+
+bool BlenderBulletCharacterController::canJump() const
+{
+ return onGround() || m_jumps < m_maxJumps;
+}
+
+void BlenderBulletCharacterController::jump()
+{
+ if (onGround())
+ m_jumps = 0;
+
+ if (!canJump())
+ return;
+
+ m_verticalVelocity = m_jumpSpeed;
+ m_wasJumping = true;
+ m_jumps++;
+}
+
CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci)
:m_cci(ci)
{
@@ -154,25 +196,6 @@ public:
};
-class BlenderBulletCharacterController : public btKinematicCharacterController
-{
-private:
- btMotionState* m_motionState;
-
-public:
- BlenderBulletCharacterController(btMotionState *motionState, btPairCachingGhostObject *ghost, btConvexShape* shape, float stepHeight)
- : btKinematicCharacterController(ghost,shape,stepHeight,2),
- m_motionState(motionState)
- {
- }
-
- virtual void updateAction(btCollisionWorld *collisionWorld, btScalar dt)
- {
- btKinematicCharacterController::updateAction(collisionWorld,dt);
- m_motionState->setWorldTransform(getGhostObject()->getWorldTransform());
- }
-};
-
btRigidBody* CcdPhysicsController::GetRigidBody()
{
return btRigidBody::upcast(m_object);
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index 6df5c85f5c0..91b2e558521 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -391,10 +391,31 @@ struct CcdConstructionInfo
};
-
class btRigidBody;
class btCollisionObject;
class btSoftBody;
+class btPairCachingGhostObject;
+
+class BlenderBulletCharacterController : public btKinematicCharacterController
+{
+private:
+ btMotionState* m_motionState;
+ int m_jumps;
+ int m_maxJumps;
+
+public:
+ BlenderBulletCharacterController(btMotionState *motionState, btPairCachingGhostObject *ghost, btConvexShape* shape, float stepHeight);
+
+ virtual void updateAction(btCollisionWorld *collisionWorld, btScalar dt);
+
+ int getMaxJumps() const;
+
+ void setMaxJumps(int maxJumps);
+
+ virtual bool canJump() const;
+
+ virtual void jump();
+};
///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution.
class CcdPhysicsController : public PHY_IPhysicsController
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index 486411d7e35..f1224babcf7 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -270,10 +270,10 @@ public:
class CharacterWrapper : public PHY_ICharacter
{
private:
- btKinematicCharacterController* m_controller;
+ BlenderBulletCharacterController* m_controller;
public:
- CharacterWrapper(btKinematicCharacterController* cont)
+ CharacterWrapper(BlenderBulletCharacterController* cont)
: m_controller(cont)
{}
@@ -295,6 +295,16 @@ public:
{
m_controller->setGravity(gravity);
}
+
+ virtual int GetMaxJumps()
+ {
+ return m_controller->getMaxJumps();
+ }
+
+ virtual void SetMaxJumps(int maxJumps)
+ {
+ m_controller->setMaxJumps(maxJumps);
+ }
};
class CcdOverlapFilterCallBack : public btOverlapFilterCallback
@@ -2320,7 +2330,7 @@ PHY_ICharacter* CcdPhysicsEnvironment::getCharacterController(KX_GameObject *ob)
{
CcdPhysicsController* controller = (CcdPhysicsController*)ob->GetPhysicsController()->GetUserData();
if (controller->GetCharacterController())
- return new CharacterWrapper(controller->GetCharacterController());
+ return new CharacterWrapper((BlenderBulletCharacterController*)controller->GetCharacterController());
return NULL;
}