nxogre and force callback?

deshan

26-09-2009 06:38:16

Hi all,
I want to move my first person character to move. Up to now what I have done was when key pressed I apply a force or LinearVelocity on the OGRE3DBody. I am not sure what is better out of orce and LinearVelocity. Following is my code

//--In FPCamera class
void FPCamera::FPCForward()
{
cam_body->setLinearVelocity(NxOgre::Vec3(0, 0, -100));
//cam_body->addForce(NxOgre::Vec3(0, 0, -1000), NxOgre::Enums::ForceMode_Force);
}

//--In Framelistner class
bool FPCFrameListener::keyPressed(const OIS::KeyEvent &e)
{
switch (e.key)
{
case OIS::KC_UP:
case OIS::KC_W:
fpCamera->FPCForward();
break;
.....
}


The problem is character stops after some time because of the friction. Now I want apply the force or velocity continuously until the key released. I need to know how you people manage to handle that problem? Could you please tell me how you made your first person camera character with physics applying to it?

Thank You

deshan

27-09-2009 08:54:03

Can any one please answer?

This was the solution from ogrenewt when I was ask from them some time back.

when create body in constructor of FPPCamera class

Body* cam_body;
cam_body->setCustomForceAndTorqueCallback<FPPCamera>(&FPPCamera::camera_force_callback,this);


this is custom callback function in FPPCamera class

void FPPCamera::camera_force_callback(OgreNewt::Body* body)
{
....
Ogre::Vector3 V1(qq * this->MyVel);
Ogre::Vector3 V0 = body->getVelocity();
Ogre::Vector3 acel = (V1 - V0);
force.x = acel.x;
force.z = acel.z;
body->addForce( force );
...
}


function to move character forward in FPPCamera class

void FPPCamera::FPPup()
{
this->MyVel = this->fps_speed*30;
}


and in GameFrameListener class

bool GameFrameListener::keyPressed(const OIS::KeyEvent &e)
{
switch (e.key)
{
case OIS::KC_UP:
case OIS::KC_W:
fppccam->FPPup();
break;
.....
}
}


So What I am doing is when keypress it just update the velocity by calling the FPPup() method in FPPCamera class . I assume that callback function continuesly listen to this. Because here character never stops until the key released. The exact thing I want to do with nxogre.

Please some one?

Again I am explaining what I want to do-
I want to do is when KC_UP pressed move my character continuously until the key released.