Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 HELP: D3DX IntersectTri method does not work?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cbx
Swordmaster

Canada
296 Posts

Posted - Jun 22 2004 :  03:17:54 AM  Show Profile  Visit cbx's Homepage  Send cbx an ICQ Message  Click to see cbx's MSN Messenger address  Send cbx a Yahoo! Message  Reply with Quote
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

Created by: X
http://www.createdbyx.com/

Edited by - cbx on Jun 22 2004 03:22:38 AM

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 22 2004 :  09:00:05 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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)  
  


Go to Top of Page

cbx
Swordmaster

Canada
296 Posts

Posted - Jun 23 2004 :  04:25:23 AM  Show Profile  Visit cbx's Homepage  Send cbx an ICQ Message  Click to see cbx's MSN Messenger address  Send cbx a Yahoo! Message  Reply with Quote
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...

Created by: X
http://www.createdbyx.com/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.14 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.