View Full Version : Local Axis of an object with a rotationMatrix

ColacX

12-29-2009, 09:08 PM

Hi there if i have an object that has a rotationMatrix

r00 r04 r08 .0

r01 r05 r09 .0

r02 r06 r10 .0

.0...0...0...1

and global x y z coordinates

and i want to find out the local-x-axis and use it to translate the local motion into global positions

how would the code be? if i want increment the localxmovement by 1.0f

tried something like this

x += r00 + r04*r08;

y += r01 + r05*r09;

z += r02 + r06*r10;

and in which way do i have normalize the rotationMatrix and the globalpositionincrements if i do so?

this way? 1 0 0

or this way?

1

0

0

Having some trouble with skewed picture and incorrect local-motions

ColacX

12-30-2009, 06:31 AM

What does the rotationMatrix really represent?

Dark Photon

12-30-2009, 09:44 AM

What does the rotationMatrix really represent?

A linear combination of X, Y, and Z, for each of X, Y, and Z.

You need to crack open a good intro to 3D graphics book and read up on matrices. I don't understand several of your questions.

Also, to one of your previous questions expressing puzzlement as to whether to use row or column vectors:

1 0 0

vs.

1

0

0

You can use either, but because you're trying using OpenGL (which is column-major operator-on-the-left -- i.e. M*v1=v2), and you're probably trying to use it from C/C++ (which is row-major), then you want to use the row-major operator-on-the-right convention in your code (v1*M=v2). This implies row vectors.

However, given some random matrix of values like the above, the provider needs to tell you which conventions is being followed. It could be either, and if you presume incorrectly, you'll just get garbage.

Now given your rotation matrix:

r00 r04 r08 .0

r01 r05 r09 .0

r02 r06 r10 .0

.0...0...0...1

If we presume operator-on-the-right convention (v1*M=v2), then you can see that the local X axis v1=(1,0,0,0) maps to v2=(r00,r04,r08,0) in the destination space. This may answer one of your other questions.

A solution which might be easier than messing around with the orientation matrix is to order your GL calls as follows -

glLoadIdentity ();

glMultmatrix (R);

glTranslate (xo, 0.0, 0.0);

Draw_Object ();

Where R is your orientation matrix and xo is the distance

you want to move the object along it's X axis. Is there a

reason you can't take this approach?

ColacX

12-31-2009, 01:22 AM

A solution which might be easier than messing around with the orientation matrix is to order your GL calls as follows -

glLoadIdentity ();

glMultmatrix (R);

glTranslate (xo, 0.0, 0.0);

Draw_Object ();

Where R is your orientation matrix and xo is the distance

you want to move the object along it's X axis. Is there a

reason you can't take this approach?

Thats almost how i have the code.

Every object draw method does this

glLoadIdentity();

glTranslate(globalX, globalY, globalZ);

glMultmatrix(rotationMatrix);

//drawObject code

the camera is calculated by doing the same but in inverse.

so i've seperated the global coordinates and the rotation out of convenience.

hope that clarifys a bit, my problem is that when the object is doing a local motion it must account its rotation, so that if viewed from the object it will look like its moving 1 step in x-axis, but when viewed by others it will look like its moved in the direction it was rotated to.

If we presume operator-on-the-right convention (v1*M=v2), then you can see that the local X axis v1=(1,0,0,0) maps to v2=(r00,r04,r08,0) in the destination space. This may answer one of your other questions.

no that looks more like multiplication of a vector with a matrix, it doesnt make sense im my case.

my problem is to translate localmotion into globalX, globalY, and globalZ.

everyobject has a globalX,globalY and globalZ

i've almost made it work with, but it's slightly wrong when the object is rotated at certain angles.

globalX += r00 + r04*r08; //i just guessed this code by

globalY += r01 + r05*r09; //trying to reason what the

globalZ += r02 + r06*r10; //rotationMatrix really means.

reasoning for my guessing is that let's say the object is not rotated at the moment then it would have a rotationMatrix with the values:

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

and if we moved 1 step in x-axis

globalX += 1 + 0*0 = 1

globalY += 0 + 1*0 = 0

globalZ += 0 + 0*1 = 0

the result is that the globalX changed +1 and the other didnt change at all, which is the wanted result that fits for this rotationMatrix but not some of the others :(

i want to create a 3D world where every object and the camera to have its own globalPosition and localRotation, and i want every object and the camera to be able to move according to their localRotation. Just like in reality.

How do you guys do it?

oh i just tried using just

globalX += r00;

globalY += r01;

globalZ += r02;

this works perfectly with any kind of rotation for the camera but doesn't work for the objects when they've been rotated over 2 axises or more. very odd that it works perfectly for the camera but not the objects. for the objects its completly wrong

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.