problem with rotating body to match Qaurtenion

dudeabot

29-12-2007 16:20:48

im using the code from

http://www.ogre3d.org/wiki/index.php/Qu ... ion_Primer

it works for nodes.. but i need to make the body rotate

here is the code:


mOrientSrc = get_body_orientation(ninjaBody);
mDirection = BodyUtil::get_body_position(cameraFPS->cam_body) - BodyUtil::get_body_position(ninjaBody);
Vector3 src = get_body_orientation(ninjaBody) * Vector3::NEGATIVE_UNIT_Z;
src.y = 0; // Ignore pitch difference angle
mDirection.y = 0;
src.normalise();
Real mDistance = mDirection.normalise();
quat = src.getRotationTo(mDirection);
mOrientDest = quat * mOrientSrc;// We want dest orientation, not a relative rotation (quat)


the next line would be


ninjaNode->setOrientation(mOrientDest );


but what do i use for the body to move?

i was trying setOmega on the forceCallback, but Omega expects a Vector3, and mOrientDest is a quaternion


void Poli3DListener::bodyCallback(OgreNewt::Body* me)
{
Ogre::Real mass;
Ogre::Vector3 inertia;

me->getMassMatrix(mass, inertia);
Ogre::Vector3 force(0,-9.8,0);
force *= mass;

me->addForce( force );

me->setOmega(???);

}


also i know setPositionOrientation() is bad, and cant go for it ;(

ProfesorX

29-12-2007 19:33:21

dudeabot, i think you are missunderstanding how it works the physics engine, you don't have to manually set the position/orientation/velocity of the body (unless yo want to put in it's original position, and with an inicial velocity)

what you have to to, is to use force/torque (see the methods addForce/addTorque of the OgreNewt::Body class).

if you want to move an object, you must use addForce.

if you want to rotate an object, you must use addTorque.

you must test different values, and with different formulas until you find the ones you want.

There are some threads in the forum about movement using forces, i recommend you to do a search.

dudeabot

29-12-2007 23:11:11

you didnt understand my question

the tutorial teaches how to set orientation on the Node

i need to know how to set orientaiton on a body without the use of setPositionOrientation which i know its bad


if you want to rotate an object, you must use addTorque.

you must test different values, and with different formulas until you find the ones you want.


it cant be empirical, andfor other bodys? there should be a formula, i tried many times but without success

also it cant rotate more than its set to: its a chasing system (what if the body is chasing and is not facing what its chasing?)

HexDump

31-12-2007 13:50:17

Same problem here, I would like for example to rotate 180 degrees, but It is really difficult to do with the torque thing :(. If anyone could help it would be nice.

HexDump.

dudeabot

31-12-2007 15:57:31

for now im using setPositionOrientation :|

walaber

01-01-2008 04:36:50

can you please explain what you are trying to do in your project first? that might help us discuss solutions better.

HexDump

01-01-2008 12:51:13

walaber, I can tell you what I´m doing for example (I think the other pal has the same problem):

I have my mesh added to the world, it has a rigid body associated in the physics world. My game is a 3D platformer with 2D playability, so, when I press right, the hero must rotate 180 degrees to look at the opossite direction it was facing, same for left.

What I´m thinking is leave my player out of the simulation, and find a way or something to just use ogrenewt for collision (adding a rigid body that only I will move to mach my entity position, etc...). What do you think?

The problem is that for a game like mine, perhaps using phycis for the player is too much... and only collisions are needed.

Thanks in advance,
HexDump.

walaber

01-01-2008 18:16:10

here is what I did for my trampoline game, which is similar (3d graphics, 2d gameplay)...

1. create an ellipsoid or some other collision body for the main player, and use the 2D Joint to keep it on the 2D plane. you might also want an UpVector to keep it upright.

2. do not use "attachToNode", instead create a custom TransformCallback. in the callback, only use the global position of the physics body for the visual model of the player, not for the direction it is facing. Handle that part with your own code that determines where the character is facing.

this allows you to use the physics for proper interaction with the world, but you don't have to fight with Newton over the exact details of how your character is rotated.

HexDump

01-01-2008 21:29:02

Good point, anyway this is the same that using setPositionOrientation, using current position of the body, and setting the correct orientation, don´t you think?.

Thanks in advance,
HexDUmp.

walaber

02-01-2008 04:28:47

yes. you mean getPositionOrientation, right?