Skip to main content
gamedev.net
🔒 Locked

Picking

Started by PauloAlto 4 replies 300+ views
Original Post
PauloAlto
PauloAlto
The picking sample that comes with the DX SDK shows how to do ray picking for a mesh. How would this be done if not using a mesh? Also, how do I add in the world matrix so that objects can be picked that have been moved from the origin?
mdias
mdias
To detect if a ray is intersecting with a mesh
moved from the origin you just have to change the
ray position by doing the following:

ray.x += Object.x
ray.y += Object.y
ray.z += Object.z

I guess is something like that that you have to do...

I hope this help

Kamikaze
PauloAlto
PauloAlto
But object.x etc would be for a mesh would it not? How do I do what is in the sample app without using meshes?
mickey
mickey
hi, if there's a mesh and you want to include world transformation, add this,

D3DXVECTOR3 vNear,vDir;
D3DXMATRIX invMat;

D3DXMatrixInverse(&invMat, NULL, Object.GetWorldMatrix());
D3DXVec3TransformCoord(&vNear, &vPickRayOrig, &invMat);
D3DXVec3TransformNormal(&vDir, &vPickRayDir, &invMat);

then,
D3DXIntersect(Object.GetMesh(), &vNear, &vDir,
&bHit, NULL, NULL, NULL, &dist, NULL, &numOfIntersection);

if it's not a mesh.., ehm., it's a sprite then?


[edited by - mickey on November 7, 2002 6:23:02 AM]
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
PauloAlto
PauloAlto
I have a number of cubes which have been made up from triangles from points in a vertex buffer. I want to be able to work out which cube has been clicked on, obviously only taking the nearest cube to the camera.

Topic Locked

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

Sign in to reply to this topic.