Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


translating to origin

This topic is 5441 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this is not an opengl specifc question, im actually using the cipher engine,,, so in kinda them same, flame me if you will. 8) I have a set of position and rotation data of a model and I need to rotate it 90 around the x axis. I have an understanding of the concepts of what i need to do. I need to translate to the origin, perform the rotation, and translate back to my position. I have working translate and rotate functions from a math lib and they are defined as follows, they work in similar fashion to glrotate and gltranslatef void mat4_Translate(float x, float y, float z, mat4_t m) void mat4_Rotate(float angle, float x, float y, float z, mat4_t m) My main problem is im not sure the sequence and usage of these functions I copy all of my data into a matrix, 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]; I assume in then simply use the functions in the following fashion // Translate to Origin mat4_Translate(t.pos[0], t.pos[1], t.pos[2], m); // Perform rotation along X axis mat4_Rotate(90, 1, 0, 0, m); // Translate back to orginal position mat4_Translate(t.pos[0], t.pos[1], t.pos[2], m); The result i'm getting however, is that the objects seem to swing along a wide arc. Which make me think that they are not in fact being rotated about the origin. So my problem is here // Translate to Origin mat4_Translate(t.pos[0], t.pos[1], t.pos[2], m); What is the correct usage of this, in order to transle back to the origin I dont have any functions like glLoadIdenity in order to clear, In fact i dont use matriaces at all really, except of course in this instance, were i need to do a rotation, Thanks [edited by - DMonaghan on November 26, 2003 3:32:02 PM]

Share this post

Link to post
Share on other sites
mat4_Translate(t.pos[0], t.pos[1], t.pos[2], m);
mat4_Translate(t.pos[0], t.pos[1], t.pos[2], m);

Your code to translate out, and translate back, should not be the same. Translate back with the negative vector.

"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post

Link to post
Share on other sites

I've tried to do something like

mat4_Translate(t.pos[0]*-1, t.pos[1]*-1, t.pos[2]*-1, m);

but with similar results

The translation function does the following
// apply a translation
m[12] += x*m[0] + y*m[4] + z*m[8];
m[13] += x*m[1] + y*m[5] + z*m[9];
m[14] += x*m[2] + y*m[6] + z*m[10];
m[15] += x*m[3] + y*m[7] + z*m[11];
So its updating the last few items in the maxtrix, however i think this info is not actually being used. As the rotate func seems to wipe them out

mat4_t rot;
vec3_t axis;
float radians, s, c, ab, bc, ca, t;

// normalise the axis of rotation
vec3_Set(x, y, z, axis);

// get the sin and cos values
radians = angle * DEG2RAD;
s = com_sin(radians);
c = com_cos(radians);
ab = axis[0] * axis[1] * (1 - c);
bc = axis[1] * axis[2] * (1 - c);
ca = axis[2] * axis[0] * (1 - c);

// build a rotation matrix
t = axis[0] * axis[0];
rot[0] = t + c * (1-t);
rot[6] = bc + axis[0] * s;
rot[9] = bc - axis[0] * s;

t = axis[1] * axis[1];
rot[2] = ca - axis[1] * s;
rot[5] = t + c * (1-t);
rot[8] = ca + axis[1] * s;

t = axis[2] * axis[2];
rot[1] = ab + axis[2] * s;
rot[4] = ab - axis[2] * s;
rot[10] = t + c * (1-t);

// fill in the rest of the matrix as identity
rot[3] = 0;
rot[7] = 0;
rot[11] = 0;
rot[12] = 0;
rot[13] = 0;
rot[14] = 0;
rot[15] = 1;

// multiply the matrix with the new one
Mult(m, rot, m);

[edited by - DMonaghan on November 26, 2003 3:42:24 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!