Post

 Resources 

Console

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

 All Forums
 VBGamer
 VBGamer
 In search of a ray pick example!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Knight Chat X
Squire

USA
24 Posts

Posted - Dec 02 2004 :  09:42:16 AM  Show Profile  Visit Knight Chat X's Homepage  Reply with Quote
Hey All,
Anyone got a working VB.Net example of Ray Picking or 3D mesh object intersection?

Need to know how to perform intersection testing on a mesh object to enable mouse interaction to know when an object has been clicked on, such as for first person shooter, so I can know where to fire a projectile, or to click on objects and interact with items in a world. It is for 3D world.

I've found one C++ example here:
http://www.mvps.org/directx/articles/improved_ray_picking.htm

There is also an example in a book called Introduction to 3D Game Programming which is specific to ray picking using a bounding sphere, so far my attempts at converting those samples to VB.Net failed.



The net is getting bigger and bigger.

Almar
Moderator

Netherlands
192 Posts

Posted - Dec 02 2004 :  2:10:10 PM  Show Profile  Visit Almar's Homepage  Send Almar an ICQ Message  Reply with Quote
Well, the above one + the C++ one included in the SDK, are the best you can get, just make sure you transform your ray to the object "world matrix" of the current/previous frame so you can check for a hit. That's the real important thing.

I only have C++ code, can't help you on it in VB :). I think someone might have done it too on the www.gpwiki.org site.


Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Dec 02 2004 :  3:37:54 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
I have some old VB code here http://www.strategon.com/dark/index.asp?page=mouseray
Go to Top of Page

Knight Chat X
Squire

USA
24 Posts

Posted - Dec 02 2004 :  9:46:07 PM  Show Profile  Visit Knight Chat X's Homepage  Reply with Quote

Thanks guys, I'm looking at both links now.

If I still can't get it going I might post a follow up with source code on the failed conversions incase there's anything that's obvious someone could point out that's causing it to not work.

The net is getting bigger and bigger.
Go to Top of Page

Knight Chat X
Squire

USA
24 Posts

Posted - Dec 03 2004 :  10:09:00 PM  Show Profile  Visit Knight Chat X's Homepage  Reply with Quote


Well guys, I couldn't get any of the method's to work in VB.Net and DirectX 9.0c at all but they do work with VB6 and DirectX 8.1, so I'm posting a zip file that contains the main code snippets I've found online and tried converting using the different method's here:

Download Attachment: 5 Ray Intersection Code Snippets.zip<br>9.02 KB

Forgot to add this one, this method uses Unprojection and IntersectionInformation with a mesh object.


Download Attachment: Ray Intersection Unprojected.txt<br>1.76 KB

Maybe someone can see why none of those examples are working and post a solution because I doubt I'm the onlyone running into problems like this.

The net is getting bigger and bigger.

Edited by - Knight Chat X on Dec 03 2004 10:54:52 PM
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Dec 03 2004 :  11:19:38 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
Well, if they work in VB6/DX8 and not in VB.NET/DX9, then I'd say the problem isn't with this ray picking code, so the bug must be somewhere else in the VB.NET and DX9 code. I know I'm stating the obvious, but I can't see why the algorithms would work in one case and nother the other. The idea is pretty much the same, you simply take a line segment extending through the view frustum and do the inverse transformations to get the line segment into the coordinate system of whatever object you're trying to intersect. The only tip that I can think of right now is to check to make sure you're using the correct matrices.
Go to Top of Page

cbx
Swordmaster

Canada
296 Posts

Posted - Dec 15 2004 :  12:52:11 PM  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
quote:
Originally posted by Knight Chat X

Hey All,
Anyone got a working VB.Net example of Ray Picking or 3D mesh object intersection?

Need to know how to perform intersection testing on a mesh object to enable mouse interaction to know when an object has been clicked on, such as for first person shooter, so I can know where to fire a projectile, or to click on objects and interact with items in a world. It is for 3D world.

I've found one C++ example here:
http://www.mvps.org/directx/articles/improved_ray_picking.htm

There is also an example in a book called Introduction to 3D Game Programming which is specific to ray picking using a bounding sphere, so far my attempts at converting those samples to VB.Net failed.






Have you tried using the Mesh.Intersect method for D3D Mesh object in DX9?

one of the overloaded intersect methods is

Public Function Intersect( _
ByVal rayPos As Vector3, _
ByVal rayDir As Vector3, _
ByRef closestHit As IntersectInformation _
) As Boolean

This method will return the falowing information ...

Dist: Retrieves or sets the distance along the ray where the intersection occurred.
FaceIndex: Retrieves or sets the index of the triangle that intersected the ray.
U: Retrieves or sets the barycentric coordinate within the triangle where the ray intersects.
V: Retrieves or sets the barycentric coordinate within the triangle where the ray intersects.


There is also a number of usfull methods contained in Direct3D.Geometry ....

BoxBoundProbe: Determines whether a ray intersects the volume of a bounding box.
ComputeBoundingBox: Computes a coordinate axis-oriented bounding box.
ComputeBoundingSphere: Computes a bounding sphere for a mesh.
DegreeToRadian: Converts degrees to radians.
FresnelTerm: Calculates the Fresnel term.
IntersectTri: Computes the intersection of a ray and a triangle.
OptimizeFaces: Optimizes a set of faces.
ptimizeVertices: Optimizes a set of vertices.
RadianToDegree: Converts radians to degrees.
SphereBoundProbe: Determines whether a ray intersects the volume of a sphere's bounding box.



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.12 seconds. Snitz Forums 2000

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