msaucedo's picture

LookAt inverse

is there a riddle here?

Vector3 Eye = new Vector3(0.0f, 2.0f, -10.0f);

mCameraTarget = Vector3.Zero;
mCameraTransform = Matrix4.LookAt(Eye, mCameraTarget, Vector3.UnitY);

// so mCameraTransform should be at Eye right?
// but looking in the debugger, the original values of eye are nowhere to be found. (?)
// so vector3.zero transformed by this matrix should yield original eye position, right?

OpenTK.Math.Vector3 zero = OpenTK.Math.Vector3.Zero;
OpenTK.Math.Vector3 testEye;
OpenTK.Math.Vector3.TransformPosition(ref zero, ref mCameraTransform, out testEye);

// shouldn't testEye equal (0.0f, 2.0f, -10.0f)? I say yes, but the actual data is something like (0.0f, 0.0f, -10.19804f)?!?!?!

So further hair pulling shows that if I inverse the transform after calling LookAt, then all behaves as I expect.
My question is: why does LookAt() seemingly return me an inversed matrix? which then I must invert again in order to do anything meaningful with?

I was hoping not to have pull out my C# matrix, vector (and other), libraries, assuming OpenTK already has all of these math libraries. Another question then: How under OpentTK math libraries is one supposed to a) create a regular transform matrix, and b) do all kinds of regular stuff one is accustomed to doing with said matrix, like transforming points to it, inverse transforming points to it, etc.?

Or am I to believe that the LookAt() function is strictly for making a view matrix ONLY used to be sent straight to gl model view? Then shouldn't it be named something different, such as, LookAtViewMatrix()?