adimpulse on correct direction

dudeabot

01-01-2008 14:08:03

im doing this way for now,


if (BodyUtil::get_body_position(info.mBody).z > BodyUtil::get_body_position(cameraFPS->cam_body).z){
info.mBody->addImpulse(Vector3(0,0,50),localpt);
}
else{
info.mBody->addImpulse(Vector3(0,0,-50),localpt);
}


but depending on the cam position, it looks very unrealistic, how would i go to calculate the impulse Vector automatically?

thanks!

walaber

01-01-2008 18:18:03

whta are you trying to do? keep an object on-screen or something?

dudeabot

01-01-2008 22:15:15

im trying to simulate a bullet hit, using a raycast as the demo "Demo04_Raycasting",

as my mouse is always centered (FPS Style), i do this:


Ray camray = mCamera->getCameraToViewportRay(0.5,0.5);

Vector3 start = camray.getOrigin();
Vector3 end = camray.getPoint( 100.0 );

OgreNewt::BasicRaycast* ray = new OgreNewt::BasicRaycast( mWorld, start, end );
OgreNewt::BasicRaycast::BasicRaycastInfo info = ray->getFirstHit();

if (info.mBody)
{
// a body was found. first let's find the point we clicked, in local coordinates of the body.
Ogre::Vector3 bodpos;
Ogre::Quaternion bodorient;

info.mBody->getPositionOrientation( bodpos, bodorient );

// info.mDistance is in the range [0,1].
Ogre::Vector3 globalpt = camray.getPoint( 100.0 * info.mDistance );
Ogre::Vector3 localpt = bodorient.Inverse() * (globalpt - bodpos);
info.mBody->addImpulse(Vector3(50,0,50),localpt);
}


the problem is no matter what values i put on the addImpulse function it moves only on the Z axis

walaber

02-01-2008 04:33:33

try replacing the last few lines with this:

// info.mDistance is in the range [0,1].
Ogre::Vector3 globalpt = camray.getPoint( 100.0 * info.mDistance );
nfo.mBody->addImpulse(camray.getDirection() * impulsePower, globalpt);


impulsePower would be a value representing the power of the hit.

that should push away on the point on the body where the ray hit.

dudeabot

02-01-2008 13:14:42

thanks walaber!

now its looking nice :)