july
25-09-2010 15:37:23
Hi, I need help with a 3er person camera collision, I have a cameraGoal and cameraPivot like ogre sample character, this work ok, but the problem is the camera collision, I see the character demo of bullet sdk 2.76, and I want to use a ClosestConvexResultCallback with sphere collision shape. This is a sample of the code
When the character is near of the wall, the camera rotate fine but it intersect the model and it’s ugly, then, if I have an smaller sphere collision shape, the camera through the wall. I think I have to fix a minimum distance between the camera and the character, but I don’t know how do that. Please, any suggestions I appreciate it.
Thanks for the time. And sorry with my English ok..
void updateCamera(Ogre::Real deltatime)
{
mCameraPivot->setPosition(mPlayer->getPosition() + Ogre::Vector3::UNIT_Y * 5);
Ogre::Vector3 goalOffset = mCameraGoal->_getDerivedPosition() - mCameraNode->getPosition();
mCameraNode->translate(goalOffset * deltatime * 9.0f);
btVector3 cameraPosition = OgreBtConverter::to(mCameraGoal->_getDerivedPosition());
btSphereShape cameraSphere(2.6);
btTransform cameraFrom,cameraTo;
cameraFrom.setIdentity();
cameraFrom.setOrigin(OgreBtConverter::to(mCameraPivot->getPosition()));
cameraTo.setIdentity();
cameraTo.setOrigin(OgreBtConverter::to(mCameraGoal->_getDerivedPosition()));
btCollisionWorld::ClosestConvexResultCallback cb( cameraFrom.getOrigin(), cameraTo.getOrigin() );
cb.m_collisionFilterMask = btBroadphaseProxy::StaticFilter;
mWorld->getBulletDynamicsWorld()->convexSweepTest(&cameraSphere,cameraFrom,cameraTo,cb);
if (cb.hasHit())
{
btScalar minFraction = cb.m_closestHitFraction;
cameraPosition.setInterpolate3(cameraFrom.getOrigin(),cameraTo.getOrigin(),minFraction);
mCameraNode->setPosition(cameraPosition.getX(),cameraPosition.getY(),cameraPosition.getZ());
}
mCameraNode->lookAt(mCameraPivot->_getDerivedPosition(), Ogre::Node::TS_WORLD);
}When the character is near of the wall, the camera rotate fine but it intersect the model and it’s ugly, then, if I have an smaller sphere collision shape, the camera through the wall. I think I have to fix a minimum distance between the camera and the character, but I don’t know how do that. Please, any suggestions I appreciate it.
Thanks for the time. And sorry with my English ok..