Xojo Conferences
XDCMay2019MiamiUSA

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

Back to the thread list
Previous thread: Was: Re: How to get a 'human understandable' direction out of a quaternion
Next thread: How to get a 'human understandable' direction out of a quaternion


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

Re: How to get a 'human understandable' direction out of a
Date: 05.03.05 23:45 (Sat, 5 Mar 2005 17:45:40 -0500)
From: Heinz J.Gattringer
On Mar 5, 2005, at 1:00 PM,
<email address removed> wrote:

> 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.

I actually am working with something like that. I have a property
myHeading which holds the current direction in radians and I update my
3D-object's orientation with a yaw statement:
myObj3D.yaw theRequiredAmount
myHeading = myHeading + theRequiredAmount
I works quite well, although it seems to me a bit redundant to keep
another property next to the orientation to keep track of an object's
heading. But I am quite happy with this, since it appears to be faster
than doing complicated calculations on the orientation quaternion in
order to extract a heading in degrees.

But I did not know that this:
> myObj3D.Orientation.SetRotationAboutAxis( 0, 1, 0, mRotation )
also works so good. In particular, I did not know you could hand the
thing an absolute heading, I thought it was a relative thing. That of
course makes that method much more powerful and useful. Tried it in my
game and works with no hitch, but my solution is I think some 2% faster
in terms of fps I get (although this could be just an illusion). Good
to know though.

> 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. :)

Yes, I need this (I think). Not for the case mentioned above which I
already had solved and you showed another convenient way to do, but for
an A.I. thing. I want the computer opponent to be able to "imagine" a
picture of the current position of the objects in the game, make some
assumptions as to where they could be a bit in the future and then act
sort of smartly upon those assumptions. For this I believe a
heading-vector (combined with speed) might be more practical than just
a heading.

Again, I thought this Transform method was a relative thing, depending
on the "separation", if I may call it so, from the handed vector and
the quaternions state. This ability of being 'absolute' makes it
naturally very useful. I was already starting to hate quaternions, but
these capabilities made me appreciate them anew. It is that I just do
not manage to comprehend them.

Thank you for the tips, very helpful.
Heinz

_______________________________________________
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
Date: 06.03.05 22:19 (Sun, 6 Mar 2005 15:19:05 -0600)
From: Joseph J. Strout
At 5:45 PM -0500 3/5/05, Heinz J.Gattringer wrote:

>But I did not know that this:
>> myObj3D.Orientation.SetRotationAboutAxis( 0, 1, 0, mRotation )
>also works so good. In particular, I did not know you could hand the
>thing an absolute heading, I thought it was a relative thing. That
>of course makes that method much more powerful and useful. Tried it
>in my game and works with no hitch, but my solution is I think some
>2% faster in terms of fps I get (although this could be just an
>illusion). Good to know though.

It's better not because of any difference in speed (which I would
expect to be minimal), but because it avoids error accumulation. For
that reason alone, I highly recommend you switch to this technique.

>I want the computer opponent to be able to "imagine" a picture of
>the current position of the objects in the game, make some
>assumptions as to where they could be a bit in the future and then
>act sort of smartly upon those assumptions. For this I believe a
>heading-vector (combined with speed) might be more practical than
>just a heading.

Well, you can always get a 2D direction out of a heading by just
using Sin and Cos. But it might be almost as fast, and perhaps
easier, to use Quaternion.Transform.

>Again, I thought this Transform method was a relative thing,
>depending on the "separation", if I may call it so, from the handed
>vector and the quaternions state.

And so it is, but of course if you hand it a vector that's pointing
"straight ahead" (whatever you define that to mean), then it will
rotate it to point in the direction of the vector.

Check out the Rb3D FAQ if you haven't already -- I believe it
discusses how a quaternion can be considered either an absolute
orientation, or a relative rotation. Just as a vector can be
considered an absolute position, or a relative change in position.

> This ability of being 'absolute' makes it naturally very useful. I
>was already starting to hate quaternions, but these capabilities
>made me appreciate them anew.

Yes, they're really quite elegant and powerful.

> It is that I just do not manage to comprehend them.

Hang in there, you will!

Best,
- Joe