bullet hole calculating

Started by
5 comments, last by Mr.L 11 years, 8 months ago
i think the title explains it pretty good:
i want to make a function that takes the player position(start of the bullet path,vector)and the bullets direction, loops through all the Objects(thetrahedrons) and returns the Vectors Position and angle of the BUllet decal.

although I have a fairly understanding of 3D geometry, i Have no Idea how i should solve it, expecialy the position in the thetrahedral.
Advertisement
Checking all objects could slow things down if there are alot of bullets or objects; so I will not describe how to cut the amount of cheking that needs to be done.

Sort the objects to be checked by distance from bullet origin.
A thetrahedron is 4 triangle faces in a pyramid fashon. Is this right? IDK
If so, you want a ray to triangle intersection. Take a look at this web page.
Loop through all four triangle faces to find points of intersection.
If there is a intersection point, skip remainder of object checking.
Sort found points by distance from bullet origin.
Nearest point is the center of bullet decal and disreguard other points. (Unless you want exit hole decal)
Angle of bullet decal is the face normal of triangle.
ok so should check and loop all faces of all thetrahedrons, and not check all thetrahedrons first?

wouldn't it save processor time by checking all thetrahedrons first, or did i missunerstand something?
It depends on many tetrahedrons objects need to be checked against a single bullet/ray.
Each tetrahedron object has four faces. So there would be four ray/triangle checks per object.
Brute force checking all tetrahedron objects could be the way to go.

Are all tetrahedrons objects always in front of the player?
If there are some behind the player there is no need to check for bullet collision on those tetrahedron objects.

Presorting the tetrahedron objects in front of the player will also cut down on the calculations if the bullet hit the nearest object.
The worst case is if the tetrahedron object were the last one to be hit or the bullet missed all together.

Actually, shooting and missing is very common so best to cut down on how many tetrahedron objects that need to be checked right off the bat.
ok the code should look like this

-loop objects and flag if behind the player.
-sort the objects, ignore the flaged ones.
-check for collision on each face of each object, break if collision with face.
-save face normal,bulletpositiono.
-draw the bullet hole.

is this right?
Yep, pretty much. There are other ways of selecting what objects to be check but this is the basic idea. Probably don't have to do any flagging, just if the object meets the criteria in order to proceed with the next check.

Pseudo Code:

empty List
Ray = Player.Shoot()

for Object in Objects:
if Object.IsBehind(Player):
next Object
if Ray.IsCollidable(Object): // Just simple check if ray passes through object's bounding sphere
List += Object // Add object to ray's collision path
else:
next Object

List.SortClosest(Player)

for Object in List:
point Point
vector Normal
if Object.FaceIntersect(Ray, &Point, &Normal):
Object.state = Bullet_Hit
Object.SetDecal(Point, Normal, BulletHoleDecal)
break
else:
next Object

Objects.Render()
ok, thanks, that helps me a lot

This topic is closed to new replies.

Advertisement