   Ray Tracing Help!
  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-----------------------------dbAddVector2dbAddVector3dbAddVector4dbCatMullRomVector2dbCatMullRomVector3dbCopyMatrix4dbCopyVector2dbCopyVector3dbCopyVector4dbCrossProductVector3dbDeleteVector2dbDeleteVector3dbDeleteVector4dbDivideVector2dbDivideVector3dbDivideVector4dbDotProductVector2dbDotProductVector3dbBCCVector2dbBCCVector3dbBCCVector4dbSquaredLengthVector2dbSquaredLengthVector3dbSquaredLengthVector4dbLengthVector2dbLengthVector3dbLengthVector4dbWVector4dbXVector2dbXVector3dbXVector4dbYVector2dbYVector3dbYVector4dbZVector3dbZVector4dbHermiteVector2dbHermiteVector3dbHermiteVector4dbIsEqualVector2dbIsEqualVector3dbIsEqualVector4dbLinearInterpolateVector2dbLinearInterpolateVector3dbLinearInterpolateVector4dbMakeVector2dbMakeVector3dbMakeVector4dbMaximizeVector2dbMaximizeVector3dbMaximizeVector4dbMinimizeVector2dbMinimizeVector3dbMinimizeVector4dbMultiplyVector2dbMultiplyVector3dbMultiplyVector4dbNormalizeVector2dbNormalizeVector3dbNormalizeVector4dbProjectVector3dbScaleVector2dbScaleVector3dbScaleVector4dbSubtractVector2dbSubtractVector3dbSubtractVector4dbTransformVector4dbTransformCoordsVector2dbTransformCoordsVector3dbTransformNormalsVector3   
  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?;  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.   ;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).   ;  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.   ;Quote:Original post by AcePilotQuote: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:MakeVector3MakeVector3?????????????Test For IntersectGet Closest IntersectDelete vectorsI 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.   ;  Do you have easy access to:1) The position of the tip of the gun barrel,2) The direction the player is facing, and3) 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?;  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.   ;Quote:Original post by ShawMishrakDo you have easy access to:1) The position of the tip of the gun barrel,2) The direction the player is facing, and3) 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 object3) I dont have any idea on how I can get this :PThere 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 ) ;  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;   