tlc
14-02-2008 01:20:42
Hi,
I tried to implement an application with first-person camera moving within a house. The camera should stop advancing if it hits the wall. I used oFusion to load the entire house scene and pass the RootSceneNode as the following:
Then I created the following camera nodes and camera body (size 10x10x10):
In my frameStarted():
At the start, without pressing any keyboard, the first person camera is 'falling' down. When I pressed on any WASD key, the camera moves in the right direction, but falls at the same time. Worst is that it passes through the walls and ground shouldn't it have any collision since I pass camera body to the ogrenewt world??
What else am I missing?
I tried to implement an application with first-person camera moving within a house. The camera should stop advancing if it hits the wall. I used oFusion to load the entire house scene and pass the RootSceneNode as the following:
OgreNewt::CollisionPrimitives::TreeCollisionSceneParser* stat_col = new OgreNewt::CollisionPrimitives::TreeCollisionSceneParser( mWorld );
stat_col->parseScene( mSceneMgr->getRootSceneNode(), true );
OgreNewt::Body* bod = new OgreNewt::Body( mWorld, stat_col );
delete stat_col;
bod->attachToNode( mSceneMgr->getRootSceneNode() );
Then I created the following camera nodes and camera body (size 10x10x10):
mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mCamNode->setScale( Ogre::Vector3(10.0, 10.0, 10.0) );
OgreNewt::Collision* cam_col = new OgreNewt::CollisionPrimitives::Ellipsoid( mWorld, Ogre::Vector3(10.0, 10.0, 10.0) );
mCamBody = new OgreNewt::Body( mWorld, cam_col );
delete cam_col;
mCamBody->attachToNode( mCamNode );
Ogre::Vector3 cam_inertia = OgreNewt::MomentOfInertia::CalcEllipsoidSolid( 40.0, Ogre::Vector3(10.0, 10.0, 10.0) );
mCamBody->setMassMatrix( 40.0, cam_inertia );
mCamBody->setStandardForceCallback();
OgreNewt::BasicJoints::UpVector* uv2 = new OgreNewt::BasicJoints::UpVector( mWorld, mCamBody, Ogre::Vector3::UNIT_Y );
// create child node to the camera node
mCamView = mCamNode->createChildSceneNode( Ogre::Vector3(0.0, 5.0, 0.0) );
mCamView->attachObject(mCamera);
mCamBody->setPositionOrientation(Ogre::Vector3(394, 160, 1665), Ogre::Quaternion(-0.989147, 0.146552, 0.00886817, 0.00569585));
mCamBody->setAutoFreeze(0);
In my frameStarted():
mMouse->capture();
mKeyboard->capture();
Ogre::Vector3 trans, strafe, vec;
Ogre::Quaternion quat;
quat = get_body_orientation(mCamBody);
vec = Ogre::Vector3(0.0, 0.0, -10.0);
trans = quat * vec;
vec = Ogre::Vector3(10.0, 0.0, 0.0);
strafe = quat * vec;
mCamView->pitch( Degree(mMouse->getMouseState().Y.rel * -0.5) );
mCamView->yaw( Degree(mMouse->getMouseState().X.rel * -0.5), SceneNode::TS_WORLD );
if (mKeyboard->isKeyDown(OIS::KC_W))
mCamBody->setVelocity( trans * 6.0 );
if (mKeyboard->isKeyDown(OIS::KC_S))
mCamBody->setVelocity( trans * -1.0 * 6.0 );
if (mKeyboard->isKeyDown(OIS::KC_A))
mCamBody->setVelocity( strafe * 1.0 * 6.0 );
if (mKeyboard->isKeyDown(OIS::KC_D))
mCamBody->setVelocity( strafe * 6.0 );
At the start, without pressing any keyboard, the first person camera is 'falling' down. When I pressed on any WASD key, the camera moves in the right direction, but falls at the same time. Worst is that it passes through the walls and ground shouldn't it have any collision since I pass camera body to the ogrenewt world??
What else am I missing?