Page 1 of 2

3D Physics Engine

Posted: Sun Mar 17, 2024 12:17 am
by ShoesForClues
Sup y'all. Been working on a 3D physics engine for a while and finally made progress with this.

This engine uses a clipping algorithm that I came up with and does not rely on GJK/EPA or SAT. This does give the disadvantage of it only working with vertex shapes.

Screenshots

Image

Image

I'll release the source of this soon, once I clean up the code. It's not as stable and kinda laggy atm.

UPDATE: Here is the preview demo!

CONTROLS:
  • Use WASDEQ and mouse buttons to move the camera
  • Press [1] to toggle wireframe
  • Press [2] to toggle bounding boxes
  • Press [3] to pause the physics simulation and [T] to step through each frame
  • Press [F] to fire an object
  • Press [R] to move all objects
Apologies if the code is messy. Some of it dates back to 2 years ago!

Please also consider following my GitHub for updates: https://github.com/0x1ED1CE/FPS

Re: 3D Physics Engine

Posted: Sun Mar 17, 2024 1:22 pm
by pgimeno
That's pretty impressive!

Re: 3D Physics Engine

Posted: Sun Mar 17, 2024 4:48 pm
by siberian
It looks great!

Re: 3D Physics Engine

Posted: Sun Mar 17, 2024 5:37 pm
by ShoesForClues
Thanks guys!

Re: 3D Physics Engine

Posted: Sun Mar 17, 2024 6:50 pm
by CapitalEx
You came up with your own algorithm? That's pretty impressive.

Re: 3D Physics Engine

Posted: Sun Mar 17, 2024 7:27 pm
by ShoesForClues
CapitalEx wrote: Sun Mar 17, 2024 6:50 pm You came up with your own algorithm? That's pretty impressive.
Yup! The first iteration actually used GJK and EPA but I was having a hard time trying to figure out how to produce a contact manifold from it.

I eventually found a source that instead uses clipping to compute the contact manifolds but it assumed I already had the separation normal and distance (either from EPA or SAT). https://dyn4j.org/2011/11/contact-point ... -clipping/

I wanted a way to compute everything using only the clipping volume: collision detection, contact manifold, separation normal and separation distance. I eventually realized this was indeed possible.

First, collision detection can be done by checking if there are any remaining vertexes from the clipping. If everything is discarded it means there were no overlapping vertexes and therefor no collision.

Second, to get an approximate contact point I calculate the centroid of the clipping volume. As mentioned in that source I found.

Third, the separation normal can be obtained by getting the average normal of the overlapping faces from the clipped volume and using their surface area as the bias. Here is a 2D example of what I mean:

Image

Last, once I have the separation normal, I can use that to find the furthest vertex along that direction and treat it as a plane. Then I find the furthest opposing vertex and calculate the distance from the plane via dot product. This gives me the separation distance.

And voila! All of this can be done using just the clipping volume. No need for GJK/EPA or SAT :)

Re: 3D Physics Engine

Posted: Mon Mar 18, 2024 2:49 am
by ShoesForClues
Just updated it with the source at the top. Please credit me if you plan to use the code, thanks! :)

Re: 3D Physics Engine

Posted: Mon Mar 18, 2024 9:43 am
by togFox
I know I want to use this in a future project - I just can't think what for at the moment! :)

Re: 3D Physics Engine

Posted: Mon Mar 18, 2024 7:29 pm
by ShoesForClues
togFox wrote: Mon Mar 18, 2024 9:43 am I know I want to use this in a future project - I just can't think what for at the moment! :)
Haha same here.

Re: 3D Physics Engine

Posted: Tue Mar 19, 2024 2:38 am
by togFox
I'm thinking either 1st person or 3rd person RPG dungeon crawler with this physics engine for combat and world movement.