GiDEoN
26-05-2006 13:32:29
I cannot get OgreNewt to work the way I like it , after trying 1,5 week i've decided I ask for help.
The camera system I use: http://www.ogre3d.org/wiki/index.php/Creating_a_simple_first-person_camera_system
My code is below:
Here I setup the camerasystem. It uses 4 nodes as the tutorial says. It works just fine except I can fly, I want the gravity of 'Newton' to solve this:) as if I solve it with gravity, I can walk stairs (with an invisible plane over it). And thats all I need in my project(besides not going through walls).
My terraincode: (removed, working properly)
My movement code:
Framestarted event:
Updated Question:
I've implemented the 'shooting blocks mechanism' from Example 1 and that works just fine. So the 'Newton World' is setup right, and Newton is gettings its updates ( using mWorld->update ( evt.timesincelastframe ) )
When I press F1 to show the debugging lines(i know that its F3 when I use default files like basiclistener. But i'm not using any exampleApplication/fameListener file ) I can see the collision object that is supposed to be attached to the cameranode. But its not moving while my camera is! I asumed because I attached the collisionbody to mCamNode, it would move with it (but it isn't)
What am I doing wrong? I've looked at all examples(too bad their ain't really a FPS camera tutorial with gravity).
Also currently none of the collision methods are working for the camera. The camera can go skyhigh and through the floor. How do I fix this?
I'm sure someone who understand this can give me a few hints. I'm clueless.
//another note
I'm not using ExampleApplication.H or ExampleFramelistener.h from Ogre. My gameloop renders 1 frame at a time using mRoot->renderOneFrame();
I've searched the forums and tried out a lot, i just cannot get it to work
The camera system I use: http://www.ogre3d.org/wiki/index.php/Creating_a_simple_first-person_camera_system
My code is below:
Here I setup the camerasystem. It uses 4 nodes as the tutorial says. It works just fine except I can fly, I want the gravity of 'Newton' to solve this:) as if I solve it with gravity, I can walk stairs (with an invisible plane over it). And thats all I need in my project(besides not going through walls).
void GameHandler::setCamera (Ogre::Camera *cam)
{
mCamera = cam;
mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
// Create the camera's yaw node as a child of camera's top node.
mCamYawNode = mCamNode->createChildSceneNode();
// Create the camera's pitch node as a child of camera's yaw node.
mCamPitchNode = mCamYawNode->createChildSceneNode();
//Create camera roll node
mCamRollNode = mCamPitchNode->createChildSceneNode();
mCamRollNode->attachObject ( mCamera );
//mCamRollNode->setFixedYawAxis( true );
//Set camera position
mCamNode->setPosition ( Vector3(0, 2000, -2500 ));
/*
Newton
*/
Ogre::Vector3 size( 1.0 , 1.0, 1.0);
//Make collision (use the Ho ;))
colHo = new OgreNewt::CollisionPrimitives::Ellipsoid( mWorld, size );
//Make body
camBody = new OgreNewt::Body( mWorld, colHo );
camBody->setAutoFreeze(0);
//Gravity
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcEllipsoidSolid( 70.0, size );
camBody->setMassMatrix( 70.0, inertia );
//Damping
camBody->setLinearDamping ( 0.01f );
camBody->setAngularDamping ( Vector3(0.01f, 0.01f, 0.01f ));
//Attach
camBody->setPositionOrientation ( mCamNode->getWorldPosition(), mCamNode->getWorldOrientation() );
camBody->attachToNode( mCamNode );
//Callback
camBody->setStandardForceCallback();
//Upfactor
OgreNewt::BasicJoints::UpVector* mUpVec = new OgreNewt::BasicJoints::UpVector(mWorld, camBody, Ogre::Vector3::UNIT_Y);
//Set Userdata
camBody->setUserData(this);
//clean up
delete colHo;
//Log event
mXmlHandler->writeLog( "Added psychics to camera" );
OgreNewt::Debugger::getSingleton().init( mSceneMgr );
}
My terraincode: (removed, working properly)
My movement code:
bool GameHandler::keyPressed(const OIS::KeyEvent &e)
{
//Camere movement
if( e.key == OIS::KC_UP || e.key == OIS::KC_W )
mDirection.z -= mMove;
if( e.key == OIS::KC_DOWN || e.key == OIS::KC_S )
mDirection.z += mMove;
if( e.key == OIS::KC_LEFT || e.key == OIS::KC_A )
mDirection.x -= mMove;
if( e.key == OIS::KC_RIGHT || e.key == OIS::KC_D )
mDirection.x += mMove;
return true;
}
bool GameHandler::keyReleased(const OIS::KeyEvent &e)
{
//Camere movement
if( e.key == OIS::KC_UP || e.key == OIS::KC_W )
mDirection.z += mMove;
if( e.key == OIS::KC_DOWN || e.key == OIS::KC_S )
mDirection.z -= mMove;
if( e.key == OIS::KC_LEFT || e.key == OIS::KC_A )
mDirection.x += mMove;
if( e.key == OIS::KC_RIGHT || e.key == OIS::KC_D )
mDirection.x -= mMove;
if( e.key == OIS::KC_F1 )
OgreNewt::Debugger::getSingleton().showLines( mWorld );
if( e.key == OIS::KC_F2 )
OgreNewt::Debugger::getSingleton().hideLines();
}
Framestarted event:
bool GameHandler::frameStarted(const Ogre::FrameEvent &evt)
{
// Yaws the camera according to the mouse relative movement.
mCamYawNode->yaw(this->mRotX);
// Pitches the camera according to the mouse relative movement.
mCamPitchNode->pitch(this->mRotY);
// Translates the camera according to the translate vector which is
// controlled by the keyboard arrows.
//
// NOTE: We multiply the translateVector by the cameraPitchNode's
// orientation quaternion and the cameraYawNode's orientation
// quaternion to translate the camera accoding to the camera's
// orientation around the Y-axis and the X-axis.
mCamNode->translate( mCamYawNode->getOrientation() * mCamPitchNode->getOrientation() * mDirection * evt.timeSinceLastFrame, Ogre::SceneNode::TS_LOCAL);
// Angle of rotation around the X-axis.
pitchAngle = (2 * Ogre::Degree(Ogre::Math::ACos( mCamPitchNode->getOrientation().w)).valueDegrees());
// Just to determine the sign of the angle we pick up above, the
// value itself does not interest us.
pitchAngleSign = mCamPitchNode->getOrientation().x;
// Limit the pitch between -90 degress and +90 degrees, Quake3-style.
if(pitchAngle > 90.0f)
{
if(pitchAngleSign > 0)
// Set orientation to 90 degrees on X-axis.
mCamPitchNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f), Ogre::Math::Sqrt(0.5f), 0, 0));
else if(pitchAngleSign < 0)
// Sets orientation to -90 degrees on X-axis.
mCamPitchNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f), -Ogre::Math::Sqrt(0.5f), 0, 0));
}
//Reset mMouse rotations
mRotX = 0;
mRotY = 0;
//Update Newton
mWorld->update ( evt.timeSinceLastFrame );
return true;
}
Updated Question:
I've implemented the 'shooting blocks mechanism' from Example 1 and that works just fine. So the 'Newton World' is setup right, and Newton is gettings its updates ( using mWorld->update ( evt.timesincelastframe ) )
When I press F1 to show the debugging lines(i know that its F3 when I use default files like basiclistener. But i'm not using any exampleApplication/fameListener file ) I can see the collision object that is supposed to be attached to the cameranode. But its not moving while my camera is! I asumed because I attached the collisionbody to mCamNode, it would move with it (but it isn't)
What am I doing wrong? I've looked at all examples(too bad their ain't really a FPS camera tutorial with gravity).
Also currently none of the collision methods are working for the camera. The camera can go skyhigh and through the floor. How do I fix this?
I'm sure someone who understand this can give me a few hints. I'm clueless.
//another note
I'm not using ExampleApplication.H or ExampleFramelistener.h from Ogre. My gameloop renders 1 frame at a time using mRoot->renderOneFrame();
I've searched the forums and tried out a lot, i just cannot get it to work