#### Archived

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

# Matrix math for mirroring an object

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

## 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 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 scalem.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 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...

1. 1
Rutin
48
2. 2
3. 3
4. 4
5. 5

• 11
• 16
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009851
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!