Skip to main content
gamedev.net
🔒 Locked

Mouse + BoxBoundProbe

Started by Johan_hertz May 13, 2004 at 11:09 AM 2 replies 500+ views
Original Post
Johan_hertz
Johan_hertz
Hi I would like to use the BoxBoundProbe function (in Geometry) and a mouse click to check if an object has been clicked. The thing is I don’t know how to transform the click on the screen to a starting point for the vector. /regards Johan Hertz
Johan_hertz
Johan_hertz
Okay

The problem is I''m using C#, so I''m not really used to C++ code, especially direct X code, but I will have a look at it and if I can''t figure it out I will come back here and weep.

/Johan
Johan_hertz
Johan_hertz
I have had a look at the C++ code now and would like, if possible, get this confirmed before I try to implement it.

1) Get the projection matrix
2) Create a vector using the mouse position and projection matrix
3) Invert the view matrix
4) Use the inverted view matrix to calculate where the click is in 3d space
5) Create the ray and see what it hits

Is this correct? One thing seems really odd to me, when calculating the ray in the pick sample this formula is used:

// Transform the screen space pick ray into 3D space
// v is the vector for the click and m is the inverted view matrix
vPickRayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31;
vPickRayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32;
vPickRayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33;
vPickRayOrig.x = m._41;
vPickRayOrig.y = m._42;
vPickRayOrig.z = m._43;

Should it not be the other way around? Should not the origin be calculated using the click and the direction directly calculated from the inverted view matrix?

/Johan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.