Xojo Conferences
XDCMay2019MiamiUSA

How to get a 'human understandable' direction out of a quaternion (Real Studio games Mailinglist archive)

Back to the thread list
Previous thread: Re: How to get a 'human understandable' direction out of a
Next thread: Changing the mouse position


How to get a 'human understandable' direction out of a quaternion   -   Heinz J.Gattringer
  Re: How to get a 'human understandable' direction out of a quaternion   -   Joseph J. Strout

How to get a 'human understandable' direction out of a quaternion
Date: 04.03.05 23:50 (Fri, 4 Mar 2005 17:50:54 -0500)
From: Heinz J.Gattringer
Hello all,

Another question born out of my mathematical limitations regarding
quaternions. In my game all action takes place on a basically
2-dimensional surface. And all my objects are mostly "straight up",
that means 'feet on the ground and head on top', at least while they
are functional in the game. So the rotation of the objects around the
direction-axis they are facing is always the same and has no bearing on
the code.
So many times it would be very practical for me to handle the direction
or facing of my objects like a vector, not a quaternion. This means, I
would be happy to be able to represent the facing of my objects like a
position vector (which every Object3D already has) and a direction
vector (idealy a normalized vector).
The question then: how can I extract a 'direction-vector' out of the
orientation-quaternion, when then "picth" and "roll" components are 0
or always the same?

Greetings,
Heinz Jose

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: How to get a 'human understandable' direction out of a quaternion
Date: 05.03.05 00:05 (Fri, 4 Mar 2005 17:05:24 -0600)
From: Joseph J. Strout
At 5:50 PM -0500 3/4/05, Heinz J.Gattringer wrote:

>So many times it would be very practical for me to handle the
>direction or facing of my objects like a vector, not a quaternion.

Actually, in this case you don't even need a vector; a scalar (i.e.
plain number) will do -- just the amount of rotation around the
vertical axis.

Indeed, in games like this I often have a simple mRotation property
(as Double), which I update as I like, and then on each frame I
simply do:

myObj3D.Orientation.SetRotationAboutAxis( 0, 1, 0, mRotation )

Instead of mRotation, you could think of this as a heading
(mHeading), a term commonly used in navigation. You could even
display this as an actual compass direction by converting to degrees.

>The question then: how can I extract a 'direction-vector' out of the
>orientation-quaternion, when then "picth" and "roll" components are
>0 or always the same?

You can extract a direction vector for ANY quaternion, by simply doing:

dirVec = q.Transform( New Vector3D(0,0,1) )

which takes a vector that points down the Z axis, and rotates it
according to the quaternion.

But I still think you may not need to do this in your case. :)

Best,
- Joe