Advertisement Jump to content
Sign in to follow this  

D3DXIntersect parameters

This topic is 4874 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
You said you looked at the MSDN site so I assume you mean this one

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

DWORD FaceIndex,
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!