Interact2D not using camera transform

Started by Musurca, April 26, 2004, 11:37:09 PM

Previous topic - Next topic

Musurca

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

EgonOlsen

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.

Musurca