Archived

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

Matrix math for mirroring an object

This topic is 5146 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 have an object in my program. I want to create a duplicate of it mirrored about the xz plane. I will want to do rotations, translations, and scaling on it also. Here is what I currently have (it doesn't work though!) Note: I have a matrix class which has the functions translate, rotatebyeuler, and scale. Mirror is the boolean which tells me if I draw the object mirrored about the xz plane.
Matrix m;
m.Translate(origin.x, origin.y, origin.z);
m.Rotate(euler.x, euler.y, euler.z);
m.Scale(scale.x, scale.y, scale.z);
if (mirrored)
  m.Scale(1, -1, 1);
 
This doesn't work! When I modify the origin values, both move in the same direction! Any ideas? Thanks, Merowe [edited by - merowe on November 13, 2003 3:48:17 PM]

Share this post


Link to post
Share on other sites
Ok, I just changed it to the following and it works:


Matrix m;
if (mirrored)
m.Scale(1, -1, 1);
m.Translate(origin.x, origin.y, origin.z);
m.Rotate(euler.x, euler.y, euler.z);
m.Scale(scale.x, scale.y, scale.z);


I don't know why, could someone please explain it?

I do have another question. I calculate the normals before-hand using something similiar to the above:


Matrix m;
// I exclude the mirror scale
m.Translate(origin.x, origin.y, origin.z);
m.Rotate(euler.x, euler.y, euler.z);
m.Scale(scale.x, scale.y, scale.z);
m.ClearTranslateValuesInMatrix();
// Multiply all normals by m here

Then, when I show the normals, some of them are messed up. Anyone know why?

The mirrored version is drawn using glFrontFace(GL_CW). I believe the normals should not be negated, which is why I don't do the Scale by 1, -1, 1. It looks pretty close, but the normals are still somewhat off!

Thanks again,

Merowe

[edited by - merowe on November 13, 2003 3:47:55 PM]

Share this post


Link to post
Share on other sites
The answer to your first question has to do with the order of transformations. In one, you are mirroring in object space, and in the other you are mirroring in world space.

Your normals should go through the same transformations that everything else does. Try mirroring them by x as well...

Share this post


Link to post
Share on other sites