D3DXIntersect parameters

Started by
1 comment, last by Calin 18 years, 7 months ago
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]

My project`s facebook page is “DreamLand Page”

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!

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.

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement