Promo

12-07-2007 19:36:23

Hello,

I'm pretty new with *Ogre and more in general with game-programming.

I would like to know if there is any easy (or feasible at least) way of determining the vector describing the axis of a body. Since many say that a picture is worth a thousand words, I illustrate my issue in the picture below: what I would like to achieve is finding the yellow vector v (only in the (x,z) plane since I'm only interested in floor movements) dynamically during my simulation.

I've tried using the function getGlobalOrientation() available in the body class, but I had no luck figuring out how to use the returned quaternion (and frankly, I'm not even sure that it would help me solve my problem)

What do you think about it? Should I dig harder in the wonderful world of quaternions, or should I maybe play around with the bounding box and the global position of the body?

Thank you in advance, any help will be greatly appreciated

Cheers

PS: using Eihort + NxOgre0.4RC3

Caphalor

12-07-2007 23:52:53

Maybe it's rubbish, but try this:

`mBody->getGlobalOrientation().zAxis();`

Promo

13-07-2007 10:21:58

Maybe it's rubbish, but try this:

`mBody->getGlobalOrientation().zAxis();`

Thanks for the advice, I've tried it out but unfortunately it doesn't seem to report the right vector

I was thinking about it a little more analytically, and I think that probably the only solution would be to someway localize the (coordinates of) two extremities of the mesh and then get the directional vector from their subtraction.. I'm wondering how to localize those points though..

or does anyone see another option? Am I ignoring some useful function in Ogre/NxOgre/PhysX that could help me out maybe?

betajaen

13-07-2007 10:43:45

What about normalising the vector?

`Vector3 direction = mBody->getGlobalPosition().normaliseCopy()`

Or am I not understanding what it is all about.

Promo

13-07-2007 11:24:37

Hi there,

I'm afraid I didn't explain my problem too well, and that screenshot didn't really help eh eh.

What I am interested in is the vector of the "axis" of my object (i.e., knowing where that 3d-cake-piece "points").

I've replaced the screenshot (with a less confusing one hopefully). Btw, I've also aligned the blender model to its axes (as in the following picture):

shouldn't I use the function getGlobalOrientation() to get what I need?

Thanks in advance

betajaen

13-07-2007 11:31:13

Oh. I think I get you.

So if your Slice of Cake was up it would be: (0 1 0) and if it was down (0 -1 0)?

Promo

13-07-2007 11:47:01

Oh. I think I get you.

So if your Slice of Cake was up it would be: (0 1 0) and if it was down (0 -1 0)?

Yep, exactly. In my case I would be interested in the XZ coordinates only though, as the cake slice should only slide along the floor plane without rolling.

I'm trying to solve the problem doing what the "Quaternion primer" [1] says:

"*(1) From the comments, getOrientation() returns a Quaternion describing the objects rotation in relation to the root. Multiplying it by UNIT_X, which is the objects initial facing position in this case, ***provides a vector describing its current facing direction**."

So after I extract that vector, I've prepared an easy way of checking whether I get the right vector: I look for the angle between (1,0,0) and that vector while moving around that piece of cake in "interesting" positions

` Vector3 unitX(1,0,0);`

Vector3 mBodyAxis = mScene->findBody("bodyName")->getGlobalOrientation()*Vector3::UNIT_Y;

std::cout << "angle: " << 180/PI * (acos( unitX.dotProduct(mBodyAxis) / (unitX.length() * mBodyAxis.length()) )) << "\n";

but I haven't been lucky yet

[1]

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

Promo

13-07-2007 13:26:24

I think I have found an acceptable solution to my problem, by tuning a little bit the vector multiplied with the quaternion (see above code) like this:

` Vector3 mBodyAxis = mScene->findBody("bodyName")->getGlobalOrientation()*(Vector3::UNIT_Y+Vector3(0.6,0.6,0.6));`

using this method I can get fairly precise axis and angles. I guess the remaining error/deviation could be due to a slightly wrong axis alignment in the modeling (blender) phase as well as due to my tuning-by-hand eh eh

Anyway I'm always open to new and eventually more precise solutions

See you