diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2013-01-30 09:55:17 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2013-01-30 09:55:17 +0400 |
commit | 9191b783bb2bc1a2d4be2b2cd215735e68353a56 (patch) | |
tree | 8440c8b155a69580b358ded134bad49e27bb8eba /source/gameengine/Physics | |
parent | 26ee2a1f79c3513ca9eaeb6a3a8d855c37088468 (diff) |
BGE: Some various changes to make moving the character physics type easier:
* Undoing the previous applyMovement() changes for characters. This was causing bugs for the Motion Actuator.
* Creating a Character Motion type for the Motion Actuator with specific controls for characters. This includes moving, rotating and jumping.
* Adding a KX_CharacterWrapper.walkDirection to set the character's direction and speed.
Note, this also resolves the following bugs:
[#33585] "Setting dLoc of motion actuator [0,0,0] via python won't stop object" reported by Manuel Bellersen (urfoex)
[#33503] "Character physics type won´t accept more than one motion anymore" reported by Mr Larodos
Diffstat (limited to 'source/gameengine/Physics')
4 files changed, 73 insertions, 11 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index cf96f22a345..0bf11fd2f9d 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -115,6 +115,11 @@ void BlenderBulletCharacterController::jump() m_jumps++; } +const btVector3& BlenderBulletCharacterController::getWalkDirection() +{ + return m_walkDirection; +} + CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci) :m_cci(ci) { @@ -926,20 +931,27 @@ void CcdPhysicsController::RelativeTranslate(float dlocX,float dlocY,float dloc if (local) dloc = xform.getBasis()*dloc; - if (m_characterController) - { - m_characterController->setWalkDirection(dloc/GetPhysicsEnvironment()->getNumTimeSubSteps()); - } - else - { - - xform.setOrigin(xform.getOrigin() + dloc); - SetCenterOfMassTransform(xform); - } + xform.setOrigin(xform.getOrigin() + dloc); + SetCenterOfMassTransform(xform); } } +void CcdPhysicsController::SetWalkDirection(float dirX,float dirY,float dirZ,bool local) +{ + + if (m_object && m_characterController) + { + btVector3 dir(dirX,dirY,dirZ); + btTransform xform = m_object->getWorldTransform(); + + if (local) + dir = xform.getBasis()*dir; + + m_characterController->setWalkDirection(dir/GetPhysicsEnvironment()->getNumTimeSubSteps()); + } +} + void CcdPhysicsController::RelativeRotate(const float rotval[9],bool local) { if (m_object) @@ -1267,6 +1279,13 @@ void CcdPhysicsController::applyImpulse(float attachX,float attachY,float attac } } + +void CcdPhysicsController::Jump() +{ + if (m_object && m_characterController) + m_characterController->jump(); +} + void CcdPhysicsController::SetActive(bool active) { } @@ -1323,6 +1342,24 @@ void CcdPhysicsController::GetVelocity(const float posX,const float posY,const linvZ = 0.f; } } + +void CcdPhysicsController::GetWalkDirection(float& dirX,float& dirY,float& dirZ) +{ + if (m_object && m_characterController) + { + const btVector3 dir = m_characterController->getWalkDirection(); + dirX = dir.x(); + dirY = dir.y(); + dirZ = dir.z(); + } + else + { + dirX = 0.f; + dirY = 0.f; + dirZ = 0.f; + } +} + void CcdPhysicsController::getReactionForce(float& forceX,float& forceY,float& forceZ) { } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index b151c2f6b59..d06403a55a2 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -417,6 +417,8 @@ public: virtual bool canJump() const; virtual void jump(); + + const btVector3& getWalkDirection(); }; ///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution. @@ -424,7 +426,7 @@ class CcdPhysicsController : public PHY_IPhysicsController { protected: btCollisionObject* m_object; - btKinematicCharacterController* m_characterController; + BlenderBulletCharacterController* m_characterController; class PHY_IMotionState* m_MotionState; @@ -517,6 +519,7 @@ protected: // kinematic methods virtual void RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local); + virtual void SetWalkDirection(float dirX,float dirY,float dirZ,bool local); virtual void RelativeRotate(const float drot[9],bool local); virtual void getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal); virtual void setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal); @@ -531,6 +534,7 @@ protected: virtual void SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local); virtual void SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local); virtual void applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ); + virtual void Jump(); virtual void SetActive(bool active); // reading out information from physics @@ -538,6 +542,7 @@ protected: virtual void GetAngularVelocity(float& angVelX,float& angVelY,float& angVelZ); virtual void GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ); virtual void getReactionForce(float& forceX,float& forceY,float& forceZ); + virtual void GetWalkDirection(float& dirX,float& dirY,float& dirZ); // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted virtual void setRigidBody(bool rigid); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index cadba97023e..254624cd8a0 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -310,6 +310,22 @@ public: { return m_controller->getJumpCount(); } + + virtual void SetWalkDirection(PHY__Vector3 dir) + { + btVector3 vec = btVector3(dir[0], dir[1], dir[2]); + m_controller->setWalkDirection(vec); + } + + virtual PHY__Vector3 GetWalkDirection() + { + btVector3 vec = m_controller->getWalkDirection(); + PHY__Vector3 retval; + retval[0] = vec[0]; + retval[1] = vec[1]; + retval[2] = vec[2]; + return retval; + } }; class CcdOverlapFilterCallBack : public btOverlapFilterCallback diff --git a/source/gameengine/Physics/common/PHY_ICharacter.h b/source/gameengine/Physics/common/PHY_ICharacter.h index 63f6c0bd18a..8a599452816 100644 --- a/source/gameengine/Physics/common/PHY_ICharacter.h +++ b/source/gameengine/Physics/common/PHY_ICharacter.h @@ -15,6 +15,7 @@ class PHY_ICharacter { public: + virtual ~PHY_ICharacter(){}; virtual void Jump()= 0; virtual bool OnGround()= 0; @@ -27,6 +28,9 @@ public: virtual int GetJumpCount()= 0; + virtual void SetWalkDirection(PHY__Vector3 dir)=0; + virtual PHY__Vector3 GetWalkDirection()=0; + #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_ICharacter") #endif |