**0**

# Invert One Axis in Rotation Matrix

###
#1
Members - Reputation: **100**

Posted 01 August 2009 - 12:52 PM

###
#2
Members - Reputation: **324**

Posted 01 August 2009 - 04:26 PM

###
#3
Members - Reputation: **100**

Posted 01 August 2009 - 04:54 PM

According to this website:

http://pages.cs.wisc.edu/~psilord/docs/local_axis.html

A rotation around the X is represented by five different values in a transformation matrix. These five values aren't unique to the X rotation, it seems, so I can't modify them without impacting the other axes.

It's highly possible that I'm not quite understanding this right though.

EDIT: And just to clarify, I have one matrix that has all three rotations inside it.

###
#4
Members - Reputation: **1064**

Posted 01 August 2009 - 05:57 PM

You can consider the first three rows of your matrix to be the relative X, Y, and Z axes of an object transformed by your matrix. The fourth row is the position of the center of that object. (In all cases, the fourth column is probably [0,0,0,1]).

In other words, to reverse your object's X-axis, all you would need to do is multiply the first row of your matrix by -1. Or if you wanted to move your object 1 unit along its own Z-axis (one definition of "move forward"), you could just increment the fourth row of your matrix by the values in the third row of your matrix. Or if you wanted to rotate the object around its own Y-axis (one definition of "Turn left or right"), you would just rotate around the axis defined by the point [fourth row] and the direction [second row].

Does that help?

###
#6
Members - Reputation: **2078**

Posted 02 August 2009 - 03:39 AM

Quote:Just to try and prevent any confusion on the OP's part, I'll go ahead and point out that this isn't actually what the term 'row major' means. 'Row major' refers to how the matrix is stored in memory; whether the basis vectors of the transform are stored in the rows or columns of the matrix is a separate issue.

In this example, I'm going to be row-major, you may have to transpose for your application.

You can consider the first three rows of your matrix to be the relative X, Y, and Z axes of an object transformed by your matrix. The fourth row is the position of the center of that object. (In all cases, the fourth column is probably [0,0,0,1]).

###
#7
Members - Reputation: **100**

Posted 02 August 2009 - 06:10 AM

According to:

http://www.gamedev.net/community/forums/topic.asp?topic_id=533653&whichpage=1#3449786

He says that "Base vectors in OpenGL are column", and so he stores the rows of the transformation matrix in column-major format. So does that mean that a "column base vector" represented in a column-major memory layout would just be:

X: m[0], m[1], m[2]

Y: m[3], m[4], m[5]

Z: m[6], m[7], m[8]

?

Or is it backwards? (m[0], m[3], m[6], ...)

Thanks.

###
#8
Members - Reputation: **2078**

Posted 02 August 2009 - 06:20 AM

Quote:For both a row-major 3x3 matrix with row vectors or a column-major 3x3 matrix with column vectors, the elements of the basis vectors would map to the elements of a 1-d array just as you've shown above.

X: m[0], m[1], m[2]

Y: m[3], m[4], m[5]

Z: m[6], m[7], m[8]

For a column-major matrix with row vectors or a row-major matrix with column vectors, it would be the other way around (i.e. m[0], m[3], m[6], etc.).

###
#9
Members - Reputation: **100**

Posted 02 August 2009 - 09:01 AM

Let's say I want to flip the rotation about the Z axis. So I multiply indices 8, 9, and 10 (4x4 matrix) by -1. However, instead of the rotation being flipped (so moving the gyro to the right makes it go to the right), the geometry is flipped. So now a line drawn from 0 to 10 in the Z now looks like it is going from 0 to -10?

I'll try to keep this in the math/physics category, but perhaps I have a bigger OpenGL problem in addition to the matrix stuff...

Thanks.

###
#10
Members - Reputation: **100**

Posted 30 March 2011 - 01:11 AM

I have the same problem. Is there any way to invert one axis directly from the rotation matrix? I can't find anything that can help me. Any other method to do it?I've confirmed that it's column-major with column vectors, however for some reason I can't get it to work.

Let's say I want to flip the rotation about the Z axis. So I multiply indices 8, 9, and 10 (4x4 matrix) by -1. However, instead of the rotation being flipped (so moving the gyro to the right makes it go to the right), the geometry is flipped. So now a line drawn from 0 to 10 in the Z now looks like it is going from 0 to -10?

I'll try to keep this in the math/physics category, but perhaps I have a bigger OpenGL problem in addition to the matrix stuff...

Thanks.

Thanks!

###
#11
Crossbones+ - Reputation: **7132**

Posted 30 March 2011 - 02:15 AM

Multiplying a column / row of the basis matrix means a mirroring in 1 dimension of the space. It is the same as applying a scale matrix where one of the factors is -1.

When looking at a rotation matrix, you'll notice that there are cosine and sine terms inside. E.g.

[ c s 0 ] [ -s c 0 ] [ 0 0 1 ](where c means cos(angle) and s means sin(angle)) is a simple, z-axis rotation matrix.

Now, inverting the rotation can be achieved by negating the angle. But look at the terms then, considering that

cos(angle) == cos(-angle)

sin(angle) == -sin(-angle)

Hence you cannot yield in an inverse rotation by negating one of the columns / rows!

Is this the problem you've encountered?

BTW: The term "axis" may mean a column / row of the basis (orientation matrix) and hence a dimension in a space, or else a pivot for a rotation. Both may be coincident (i.e. in Euler rotations) but are not the same.

###
#13
GDNet+ - Reputation: **10739**

Posted 30 March 2011 - 05:15 AM

Try doing the rotation in the gyroscope's system, rather than OGL. As mentioned above, you just scale the x-axis vector. However, you have to apply that scaling both

*before*and

*after*you do the rotation.

I.e., create a scale matrix for scale factors ( -1, 1, 1 ); scale the x-axis by -1.

Your_matrix = scaleMatrix * gyroMatrix * scaleMatrix

Note: this is for a rotation matrix only, before your multiply by the OGL translation.

Application of the first scaleMatrix moves into gyro space. The gyroMatrix applies the rotation. The second scaleMatrix moves back into OGL space. I believe the second scaling matrix is what you're missing.

EDIT: Good heavens! Just noticed the OP posting date. Guess this is a bit late.

**Edited by Buckeye, 30 March 2011 - 12:41 PM.**

Please don't PM me with questions. Post them in the forums for *everyone's* benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.