Archived

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

dx intersect

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

Recommended Posts

hi got this simple problem, i need to know where a ray hits a mesh (and it''s not a ray from screen, it is a 3d ray on the 3d world) I use dx.intersect and gets the value true/false and also some hit info which tells me the distance and stuff. My problem is: I need the x,y,z of that intersection point on the mesh. I checked the dx9 pick examples but they get triangles not a x,y,z point. how do i get the x,y,z from mesh.intersect? I searched the forum and found the same question 40 times but nobody really answered only pointing to the pick example (which again, doesn''t do it... it only gets the hitted triangle) any ideas?

Share on other sites
I hope I understand your question. Look into using the D3DXIntersect function. Among the parameters returned by this function are the distance to the hit point and the barycentric coordinates of the intersection point. Barycentric coordinates bascially tell you how much "weight" each vertex of a triangle has in determining the location of a point on the triangle's surface. Your code would look something like this:

D3DXIntersect(mesh, &rayOrigin, &rayDir, &hit, &index, &u, &v, &distance, &hitBuffer, &numHits);

Now, you use the "index" variable to access the particular triangle of your mesh that was hit. Even though it's inefficient, let's say you copy the triangles' vertices to v0, v1, and v2. I'm just copying to make notation easier to understand. To generate the actual intersection point, you would do this:

if( hit == TRUE )
{
hitPoint = v0 + u(v1-v0) + v(v2-v0);
}

Another way to do it is to note that any point can be defined by starting at an origin, and moving a certain distance along a particular direction. The D3DXIntersect function allows you to do this as well because it returns the actual distance to the point of intersection. So another way to compute the hit point is as follows (assuming "rayDir" has been normalized).

if( hit == TRUE )
{
hitPoint = rayOrigin + distance*rayDir;
}

Either one of these techniques should work. I would use the second one simply because it's easier to understand and also less computationally expensive.

Hope this helps,
neneboricua19

[edited by - neneboricua19 on June 17, 2003 9:09:23 PM]

[edited by - neneboricua19 on June 17, 2003 9:10:27 PM]

1. 1
2. 2
Rutin
20
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633739
• Total Posts
3013619
×