Sign in to follow this  

bullet hole calculating

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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 [url=""]web page[/url].
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.

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
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.

[b]Pseudo Code:[/b]
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
next Object


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


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