Code: Select all
//this is the ground setup
void CRealObject::setupPhysics()
{
cout<<"setting up physics"<<endl;
if(collObj)
{
delete collObj;
collObj = 0;
}
this->updateAbsolutePosition();
matrix4 transform = getAbsoluteTransformation();
vector3df rot = transform.getRotationDegrees();
btVector3 trans = btVector3(getAbsolutePosition().X,getAbsolutePosition().Y,getAbsolutePosition().Z);
btQuaternion quat = myGame->EulerXYZtoQuat(rot);
btVector3 EulerRotation;
//this function works, i've tested it
myGame->QuaternionToEuler(quat, EulerRotation);//mygame just contains all of my "global" attributes, including the dynamicsworld and others.
vector3df rotation = vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]);
btTransform bulletTransform(quat,trans);
//bulletTransform.setIdentity();
// Give it a default MotionState
btDefaultMotionState *MotionState = new btDefaultMotionState(bulletTransform);
// Create the shape
aabbox3df box = getMesh()->getBoundingBox();
btVector3 HalfExtents( getScale().X*(box.MaxEdge.X - box.MinEdge.X), getScale().Y*(box.MaxEdge.Y - box.MinEdge.Y), getScale().Z*(box.MaxEdge.Z - box.MinEdge.Z));
btCollisionShape *Shape = new btBoxShape(HalfExtents*.5f);
// Add mass
btVector3 LocalInertia;
Shape->calculateLocalInertia(mass, LocalInertia);
collObj = new btRigidBody(mass, MotionState, Shape, LocalInertia);
// Store a pointer to the irrlicht node so we can update it later
collObj->setUserPointer((void *)this);
// Add it to the world
if(myGame)
myGame->getWorld()->addRigidBody(collObj);
myGame->getObjects().push_back(collObj);
}
kinematic = false;
}
//this is the character controller
void CPlayerObject::setupPhysics()
{
btCollisionShape* shape = new btCapsuleShape(.1f,2.f);
body= new btPairCachingGhostObject();
body->setCollisionShape(shape);
myGame->getWorld()->addCollisionObject(body);
controller = new btKinematicCharacterController(body,(btConvexShape*)shape, .25f,1);
myGame->getWorld()->addCharacter(controller);
controller->setUseGhostSweepTest(true);
setBodyToNode();
}//end of setupPhysics
Edit: a raytest works, why wouldn't a sweep test?
Edit 2: Ok, so all I had to do was make the ground a static object and the collision detected. It still doesn't stop falling, however. Why would this be?