Skip to main content
gamedev.net
🔒 Locked

Matrix help needed,

Started by DMonaghan Nov 26, 2003 at 9:45 AM 4 replies 550+ views
Original Post
DMonaghan
DMonaghan
I am working with the Cipher Graphics engine, and Tokamak physics engine. My Cipher game code is using a coord system where Z is the up/down axis The Tokamak coord system is setup so Y is the up/down axis So I need to convert the axis info I''m getting from tokamak to be compatabile with the coords of my game code. During each frame I get the position and rotate info from tokamak in the following format. neT3 t t.rot[0][0]; // X rotation t.rot[0][1]; t.rot[0][2]; t.rot[1][0]; // Y rotation t.rot[1][1]; t.rot[1][2]; t.rot[2][0]; // Z rotation t.rot[2][1]; t.rot[2][2]; t.pos[0]; // XYZ Position t.pos[1]; t.pos[2]; I''ve heard tell, that in order to convert my data from a Y up system to a Z up system, I simply need to rotate about the X access 90 degrees. I have a math lib function which works pretty much the same as glRotate(). This function is called mat4_Rotate and is defined as /* ========================== mat4_Rotate Adds in a rotation of angle degrees about the vector x, y, z to the matrix, similar to glRotate ========================== */ void mat4_Rotate(float angle, float x, float y, float z, mat4_t m) Now for the question, How the hell do i use this fuctino to do it. I''ve assume that I simply fill in the (mat4_t m) matrix with the data i get from tokamak. Like so. m[0] = t.rot[0][0]; m[1] = t.rot[0][1]; m[2] = t.rot[0][2]; m[3] = 0; m[4] = t.rot[1][0]; m[5] = t.rot[1][1]; m[6] = t.rot[1][2]; m[7] = 0; m[8] = t.rot[2][0]; m[9] = t.rot[2][1]; m[10] = t.rot[2][2]; And then rotate ...... mat4_Rotate(90, 1, 0, 0, m); I then simply update my game code with the updated matrix (m) ......... ....... Obviously since i writing this, its not really working out for me.... Is there some obvious that i am doing wrong?
jamessharpe
jamessharpe
Your code isn''t actually changing the matrix. You need to pass the matrix by reference so that the matrix gets changed. At the moment a copy of your matrix is being made, and then this is modified in the procedure and then just discarded, leaving you with the original matrix in m.

Just change your function definition to:
void mat4_Rotate(float angle, float x, float y, float z, mat4_t &m)

and the code should work without any other changes.

James
DMonaghan
DMonaghan
I just checked that, the matrix does actually get updated in subsqeunt calls within the rotate function.

So I''m back to sqaure 1,.....
DMonaghan
DMonaghan
Also just to added, I think it has something to do with the axis its rotated against, as the object seem to swing along a wide arc, just before the come to a rest.... do i need to translate the position info to the origin?... if so.. how does this affect the rotate func, since the pos info is not sent here?


Before rotate
[0] 0.99542832 float
[1] -0.087401859 float
[2] -0.038514689 float
[3] 0.00000000 float
[4] 0.085420631 float
[5] 0.99506980 float
[6] -0.050392073 float
[7] 0.00000000 float
[8] 0.042729162 float
[9] 0.046871748 float
[10] 0.99798661 float
[11] 0.00000000 float
[12] 18.365654 float
[13] 18.684746 float
[14] 5.0454059 float
[15] 0.00000000 float

After Rotate
[0] 0.99542832 float
[1] -0.087401859 float
[2] -0.038514689 float
[3] 0.00000000 float
[4] 0.042729158 float
[5] 0.046871703 float
[6] 0.99798661 float
[7] 0.00000000 float
[8] -0.085420631 float
[9] -0.99506980 float
[10] 0.050392028 float
[11] 0.00000000 float
[12] 18.365654 float
[13] 18.684746 float
[14] 5.0454059 float
[15] 0.00000000 float


[edited by - DMonaghan on November 26, 2003 11:22:25 AM]
jamessharpe
jamessharpe
There is always another way that should work. Think of the matrix as describing the basis of your coordinate system. Then each of the columns/rows(depends how you represent your matrix) represents one of the axes. Look up how you construct a lookat matrix. Simply all you need to do is swap the two columns/rows in the 2nd and 3rd position.

James

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.