Archived

This topic is now archived and is closed to further replies.

PauloAlto

Picking

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Opá isto é fácil!!!

Use all the useful code that comes with the pick example (there are al least 2 releveant functions, if I remember correclty). One of the functions, the one that does intersection analysis, is important and here you just need to change the function a bit so that it uses whatever struct you want to use. Or if you feel like it you can do your one intersection analysis, Flipcode has (or had) a nice selection of intersection algos, somewhere.

And do remember to send in your tris in the correct order or your intersection will fail, is it''ll be testing for the back of the tri and not the front.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites