Author Topic: Interact2D not using camera transform  (Read 4107 times)

Offline Musurca

  • byte
  • *
  • Posts: 9
    • View Profile
Interact2D not using camera transform
« on: April 26, 2004, 11:37:09 pm »
I've been implementing picking in my jPCT application, and I've come across the following problem: a ray created with reproject2D3D(...) from X and Y screen coordinates chosen by the mouse does not take into account the camera's transform. I have to manually multiply the ray by the camera's front matrix like so:

Camera cam;
FrameBuffer buffer;

.
.
.

SimpleVector rayTemp = Interact2D.reproject2D3D(cam, buffer, mX, mY);
rayTemp.normalize();
Matrix orient = cam.getFront();
float[] dump = orient.getDump();
SimpleVector ray = new SimpleVector();
ray.x = dump[0]*rayTemp.x + dump[1]*rayTemp.y + dump[2]*rayTemp.z + dump[3]*1;
ray.y = dump[4]*rayTemp.x + dump[5]*rayTemp.y + dump[6]*rayTemp.z + dump[7]*1;
ray.z = dump[8]*rayTemp.x + dump[9]*rayTemp.y + dump[10]*rayTemp.z + dump[11]*1;


If I don't do this, the ray has entirely the wrong orientation. Is this intentional behavior, or am I just doing something wrong?

Thanks,

-Nick

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Interact2D not using camera transform
« Reply #1 on: April 27, 2004, 12:03:10 am »
Well, the picking takes place in camera space, i.e. the space where the camera is always located at (0,0,0) and looking down the z-axis. That's the space the visibility list is in and that's also the space the ray is in. That's why it doesn't reflect the camera's transformation and for picking from the visibility list, it doesn't have to. IF you want to use this ray for anything else then picking with the provided methods, then you have to do the transformation "by hand" (which reminds me to add a method to ease this case...instead of working with the dump).
Hope this helps.

Offline Musurca

  • byte
  • *
  • Posts: 9
    • View Profile
Interact2D not using camera transform
« Reply #2 on: April 27, 2004, 01:06:38 am »
Ah, okay, that makes sense. Thanks.