Note: You must be registered in order to post a reply.
|
cbx |
Posted - Jun 22 2004 : 03:17:54 AM I wrote a simple app to try out the IntersectTri method provided in the Direct3D9 API. The IntersectTri method is also availible in the D3D8 API.
http://msdn.microsoft.com/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/geometry/m/intersecttri.asp
This is the code i'm using...
Dim Hit As Direct3D.IntersectInformation Ret = Direct3D.Geometry.IntersectTri(mobjPts(0), mobjPts(1), mobjPts(2), RayPos, RayDir, Hit)
Ret is a boolean mobjPts(0), mobjPts(1), mobjPts(2) are vector3 structures RayPos, RayDir are also vector3 structures.
The X,Y for mobjPts(0), mobjPts(1), mobjPts(2) are set using the mouse buttons, and the Z value for all three points is set to 0.
The X,Y for RayPos, RayDir are set using the mouse buttons, and the Z value for RayPos is set to -0.0000000000000001 and the Z value for RayDir is set to 0.0000000000000001.
But when I run the app the ray never seems to intersect the triangle. I have also tried variations like setting the raypos z value to to -10 and the Z value for RayDir is set to 10 but it does not help.
I don't believe I am doing anything wrong! Can anyone suggest why the IntersectTri method never returns true?
Download Attachment: IntersectTri.zip 16.08 KB |
cbx |
Posted - Jun 23 2004 : 04:25:23 AM It did work for me but rarely. It only seemed to work sometimes but not all the time, like for instance there are times when the ray would clearly be intersecting the triangle but not return a hit, but adjusting the ray ever so slightly would cause hit.
Anyway I am just in the process of exploring multiple techniques related to collision detection... |
Eric Coleman |
Posted - Jun 22 2004 : 09:00:05 AM For some reason, I've never had much luck getting DirectX 9 to work properly with VB.NET, so I can't modify the code or compile, but I did run the .exe you provided and this is what I got.
I looks like it works to me. However, I did notice that your ray isn't very long. Try drawing side views of the triangle and ray as well,
e.Graphics.DrawLine(New Pen(Color.Red), mobjPts(0).X, mobjPts(0).Y, mobjPts(1).X, mobjPts(1).Y) e.Graphics.DrawLine(New Pen(Color.Red), mobjPts(1).X, mobjPts(1).Y, mobjPts(2).X, mobjPts(2).Y) e.Graphics.DrawLine(New Pen(Color.Red), mobjPts(2).X, mobjPts(2).Y, mobjPts(0).X, mobjPts(0).Y) e.Graphics.DrawLine(New Pen(Me.ForeColor), RayPos.X, RayPos.Y, RayDir.X, RayDir.Y) e.Graphics.DrawLine(New Pen(Color.Green), mobjPts(0).X, mobjPts(0).Z, mobjPts(1).X, mobjPts(1).Z) e.Graphics.DrawLine(New Pen(Color.Green), mobjPts(1).X, mobjPts(1).Z, mobjPts(2).X, mobjPts(2).Z) e.Graphics.DrawLine(New Pen(Color.Green), mobjPts(2).X, mobjPts(2).Z, mobjPts(0).X, mobjPts(0).Z) e.Graphics.DrawLine(New Pen(Me.Cyan), RayPos.X, RayPos.Z, RayDir.X, RayDir.Z) e.Graphics.DrawLine(New Pen(Color.Blue), mobjPts(0).Y, mobjPts(0).Z, mobjPts(1).Y, mobjPts(1).Z) e.Graphics.DrawLine(New Pen(Color.Blue), mobjPts(1).Y, mobjPts(1).Z, mobjPts(2).Y, mobjPts(2).Z) e.Graphics.DrawLine(New Pen(Color.Blue), mobjPts(2).Y, mobjPts(2).Z, mobjPts(0).Y, mobjPts(0).Z) e.Graphics.DrawLine(New Pen(Me.Magenta), RayPos.Y, RayPos.Z, RayDir.Y, RayDir.Z)
|
|
|
VBGamer |
© |
|
|
|
|