add no gravity, no collision and remove debug messages.

This commit is contained in:
gugus 2011-03-17 11:00:46 +01:00
parent 79fba7e77e
commit d872d09081
4 changed files with 41 additions and 10 deletions

View file

@ -22,7 +22,6 @@ subject to the following restrictions:
#include "LinearMath/btDefaultMotionState.h"
#include "btKinematicCharacterController.h"
#include <iostream>
///@todo Interact with dynamic objects,
///Ride kinematicly animated platforms properly
///Support ducking
@ -132,6 +131,8 @@ btKinematicCharacterController::btKinematicCharacterController( btPairCachingGho
m_wasJumping = false;
setMaxSlope( btRadians( 45.0 ) );
mCollision = true;
}
@ -142,9 +143,10 @@ btKinematicCharacterController::~btKinematicCharacterController ()
bool btKinematicCharacterController::recoverFromPenetration( btCollisionWorld* collisionWorld )
{
//std::cout << "recover!!!!";
bool penetration = false;
if(!mCollision) return penetration;
collisionWorld->getDispatcher()->dispatchAllCollisionPairs( internalGhostObject->getOverlappingPairCache(),
collisionWorld->getDispatchInfo(),
collisionWorld->getDispatcher() );
@ -172,10 +174,6 @@ bool btKinematicCharacterController::recoverFromPenetration( btCollisionWorld* c
for( int p = 0; p < manifold->getNumContacts(); p++ )
{
const btManifoldPoint&pt = manifold->getContactPoint( p );
if(manifold->getBody1() == externalGhostObject) std::cout << "external!!";
if(manifold->getBody0() == externalGhostObject) std::cout << "external!!";
if(manifold->getBody1() == internalGhostObject) std::cout << "internal!!";
if(manifold->getBody0() == internalGhostObject) std::cout << "internal!!";
if( (manifold->getBody1() == externalGhostObject && manifold->getBody0() == internalGhostObject)
||(manifold->getBody0() == externalGhostObject && manifold->getBody1() == internalGhostObject) )
{
@ -194,7 +192,6 @@ bool btKinematicCharacterController::recoverFromPenetration( btCollisionWorld* c
currentPosition += pt.m_normalWorldOnB * directionSign * dist * m_recoveringFactor;
penetration = true;
std::cout << "recover!!!!";
}
}
}
@ -219,6 +216,13 @@ btVector3 btKinematicCharacterController::stepUp( btCollisionWorld* world, const
{
btVector3 targetPosition = currentPosition + getUpAxisDirections()[ m_upAxis ] * ( m_stepHeight + ( m_verticalOffset > btScalar( 0.0 ) ? m_verticalOffset : 0.0 ) );
//if the no collisions mode is on, no need to go any further
if(!mCollision)
{
currentStepOffset = m_stepHeight;
return targetPosition;
}
// Retrieve the collision shape
//
btCollisionShape* collisionShape = externalGhostObject->getCollisionShape();
@ -319,6 +323,9 @@ btVector3 btKinematicCharacterController::stepForwardAndStrafe( btCollisionWorld
//
btVector3 targetPosition = currentPosition + walkMove;
//if the no collisions mode is on, no need to go any further
if(!mCollision) return targetPosition;
// Retrieve the collision shape
//
btCollisionShape* collisionShape = externalGhostObject->getCollisionShape();
@ -400,6 +407,9 @@ btVector3 btKinematicCharacterController::stepDown( btCollisionWorld* collisionW
//
btVector3 targetPosition = currentPosition - stepDrop;
//if the no collisions mode is on, no need to go any further
if(!mCollision) return targetPosition;
btTransform start;
start.setIdentity();
start.setOrigin( currentPosition );

View file

@ -159,6 +159,9 @@ public:
}
bool onGround() const;
//if set to false, there will be no collision.
bool mCollision;
};
#endif // KINEMATIC_CHARACTER_CONTROLLER_H

View file

@ -34,7 +34,7 @@ namespace Physic
externalGhostObject = new PairCachingGhostObject(name);
externalGhostObject->setWorldTransform( transform );
btScalar externalCapsuleHeight = 90;
btScalar externalCapsuleHeight = 130;
btScalar externalCapsuleWidth = 16;
externalCollisionShape = new btCapsuleShapeZ( externalCapsuleWidth, externalCapsuleHeight );
@ -47,7 +47,7 @@ namespace Physic
internalGhostObject = new PairCachingGhostObject(name);
internalGhostObject->setWorldTransform( transform );
//internalGhostObject->getBroadphaseHandle()->s
btScalar internalCapsuleHeight = 88;
btScalar internalCapsuleHeight = 120;
btScalar internalCapsuleWidth = 15;
internalCollisionShape = new btCapsuleShapeZ( internalCapsuleWidth, internalCapsuleHeight );
@ -56,8 +56,12 @@ namespace Physic
internalGhostObject->setCollisionShape( internalCollisionShape );
internalGhostObject->setCollisionFlags( btCollisionObject::CF_CHARACTER_OBJECT );
mCharacter = new btKinematicCharacterController( externalGhostObject,internalGhostObject,btScalar( 10 ),1,20,20,9.8,0.2 );
mCharacter = new btKinematicCharacterController( externalGhostObject,internalGhostObject,btScalar( 10 ),1,9.8,20,9.8,0.2 );
mCharacter->setUpAxis(btKinematicCharacterController::Z_AXIS);
mCharacter->setUseGhostSweepTest(false);
mCharacter->mCollision = false;
setGravity(0);
}
PhysicActor::~PhysicActor()
@ -69,6 +73,16 @@ namespace Physic
delete externalCollisionShape;
}
void PhysicActor::setGravity(float gravity)
{
mCharacter->setGravity(gravity);
}
void PhysicActor::enableCollisions(bool collision)
{
mCharacter->mCollision = collision;
}
void PhysicActor::setWalkDirection(const btVector3& mvt)
{
mCharacter->setWalkDirection( mvt );

View file

@ -68,6 +68,10 @@ namespace Physic
void setRotation(const btQuaternion& quat);
void setGravity(float gravity);
void enableCollisions(bool collision);
btVector3 getPosition(void);
btQuaternion getRotation(void);