Author Topic: Help - world to camera space  (Read 2848 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Help - world to camera space
« on: August 20, 2012, 01:01:07 pm »
Please, how can I get vector from world space in camera space?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Help - world to camera space
« Reply #2 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Help - world to camera space
« Reply #3 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().

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Help - world to camera space
« Reply #4 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;

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Help - world to camera space
« Reply #5 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.