16.08 KB">
HELP: D3DX IntersectTri method does not work?
cbxI 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. [url]http://msdn.microsoft.com/library/en-us/directx9_m/directx/ref/ns/microsoft.directx.direct3d/c/geometry/m/intersecttri.asp[/url] This is the code i'm using... [code]Dim Hit As Direct3D.IntersectInformation Ret = Direct3D.Geometry.IntersectTri(mobjPts(0), mobjPts(1), mobjPts(2), RayPos, RayDir, Hit)[/code] 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: [url="http://www.vbgamer.com/msgboard/uploaded/cbx/20046223109_IntersectTri.zip"][img]icon_paperclip.gif[/img]IntersectTri.zip[/url]
16.08 KB
Eric ColemanFor 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. [img]http://www.vbgamer.com/msgboard/uploaded/Eric Coleman/200462284711_test.gif[/img] 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, [code] 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) [/code]
cbxIt 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...