3D Physics Engine

Show off your games, demos and other (playable) creations.
User avatar
ShoesForClues
Prole
Posts: 15
Joined: Wed Dec 12, 2018 1:43 pm

3D Physics Engine

Post 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
Attachments
demo.zip
(60.84 KiB) Downloaded 222 times
Last edited by ShoesForClues on Mon Mar 18, 2024 9:26 pm, edited 2 times in total.
User avatar
pgimeno
Party member
Posts: 3655
Joined: Sun Oct 18, 2015 2:58 pm

Re: 3D Physics Engine

Post by pgimeno »

That's pretty impressive!
User avatar
siberian
Prole
Posts: 21
Joined: Sat Apr 06, 2019 1:42 pm

Re: 3D Physics Engine

Post by siberian »

It looks great!
User avatar
ShoesForClues
Prole
Posts: 15
Joined: Wed Dec 12, 2018 1:43 pm

Re: 3D Physics Engine

Post by ShoesForClues »

Thanks guys!
User avatar
CapitalEx
Prole
Posts: 8
Joined: Fri Jul 24, 2015 2:33 am

Re: 3D Physics Engine

Post by CapitalEx »

You came up with your own algorithm? That's pretty impressive.
~~<Ɵ/\/\_: *snake noises*
User avatar
ShoesForClues
Prole
Posts: 15
Joined: Wed Dec 12, 2018 1:43 pm

Re: 3D Physics Engine

Post 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 :)
Last edited by ShoesForClues on Mon Mar 18, 2024 4:23 am, edited 1 time in total.
User avatar
ShoesForClues
Prole
Posts: 15
Joined: Wed Dec 12, 2018 1:43 pm

Re: 3D Physics Engine

Post by ShoesForClues »

Just updated it with the source at the top. Please credit me if you plan to use the code, thanks! :)
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: 3D Physics Engine

Post by togFox »

I know I want to use this in a future project - I just can't think what for at the moment! :)
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
User avatar
ShoesForClues
Prole
Posts: 15
Joined: Wed Dec 12, 2018 1:43 pm

Re: 3D Physics Engine

Post 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.
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: 3D Physics Engine

Post by togFox »

I'm thinking either 1st person or 3rd person RPG dungeon crawler with this physics engine for combat and world movement.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests