Sign in to follow this  
riruilo

About transformations in a scene graph

Recommended Posts

riruilo    218
Hi all! Let's say I have a scene graph and its nodes. This nodes have several transformations. What should I do? Store a list with different transformations like scale, rotations and translate, or should I store only and only one matrix per node? If I store a matrix per node, can I easily set and get translation, scale and rotation? Thanks a lot.

Share this post


Link to post
Share on other sites
lightbringer    1070
I usually keep a vector for position and a quaternion for rotation, one each for each node, because I do all my rotations using quaternions. But I also cache the transformation matrix (once per node) and update it every time the position or rotation changes. It's been a while since I looked at this code. You can easily get the translation from the matrix, but I think getting the rotation is quite a bit more complicated if possible at all.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
You can easily get the translation from the matrix, but I think getting the rotation is quite a bit more complicated if possible at all.
In most cases, you can get the rotation back without too much trouble. However, if you're going to need frequent access to the rotation component of the transform, it'll certainly be more convenient (and less expensive) to store it separately.

Share this post


Link to post
Share on other sites
riruilo    218
Quote:
Original post by jyk
Quote:
You can easily get the translation from the matrix, but I think getting the rotation is quite a bit more complicated if possible at all.
In most cases, you can get the rotation back without too much trouble. However, if you're going to need frequent access to the rotation component of the transform, it'll certainly be more convenient (and less expensive) to store it separately.


So, Is it better to store a position and 3 rotations and a scale rather than a matrix? Note that when creting my game, I will access to the position of a node (the main character) very often.

Thanks for replies.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
So, Is it better to store a position and 3 rotations and a scale rather than a matrix?
Before answering that question, let me ask: why do you think you need three rotations?

Share this post


Link to post
Share on other sites
riruilo    218
Quote:
Original post by jyk
Quote:
So, Is it better to store a position and 3 rotations and a scale rather than a matrix?
Before answering that question, let me ask: why do you think you need three rotations?


Not sure, maybe one per axis.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Not sure, maybe one per axis.
An orientation can be uniquely described by a single axis, and a single angle. You don't need any more than that.

There are however a variety of different ways to store and manipulate orientations and rotations in axis-angle form. As it happens, what might perhaps be the most obvious choice - an axis-angle pair - is somewhat difficult to work with, and is rarely used in practice. Common alternatives are a 3x3 matrix, or a unit-length quaternion.

I imagine what you have in mind is an Euler-angle triple (e.g. yaw, pitch, and roll). If you're going to use Euler angles to represent object orientations in your scene graph, just make sure you can articulate why they would be a better choice (in the given context) than a matrix or quaternion.

Share this post


Link to post
Share on other sites
riruilo    218
Thanks.

If I use a quaterion ( I have no idea about quaternions ) how should I store my transformation matrix? I mean, do I need 2 transformation matrix?

Sorry but I don't understand it very well.

Thanks a lot.

Share this post


Link to post
Share on other sites
lightbringer    1070
Nothing changes in that respect. To get the world transform matrix for any given node, you first get a copy of the parent's world transform, then you translate it by your position vector, then you multiply it by the orientation quaternion (a quaternion is easily changed into a matrix, which you then multiply by).

The good news is, you don't need to understand quaternions thoroughly to use them. Just grab one from whatever vector math library you are using.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this