math & physics
draetsch at November 27th, 2008 12:37 — #1
Hello people from Devmaster,
just a short introduction of myself.
I am working for a 3D Software company as 3D Artist (Realtime) in germany. In my spare time I like to fiddle around with everything that is 3D, programming and computers in general. And I want to create a big MMO just by myself ...
no just kidding.
At work I have a small problem to solve programmatically and I thought here are some people who could know such a thing.
I have a camera in 3D space (Z-up). The translation values are given in the form of x,y,z and the rotation in the form of Axis (x, y and z) + angle.
I now need to mirror this camera at the YZ plane. I could do this very complicated in the software, but I have a bunch of these (50 cameras or so).
Can someone point me in the right direction how to do this?
I think I can mirror the axis by multiplying the y value with -1, but how do I get the correct angle?
Thanks to all of you for this interesting community.
reedbeta at November 27th, 2008 14:07 — #2
First, if you're mirroring across the YZ plane, you want to multiply the X value (of the translation) with -1, not the Y value.
As for the rotation, that is more complicated. One hangup is that if you mirror a camera, you would switch its local coordinates from right-handed to left-handed (or vice versa), having the effect of mirroring the image it generates as well. I'm guessing that this is actually *not* what you want, and you want the camera to retain handedness but point in a mirrored direction.
Unfortunately, there's no simple formula that I know of - you're probably going to have to convert the axis-angle representation to a rotation matrix, extract the coordinate axes (forward, right, up), then mirror forward and up (by negating their X component) and recalculate right as the cross product of forward and up. Then put it back into a matrix and convert it back to axis-angle.
If you're doing this in a 3D package's scripting language like Maxscript or MEL, it probably has functions for manipulating vectors and matrices already, so you won't have to worry too much about the mechanics.
Does that give you enough to get started with?
draetsch at December 4th, 2008 03:11 — #3
thanks for your help. I had some methods that convert the axis/angle notation to Euler and back but when I used them I got wrong numbers, what makes me think they were buggy. Problem was that I used degrees instead of radiant values. Typical beginners error I suppose.
Now it's working since it is easy to mirror the Euler representation.
Thank you very much for your help.