|
Ball simulation |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Hi guys, (and gals if there are any), I was inspired to make a ball simulation based on https://www.allegro.cc/forums/thread/617607, and I now have a fully functional if partially broken simulator. It's pretty stable, but there must be some small condition I'm missing that allows balls to escape my 'pen'. {"name":"611793","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/9\/b95642beba27f3d707743eea718cb23e.png","w":1026,"h":801,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/9\/b95642beba27f3d707743eea718cb23e"} As you can see, there are many balls with many different velocities and accelerations, and the intercept times are all calculated properly, except for every once in a while, a collision is failed to be detected. And a few balls still escape the pen. Can anyone help me figure out what is going on? I narrowed it down to this ; 1. An intercept is detected. In an attempt to remedy #4 I used the normal direction and "Pushed" the balls away from each other by half the difference between the distance and the total radial distance. What can I do to prevent them from overlapping in the first place? "Rewind time" by a small amount so they never overlap in the first place? I need to work on the numerical stability of the program as well, if anyone has any tips on that I would appreciate it. I know I said never to move objects into overlap positions, but I'm not sure how to do that here. I feel like I'm going to have to 'cheat' somehow. All the code is on Github here : My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
GullRaDriel
Member #3,861
September 2003
|
I build it on my comp using git allegro source and shared library (had to modify the project options) It never escaped yet... And I tried stressing it ! Proof: {"name":"611794","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/6\/26b76e8283779a5d7de76e5ec545daf6.png","w":1033,"h":812,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/6\/26b76e8283779a5d7de76e5ec545daf6"} "Code is like shit - it only smells if it is not yours" |
Edgar Reynaldo
Major Reynaldo
May 2007
|
That's amazing! How did you get them to stay put! EDIT Pull from git and try again. This time try with only 10-20 large balls (small balls can be launched with the RMB. The farther you are from the middle of the screen with the mouse, the faster they will go. Leave a little space. I added a workspace project. I can add dynamic linking projects too if you want. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
dakatt
Member #10,695
February 2009
|
I can't build the project but that's my lack of build exp rather than your fault. I don't know if it will help (considering one of the issues in my engine is the problem you set out to solve) but this is what I have so far To setup create a CP2D_Engine object in main, then use ->Update() and ->Draw() in the main loop. To create a body use ->Add_Body(). I don't know how I'd incorporate the collision times that you spoke of before Edgar but maybe splitting the overlap and collision resolution functions could achieve a similar result? |
Chris Katko
Member #1,881
January 2002
|
I just want to re-iterate that I freakin' love the "graph" like presentation. My brain is like "OOoooOOOhhh that could be a game." -----sig: |
Edgar Reynaldo
Major Reynaldo
May 2007
|
If you build it they will come. Join me, and together we can rule the galaxy as Father and Son! Dakatt said: I can't build the project but that's my lack of build exp rather than your fault. I don't know if it will help (considering one of the issues in my engine is the problem you set out to solve) but this is what I have so far It should be easier now. I included a workspace with a static library set up. You just have to tell it where to find allegro. Load the workspace in CB and rebuild. dakatt said: To setup create a CP2D_Engine object in main, then use ->Update() and ->Draw() in the main loop. To create a body use ->Add_Body(). I don't know how I'd incorporate the collision times that you spoke of before Edgar but maybe splitting the overlap and collision resolution functions could achieve a similar result? If you're going to use intercept times, then you need a collision table. You can see how I did it in my Merlin (Interceptor) library here : https://github.com/EdgarReynaldo/Merlin Check this line in your p2d_body.h file : https://github.com/DaKatt/P2D/blob/master/p2d_body.h#L73 distance will never be negative, fabs is unnecessary. Just a tip. Could it be because of the default rounding mode? Do I have to set that somehow? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
GullRaDriel
Member #3,861
September 2003
|
I compiled it with gcc version 6.3.0 (MinGW.org GCC-6.3.0-1) on windows 7 x64 with latest allegro5 from git.
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/
"Code is like shit - it only smells if it is not yours" |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I'm not sure what I did, but some tinkering seemed to stabilize things. Try the binaries for the ball bin and the intercept graph : {"name":"611797","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/b\/ab9cd722d7d8cc77d2aa886d9a3384c0.png","w":1026,"h":801,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/b\/ab9cd722d7d8cc77d2aa886d9a3384c0"} {"name":"611798","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/9\/796fc2a0ec62437603f9f296a2c7ca6a.png","w":1026,"h":801,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/9\/796fc2a0ec62437603f9f296a2c7ca6a"} I let the ball bin run for like 15 minutes and none escaped, so? But definitely try the intercept graph (IGraph.exe). Controls are LMB, RMB, and MMB. LMB moves the ball. RMB sets the velocity. MMB sets the acceleration. S stops the ball. P pauses and unpauses the simulation. R toggles redraw. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
GullRaDriel
Member #3,861
September 2003
|
Got it fine too even with more than 450 little balls. I have waited until there was no more overlapping, and none escaped. {"name":"611803","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/a\/0a79f69212a6b11997f9d43540029d67.png","w":1303,"h":861,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/a\/0a79f69212a6b11997f9d43540029d67"} "Code is like shit - it only smells if it is not yours" |
Edgar Reynaldo
Major Reynaldo
May 2007
|
If you rebuild with elasticity equal to .7 or .8, you can get the balls to fall through each other. Elasticity is in resolver.cpp. For some reason it doesn't like low velocity particles. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
GullRaDriel
Member #3,861
September 2003
|
In which order do you do things ? "Code is like shit - it only smells if it is not yours" |
Edgar Reynaldo
Major Reynaldo
May 2007
|
That's exactly what I do Gully. thanks I'm gonna try something if I can get my old computer running 🏃 My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|