www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on August 20, 2012, 01:01:07 pm

Title: Help - world to camera space
Post by: Thomas. on August 20, 2012, 01:01:07 pm
Please, how can I get vector from world space in camera space?
Title: Re: Help - world to camera space
Post by: EgonOlsen on August 20, 2012, 04:07:17 pm
By using this method: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Camera.html#transform(com.threed.jpct.SimpleVector) (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Camera.html#transform(com.threed.jpct.SimpleVector))
Title: Re: Help - world to camera space
Post by: Thomas. on August 20, 2012, 04:56:55 pm
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.
Title: Re: Help - world to camera space
Post by: EgonOlsen on August 20, 2012, 09:09:57 pm
If it's about the direction only, just multiply the vector in question with the matrix returned by Camera.getBack().
Title: Re: Help - world to camera space
Post by: Thomas. on August 20, 2012, 09:31:22 pm
Thanks ;) I have two working versions.

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

and this also working
Code: [Select]
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;
Title: Re: Help - world to camera space
Post by: EgonOlsen on August 20, 2012, 10:07:02 pm
The first version is actually wrong. You are doing a transformation from camera space to world space that way. Leave out the invert()-call.