N-Body simulation in c++ using DarkGDK (O(n^2) algorithm)
Loading...
3,825
Loading...
Uploader Comments (DKM101)
see all
All Comments (14)
-
Good work =)
-
@DKM101 another thing i ve just seen: your for loop: for(n = 0...) ... for(i = 0...) you should change it to for(n = 0...) ... for(i = n+1...). And for the collision i would just do something like project v1 and v2 on the connection vector of the two bodies and exchange the resulting velocities depending on their mass. if you want it accurate you should calculate the real collision time and take it into account for calculating their real positions after the collision
-
Cool. But you should try to use the barnes hut algorithm to reduce the inefficient O(n^2) algorithm to O(nlogn) :)
-
Thats so...beautiful
-
Awesome.
Loading...
passing const float as a parameter doesnt make sense.(in checkColl) :D
Tip to speed it up drastically: add a grid of size e.g. 16x16 and calculate just every x frames gravitational attraction of all grid points + create a list with all grid points that have an attraction != 0 and use these grid points to calculate attraction of each body. for bodies in the same grid(+ maybe the neighboring grid points) calculate the force as you do it now. That way you can adjust between performance and quality
ecreif 1 year ago
@ecreif
Yeah, I have a quadtree coded up but... what I can't get working is the damned collision! I have a method I can iterate huge amount of times to get expected results, but that's just too slow. (the method ensures that per 2 colliding bodies, momentum is preserved)
Meh, I either need to remove collision physics, or learn to do it better!
DKM101 1 year ago
That's awesome, dude. Do you still have angular momentum appearing from the ether? You should stick in a gridding system if you haven't already, unless you already have some kind of system to stop checking collision between distant bodies. Any thoughts about making a game from this?
MrHoppyX 1 year ago
@MrHoppyX
I've found a hack to fix it, but I need to write a collision solver to cut down on computation time. Turns out I can't just deal with a bunch of cases between two objects unless I iterate whatever collision algorithm 100 or so times, because all of the collisions are interdependent. Once I get collision physics working I'm gonna implement a quadtree and some other optimizations, Hopefully can a thousand or so objects! More if I try to multithread it or run stuff on the GPU.
DKM101 1 year ago
thanks for the nazi zombie instrumental shoutout man (im khalillondon), love the vid, good shit. stay up!
lilkale187 1 year ago
@lilkale187
:D
DKM101 1 year ago