hi guys,
i hope you can help me with my current problem.

what i'm trying to achieve is picking an object from a render to texture scene. 
 The current structure of my scenegraph is containing:
- a main camera 
- a RenderToTextre-camera
- a plane (rendered by the mainCam), which gets it's texture from the 
RTT-camera 
- a sub-scene (bunch of spheres) rendered by the RTT-camera.

So as the user clicks onto the plane, a corresponding ray should be sent into 
the subscene and tested for collisions. Both cameras are perspective ones.

My current approach can be described as following:
- use the mouse-coordinates of the viewer to send a first ray into the main 
scene.
- check if the ray hits the plane 
- if so, get the uv-coordinates of the plane at the ray-hitpoint 
- as the hit uv-coordinate corresponds to a pixel of the the RTT-camera's 
viewport, use this position as the origin of a second ray sent into the 
sub-scene..

The actual problem i encounter is how to calculate the direction of the second 
ray? (although i know what to do in theory)
Unproject the 2D-coordinate of the viewport-point to a line in 3D-space.
Therefore i have to calculate 2 positions of the line, one on the nearplane and 
another on the farplane. But how do i achieve this??

First i normalize the recieved uv-coords (x/y) to ranges between -1 and 1.
Then i create two Vec3 of it, one with z=0 (nearplane) one with z=1 (farplane) 
and multiply both with the inverse viewProjectionMatrix of the RTT-camera, so i 
get two world-coordinates.
Subtracting near - far, i should get a vector which gives me the direction of 
the ray.

But it seems i'm missing something, somewhere.
Could one of you guys give me a hint what i'm missing?! 
Or point me to some code-snippets where this is done?

Regards,
Manuel


-- 
GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit 
gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to