Linaxys
25-08-2009 11:54:24
Hello,
I'm trying to make my FPS camera with a CapsuleCollisionShape.
The result is that : View My Video
It jumps randomly sometimes and the speed is not really good, I think increasing the gravity is not the good solution.
I create the world's mesh :
The player's creation :
Player movement and rotation :
Can someone tell me what I am doing wrong, please ?
Thanks for your replies.
I'm trying to make my FPS camera with a CapsuleCollisionShape.
The result is that : View My Video
It jumps randomly sometimes and the speed is not really good, I think increasing the gravity is not the good solution.
I create the world's mesh :
Ogre::Plane plane;
plane.normal = Ogre::Vector3::UNIT_Y;
plane.d = 100;
Ogre::MeshManager::getSingleton().createPlane("planeMesh",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
1500,1500,20,20,true,1,60,60,Ogre::Vector3::UNIT_Z);
Ogre::Entity* planeEnt = m_SceneMgr->createEntity( "plane", "planeMesh" );
planeEnt->setMaterialName("Examples/Rockwall");
planeEnt->setCastShadows(false);
Ogre::SceneNode *planeNode = m_SceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,0));
planeNode->attachObject(planeEnt);
OgreBulletCollisions::StaticMeshToShapeConverter *trimeshConverter = new OgreBulletCollisions::StaticMeshToShapeConverter(planeEnt);
OgreBulletCollisions::TriangleMeshCollisionShape *sceneTriMeshShape = trimeshConverter->createTrimesh();
delete trimeshConverter;
OgreBulletDynamics::RigidBody *planeRigid = new OgreBulletDynamics::RigidBody("planeRigid", oWorld);
planeRigid->setStaticShape(planeNode, sceneTriMeshShape, 0.0f, 0.8f, Ogre::Vector3::ZERO);
The player's creation :
m_Shape = new OgreBulletCollisions::CapsuleCollisionShape(8, 15, Ogre::Vector3::UNIT_Y);
m_Body = new OgreBulletDynamics::RigidBody("playerBody", m_DynamicsWorld);
Ogre::SceneNode *cameraNode = m_SceneMgr->getRootSceneNode()->createChildSceneNode("playerNode");
cameraNode->attachObject(m_Camera);
m_Body->setShape(cameraNode, m_Shape, 0.0f, 0.0f, 1.0f, m_Camera->getPosition());
m_Body->getBulletRigidBody()->setSleepingThresholds(0.0f,0.0f);
m_Body->getBulletRigidBody()->setRestitution(0.0f);
m_Body->getBulletRigidBody()->setAngularFactor(0.0f);
m_Body->setLinearVelocity(Ogre::Vector3(0,-50,0));
Player movement and rotation :
void Player::Move(bool fwd, bool bck, bool rgt, bool lft, bool up, bool dwn)
{
Ogre::Vector3 walkDirection = m_Body->getLinearVelocity();
Ogre::Real newVelX = 0, newVelY = walkDirection.y, newVelZ = 0;
Ogre::Quaternion quat = m_Camera->getOrientation();
if (lft)
newVelX = -100;
if (rgt)
newVelX = 100;
if (fwd)
newVelZ = -100;
if (bck)
newVelZ = 90;
walkDirection = quat * Ogre::Vector3(newVelX,0,newVelZ);
walkDirection.y = newVelY;
m_Body->setLinearVelocity(walkDirection);
}
void Player::Rotate(int axisX, int axisY)
{
Ogre::Real oldPitch = m_Camera->getOrientation().getPitch().valueDegrees();
Ogre::Real oldYaw = m_Camera->getOrientation().getYaw().valueDegrees();
if (m_Camera->getOrientation().getPitch().valueDegrees() < 85 &&
m_Camera->getOrientation().getPitch().valueDegrees() > -85)
m_Camera->pitch( Ogre::Degree(axisY * -0.1) );
if (m_Camera->getOrientation().getPitch().valueDegrees() >= 85 ||
m_Camera->getOrientation().getPitch().valueDegrees() <= -85)
m_Camera->pitch( Ogre::Degree(axisY * 0.1) );
m_Camera->yaw( Ogre::Degree(axisX * -0.1) );
}
Can someone tell me what I am doing wrong, please ?
Thanks for your replies.