Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

N-Body simulation in c++ using DarkGDK (O(n^2) algorithm)

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
3,825
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Mar 20, 2010

little demo of a collision system with gravity. Songs are from newgrounds:
(1) "The Dust and the Devil" by primal-instinct
(2) "Ode to Nazi Zombies" by Khalillondon

You can get the executable of this program here: http://www.filefactory.com/file/b0c214a/n/GDKtest.exe
the source code is posted here: http://forum.thegamecreators.com/?m=forum_view&t=167604&b=6

[update]
source code to this and other stuff is now up here:
http://www.neurofuzzydev.com/downloads/

  • likes, 1 dislikes

Link to this comment:

Share to:

Uploader Comments (DKM101)

  • 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

    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!

  • 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

    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.

  • thanks for the nazi zombie instrumental shoutout man (im khalillondon), love the vid, good shit. stay up!

  • @lilkale187

    :D

see all

All Comments (14)

Sign In or Sign Up now to post a comment!
  • 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...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more