Jump to content
  • Advertisement
Sign in to follow this  
Calin

D3DXIntersect parameters

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone! I am trying to add a picking function to my game. The problem is that I am a little confused on D3DXIntersect. I went to MSDN already and I understand what the first 4 parameters stand for. I am not sure however about the rest of them. Can someone point a place where I can see D3DXIntersect put to practical use? [Edited by - Calin on September 14, 2005 12:38:47 PM]

Share this post


Link to post
Share on other sites
Advertisement
You said you looked at the MSDN site so I assume you mean this one

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/d3dx/functions/mesh/d3dxintersect.asp

in which case, it seems fairly simple. There are only three inputs, the mesh you want to check it with, the starting point of the ray, and the direction vector of the ray. All the other values are output and most of them you will find are entirely unnecessary for what you want. In fact, the ONLY one that you want to use if you're merely using this for picking is the pHit BOOL. This will simply tell you if the ray interescts your mesh. If it does, then you've picked it, if not... then you haven't. pDist can also be a helpful function for other D3DXIntersect uses, but you don't need it for this. So to use this function, just create a bunch of values following the following structure

BOOL Hit,
DWORD FaceIndex,
FLOAT U,
FLOAT V,
FLOAT Dist,
LPD3DXBUFFER pAllHits,
DWORD CountOfHits

The exact names don't make a difference. I'm using local variables here rather than pointers, since you don't need to keep the values anyway it's simpler to create the objects directly rather than pointers and then they'll be deleted when the function completes. However, make sure when you refer to these variables when you call D3DXIntersect you use &Hit, &FaceIndex, etc.

Finally, a word of caution. Don't use this as your first line of checking or you will kill CPU power. If you're picking you need to check all the objects on screen that can be picked. These will all be meshes and you don't want to call a D3DXIntersect on each of those meshes every time you try and pick. Use box/sphere/cylinder detection FIRST, and if that returns true, THEN use D3DXIntersect.

Good luck!

Share this post


Link to post
Share on other sites

Thanks rjackets !
Your post is really helpful. I will try to see if it works.

BTW: I knew I must use bounding box collisions first, it`s just that I want to take one thing at a time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!