Sign in to follow this  
Fixxer

Ray Tracing Help!

Recommended Posts

I cannot figure how to get ray tracing to work at all. Right now I just want to use them for bullets. Here are the functions I have to use, I think most of them explain them selves. Can anyone help me? FUNCTION LIST ----------------------------- dbAddVector2 dbAddVector3 dbAddVector4 dbCatMullRomVector2 dbCatMullRomVector3 dbCopyMatrix4 dbCopyVector2 dbCopyVector3 dbCopyVector4 dbCrossProductVector3 dbDeleteVector2 dbDeleteVector3 dbDeleteVector4 dbDivideVector2 dbDivideVector3 dbDivideVector4 dbDotProductVector2 dbDotProductVector3 dbBCCVector2 dbBCCVector3 dbBCCVector4 dbSquaredLengthVector2 dbSquaredLengthVector3 dbSquaredLengthVector4 dbLengthVector2 dbLengthVector3 dbLengthVector4 dbWVector4 dbXVector2 dbXVector3 dbXVector4 dbYVector2 dbYVector3 dbYVector4 dbZVector3 dbZVector4 dbHermiteVector2 dbHermiteVector3 dbHermiteVector4 dbIsEqualVector2 dbIsEqualVector3 dbIsEqualVector4 dbLinearInterpolateVector2 dbLinearInterpolateVector3 dbLinearInterpolateVector4 dbMakeVector2 dbMakeVector3 dbMakeVector4 dbMaximizeVector2 dbMaximizeVector3 dbMaximizeVector4 dbMinimizeVector2 dbMinimizeVector3 dbMinimizeVector4 dbMultiplyVector2 dbMultiplyVector3 dbMultiplyVector4 dbNormalizeVector2 dbNormalizeVector3 dbNormalizeVector4 dbProjectVector3 dbScaleVector2 dbScaleVector3 dbScaleVector4 dbSubtractVector2 dbSubtractVector3 dbSubtractVector4 dbTransformVector4 dbTransformCoordsVector2 dbTransformCoordsVector3 dbTransformNormalsVector3

Share this post


Link to post
Share on other sites
Well, that's sort of like saying "I need to build some object, here's what I have: some screws and some other generic construction type parts."

You can use those vector functions and others in your raytracing algorithm, but you need to read about ray-object intersection algorithms/formulas, which are readily available, to see how you must use those functions.

You say that you can't figure out how to get raytracing working at all, but--no offense intended--it doesn't sound like you have even tried... at ALL... to figure out how to get it to work. Is there any particular aspect of it that you are unclear about?

Share this post


Link to post
Share on other sites
Basically all of it.
I got "help" at another forum, but I was left still unclear about it all, and then no one decided to respond to my questions I had.

What I got from it was (and im not even sure if this is right) making 2 vectors, projecting them starting from the barrel of the gun, at the angle the user is aiming, and storing all the locations the ray hits my world in, and then treating the 1st location as the bullet hit, and then acting once I have that info.

Even with that info, I dont know what to do.

Share this post


Link to post
Share on other sites
Quote:

What I got from it was (and im not even sure if this is right) making 2 vectors, projecting them starting from the barrel of the gun, at the angle the user is aiming, and storing all the locations the ray hits my world in, and then treating the 1st location as the bullet hit, and then acting once I have that info.


That information is pretty clear. Create a ray with a starting position equal to the gun's current position and a direction equal to the gun's direction. Then test that ray against possible polygons that may be hit (for a simple game just test it against every polygon in the scene). Ignore every intersection but the closest one. The object at this intersection point should be considered "shot", and the appropriate actions should be taken after that.

I don't think that you will have to use any functions besides the basic vector creation and component manipulation functions (except maybe in your intersection routines).

Share this post


Link to post
Share on other sites
I'm assuming the two vectors you mention are the position of the gun's barrel tip and the direction that the player is facing. These two vectors form a ray originating at the barrel tip and pointing in the direction the gun is aiming(assuming the gun is aiming the same direction the player is looking).

Once you have that ray, its just a matter of intersecting it with your scene, like you mentioned, and finding the closest intersection. To do this, you need to perform a ray/object intersection with every object in your scene (Later, you can use spatial partitioning to optimize this so you only have to test a subset of the objects in your scene). To be precise, you could perform ray/triangle-mesh intersections with each object, or use bounding spheres/boxes, or whatever else you want to use.

If you're unclear on how to perform these ray/object intersections, I'd suggest looking over some graphical ray tracing tutorials, as those are common and the concepts are the same. I think Flipcode has a nice serious of tutorials on raytracing that covers trivial ray-sphere intersections.

Share this post


Link to post
Share on other sites
Quote:
Original post by AcePilot
Quote:

What I got from it was (and im not even sure if this is right) making 2 vectors, projecting them starting from the barrel of the gun, at the angle the user is aiming, and storing all the locations the ray hits my world in, and then treating the 1st location as the bullet hit, and then acting once I have that info.


That information is pretty clear. Create a ray with a starting position equal to the gun's current position and a direction equal to the gun's direction. Then test that ray against possible polygons that may be hit (for a simple game just test it against every polygon in the scene). Ignore every intersection but the closest one. The object at this intersection point should be considered "shot", and the appropriate actions should be taken after that.

I don't think that you will have to use any functions besides the basic vector creation and component manipulation functions (except maybe in your intersection routines).


So:

MakeVector3
MakeVector3
?????????????
Test For Intersect
Get Closest Intersect
Delete vectors

I dont know, thats where I am at.
I think my "engine" might be too crappy for this to work anyway.
I am using the Dark Game SDK, and the basic collision functions dont even work.

Share this post


Link to post
Share on other sites
Do you have easy access to:

1) The position of the tip of the gun barrel,
2) The direction the player is facing, and
3) A list of triangles that compose your scene?

I'm not familiar with the Dark Game SDK, does it provide a ray/triangle intersection function, given a ray and three vertices?

Share this post


Link to post
Share on other sites
Well... you just described the process fairly accurately. Go here for a really good tutorial on the topic. If this doesn't help you, I don't know what to say.

Share this post


Link to post
Share on other sites
Quote:
Original post by ShawMishrak
Do you have easy access to:

1) The position of the tip of the gun barrel,
2) The direction the player is facing, and
3) A list of triangles that compose your scene?

I'm not familiar with the Dark Game SDK, does it provide a ray/triangle intersection function, given a ray and three vertices?



1.)Yes, I have a vech object ( a very tiny cube) that I use to move the camera, and test for collision.

2) Yes, and angle of the vech object

3) I dont have any idea on how I can get this :P

There is this function I just found....

-----------------------------------------------

dbIntersectObject
This command will return the distance to the point of intersection between two coordinates, in reference to the specified object. Use this command to project a line from your current position to a destination to determine whether a collision will occur with an object. Ideal for bullet calculations and fast manual polygon collision.

Syntax
float dbIntersectObject ( int iObject, float fX, float fY, float fZ, float fToX, float fToY, float fToZ )

Share this post


Link to post
Share on other sites
Alright, this should be trivial enough. If that dbIntersectObject function does what it says, then just call it for each object in your scene. Whichever object returns the smallest value, that's your nearest intersection. I'm not sure how it handles the no-collision condition though. It might return 0.0 or -1.0, so make sure you don't count that as your nearest intersection.

Your fx, fy, and fz will just be the position of your vech object. For toX, toY, and toZ, you'll want to use the vech object's orientation to add on to the vech object's position. You really want your toX, toY, and toZ coordinates to represent a point farther away than any object in your scene, but on the ray cast by the gun's barrel.

In pseudo-code, you'd have something like:

fX = vech.position.x;
fY = vech.position.y;
fZ = vech.position.z;

fToX = vech.position.x + vech.direction.x * cons; // cons is just some multiplier to make sure your fToX, fToY, and fToZ values are farther away than your farthest object in your scene.
fToY = vech.position.y + vech.direction.y * cons;
fToZ = vech.position.z + vech.direction.z * cons;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this