Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Invert One Axis in Rotation Matrix


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 inanimate   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 August 2009 - 12:52 PM

Hey. I've searched around and asked some friends, but so far nobody knows the answer... I'm using a 3D gyroscope as input to game, and I want to simply rotate the scene identical to how a user rotates the gyroscope. This seemed easy, especially because one of the gyroscope's outputs is a rotation matrix (seemingly for use with OpenGL, which I'm using). However the issue has always been that the coordinate systems don't line up. I've messed with it enough and finally gotten it down to two correct axes--y and z. (As in, you tilt up, the object tilts up, you roll clockwise, the object rolls clockwise, et cetera.) The final frontier is the x axis, which is inverted. So you pan up, the object pans down. How can I invert/multiply by -1 that axis in the rotation matrix? OpenGL is column-major and the device is seemingly row-major, although I don't think it actually says, so I've already fixed that problem. I'm still not that good with rotation matrices, so getting two axes working was honestly just swapping values until I got it to work. But is there an easy way to fix that one axis? Or perhaps change the scene instead so it looks to be working? I've rotated the camera in certain ways so a different axis is messed up, but I've never had all three correct. Thanks.

Sponsor:

#2 Aken H Bosch   Members   -  Reputation: 197

Like
0Likes
Like

Posted 01 August 2009 - 04:26 PM

So, you want to multiply a row of this matrix by -1? Can you explain, please, why you can't just multiply the values in the row by -1? It seems like maybe there's something I'm not getting about this problem... it seems like a very simple case of "just put a minus sign in"...

#3 inanimate   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 August 2009 - 04:54 PM

Well, I though it was that simple, but it didn't end up seeming so.

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 BeanDog   Members   -  Reputation: 1063

Like
0Likes
Like

Posted 01 August 2009 - 05:57 PM

What Aken is trying to say may not make sense to you if you don't understand one common way to interpret the values in your matrix. 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]).

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?

~BenDilts( void );

Lucidchart: Online Flow Chart Software; Lucidpress: Digital Publishing Software


#5 inanimate   Members   -  Reputation: 100

Like
0Likes
Like

Posted 01 August 2009 - 10:18 PM

Oh, wow, OK. I didn't know you could think about it (and use it) like that.

Thanks a lot. I haven't tried it yet, but I'll try that out tomorrow morning and see what happens.

#6 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 02 August 2009 - 03:39 AM

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

#7 inanimate   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 August 2009 - 06:10 AM

Interesting. I'm using OpenGL, so just to see if I have this correct...

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 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 02 August 2009 - 06:20 AM

Quote:
X: m[0], m[1], m[2]
Y: m[3], m[4], m[5]
Z: m[6], m[7], m[8]
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.

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 inanimate   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 August 2009 - 09:01 AM

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.

#10 Pertur   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 March 2011 - 01:11 AM

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.

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?
Thanks!

#11 haegarr   Crossbones+   -  Reputation: 4421

Like
1Likes
Like

Posted 30 March 2011 - 02:15 AM

I'm not sure but I have the impression that another conceptual misunderstanding is underway here. It seems me that space mirroring and rotation inversion are confused.

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.

#12 Pertur   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 March 2011 - 04:16 AM

Ok, I guess I can't do directly from the matrix ... I will try to get euler angles and create a new matrix ...

#13 Buckeye   Crossbones+   -  Reputation: 5613

Like
0Likes
Like

Posted 30 March 2011 - 05:15 AM

It appears the gyroscope is providing you with a left-hand system and you're using OGL as a right-hand system.

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.


#14 RobTheBloke   Crossbones+   -  Reputation: 2349

Like
0Likes
Like

Posted 01 April 2011 - 09:52 AM

Ok, I guess I can't do directly from the matrix ... I will try to get euler angles and create a new matrix ...


^^ What buckeye said ^^ ..... for that is the correct way ;)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS