Simple Picking tutorial request

Jan 27, 2010 at 4:54 PM

Hi StatusUnknown,

I've been trying to play with 3d picking recently and got one issue that I couldn't get solved...

It would be great if you (or someone from the community) could come up with a small sample on how to do so using Camera3D.ProjectToCoordinates.

Thanks

Philippe

 

Coordinator
Jan 28, 2010 at 3:07 PM

What specifically are you having trouble with? Is something not working right with ProjectToCoordinates?

Jan 31, 2010 at 4:58 PM

Hi Philippe,

Just tell us what's your exact problem and we will be able to help you ;)

To get a ray from your mouse position you need to be in a draw method :

public void Draw(DrawState state)
        {
            Vector3 worldPosition;
            state.ProjectFromScreen(ref m_mousePosition, 1, out worldPosition);
            m_rayFromMouse = worldPosition - Camera.Position;
            m_rayFromMouse.Normalize();
        }

 

 

Coordinator
Feb 1, 2010 at 1:12 AM
Edited Feb 1, 2010 at 1:14 AM

The same function is also available through the Camera class (ProjectFromTarget).
Although, for a few reasons it's actually very expensive to call ProjectFromTarget directly on the Camera instead of the DrawState (requires a couple of matrix inversions, for instance).

ProjectFromScreen should have been called ProjectFromTarget all along, but I didn't want to break it. Probably more confusing now. :-/ hmm

Also note, the opposite function, ProjectFromScreen (when called from the draw state) will return a local position, not a world position. (So the world matrix is taken into account).