Help - world to camera space

Started by Thomas., August 20, 2012, 01:01:07 PM

Previous topic - Next topic

Thomas.

Please, how can I get vector from world space in camera space?


Thomas.

I somehow missed this method ;) But I need transform normalized vector, this method works with SimpleVector like with a point in world space, not like a vector.

EgonOlsen

If it's about the direction only, just multiply the vector in question with the matrix returned by Camera.getBack().

Thomas.

Thanks ;) I have two working versions.

This version seems be faster
SimpleVector vec = new SimpleVector(dir);
Matrix back = cam.getBack();
back = back.invert();
vec.matMul(back);


and this also working
SimpleVector xA = cam.getXAxis();
SimpleVector yA = cam.getYAxis();
SimpleVector zA = cam.getZAxis();
SimpleVector vec = new SimpleVector();
vec.x = dir.x * xA.x + dir.y * xA.y + dir.z * xA.z;
vec.y = dir.x * yA.x + dir.y * yA.y + dir.z * yA.z;
vec.z = dir.x * zA.x + dir.y * zA.y + dir.z * zA.z;

EgonOlsen

The first version is actually wrong. You are doing a transformation from camera space to world space that way. Leave out the invert()-call.