<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Ball simulation</title>
		<link>http://www.allegro.cc/forums/view/617660</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 13 Dec 2018 18:32:58 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi guys, (and gals if there are any),</p><p>I was inspired to make a ball simulation based on <a href="https://www.allegro.cc/forums/thread/617607">https://www.allegro.cc/forums/thread/617607</a>, and I now have a fully functional if partially broken simulator.</p><p>It&#39;s pretty stable, but there must be some small condition I&#39;m missing that allows balls to escape my &#39;pen&#39;.</p><p><span class="remote-thumbnail"><span class="json">{"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"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/b/9/b95642beba27f3d707743eea718cb23e-240.jpg" alt="611793" width="240" height="187" /></span></p><p>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.</p><p>Can anyone help me figure out what is going on?</p><p>I narrowed it down to this ;</p><p>1. An intercept is detected.<br />2. I advance time to the first intercept<br />3. At this point, the balls should touch, but not overlap (distance = 0)<br />4. Sometimes the ball overlaps<br />5. Time is advanced to the next intercept<br />6. Sometimes its so quick that the overlapping ball gets hit by another ball, driving it even further into the first ball. No collision can be detected because they already overlap.</p><p>In an attempt to remedy #4 I used the normal direction and &quot;Pushed&quot; the balls away from each other by half the difference between the distance and the total radial distance.</p><p>What can I do to prevent them from overlapping in the first place? &quot;Rewind time&quot; by a small amount so they never overlap in the first place?</p><p>I need to work on the numerical stability of the program as well, if anyone has any tips on that I would appreciate it.</p><p>I know I said never to move objects into overlap positions, but I&#39;m not sure how to do that here. I feel like I&#39;m going to have to &#39;cheat&#39; somehow.</p><p>All the code is on Github here :</p><p><a href="https://github.com/EdgarReynaldo/Merlin">https://github.com/EdgarReynaldo/Merlin</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 10 Dec 2018 21:38:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I build it on my comp using git allegro source and shared library (had to modify the project options)</p><p>It never escaped yet...</p><p>And I tried stressing it !</p><p>Proof:</p><p><span class="remote-thumbnail"><span class="json">{"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"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/2/6/26b76e8283779a5d7de76e5ec545daf6-240.jpg" alt="611794" width="240" height="188" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Mon, 10 Dec 2018 22:18:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s amazing! How did you get them to stay put! <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p><b>EDIT</b><br />What did you compile them with? What OS and architecture are you using?</p><p>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.</p><p>I added a workspace project. I can add dynamic linking projects too if you want.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 11 Dec 2018 01:18:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I can&#39;t build the project but that&#39;s my lack of build exp rather than your fault. I don&#39;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</p><p><a href="https://github.com/DaKatt/P2D">https://github.com/DaKatt/P2D</a></p><p>To setup create a CP2D_Engine object in main, then use -&gt;Update() and -&gt;Draw() in the main loop. To create a body use -&gt;Add_Body(). I don&#39;t know how I&#39;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?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dakatt)</author>
		<pubDate>Tue, 11 Dec 2018 02:33:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I just want to re-iterate that I freakin&#39; love the &quot;graph&quot; like presentation. My brain is like &quot;OOoooOOOhhh that could be a game.&quot;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 11 Dec 2018 16:21:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you build it they will come.</p><p>Join me, and together we can rule the galaxy as Father and Son!</p><p><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=tzvY1OzoDbQ" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/d/6/d6e2be7f7a1fed776bd5f09a89f61869.jpg" border="0" alt="video" title="Click to play video" /></a></div></div></p><div class="quote_container"><div class="title"><a href="https://www.allegro.cc/forums/thread/617660/1040403#target">Dakatt</a> said:</div><div class="quote"><p>
I can&#39;t build the project but that&#39;s my lack of build exp rather than your fault. I don&#39;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
</p></div></div><p>
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.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/617660/1040403#target">dakatt</a> said:</div><div class="quote"><p>
<a href="https://github.com/DaKatt/P2D">https://github.com/DaKatt/P2D</a></p><p>To setup create a CP2D_Engine object in main, then use -&gt;Update() and -&gt;Draw() in the main loop. To create a body use -&gt;Add_Body(). I don&#39;t know how I&#39;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?
</p></div></div><p>
If you&#39;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 :</p><p><a href="https://github.com/EdgarReynaldo/Merlin">https://github.com/EdgarReynaldo/Merlin</a></p><p>Check this line in your p2d_body.h file :</p><p><a href="https://github.com/DaKatt/P2D/blob/master/p2d_body.h#L73">https://github.com/DaKatt/P2D/blob/master/p2d_body.h#L73</a></p><p>distance will never be negative, fabs is unnecessary. Just a tip.</p><p>Could it be because of the default rounding mode? Do I have to set that somehow?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 11 Dec 2018 17:03:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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.
</p><div class="spoiler"><p>
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=/<br />mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c<br />++,objc,obj-c++,fortran,ada --with-pkgversion=&#39;MinGW.org GCC-6.3.0-1&#39; --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libs<br />tdcxx-debug --enable-libgomp --disable-libvtv --enable-nls<br />Thread model: win32<br />gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
</p></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Tue, 11 Dec 2018 20:05:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure what I did, but some tinkering seemed to stabilize things.</p><p>Try the binaries for the ball bin and the intercept graph :</p><p><a href="https://www.allegro.cc/files/attachment/611799">alpha1.zip</a></p><p><span class="remote-thumbnail"><span class="json">{"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"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/b/ab9cd722d7d8cc77d2aa886d9a3384c0-240.jpg" alt="611797" width="240" height="187" /></span></p><p><span class="remote-thumbnail"><span class="json">{"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"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/7/9/796fc2a0ec62437603f9f296a2c7ca6a-240.jpg" alt="611798" width="240" height="187" /></span></p><p>I let the ball bin run for like 15 minutes and none escaped, so? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 11 Dec 2018 21:29:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Got it fine too even with more than 450 little balls.</p><p>I have waited until there was no more overlapping, and none escaped.</p><p><span class="remote-thumbnail"><span class="json">{"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"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/0/a/0a79f69212a6b11997f9d43540029d67-240.jpg" alt="611803" width="240" height="158" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 12 Dec 2018 13:33:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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.</p><p>For some reason it doesn&#39;t like low velocity particles.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 13 Dec 2018 10:07:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In which order do you do things ?<br />You have to generate new position, check if collide, then only if not swap old and new positions. If moving it make it collide it has to stay where it is and have its velocity/whateverelse reversed according to the bounce.<br />The best case would be to compute the intersect point of colliding, and then move accordingly to the first non colliding position, and reverse velocity/whateverelse according to the bounce.<br />So ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Thu, 13 Dec 2018 15:47:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s exactly what I do Gully. thanks I&#39;m gonna try something if I can get my old computer running 🏃
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 13 Dec 2018 18:32:58 +0000</pubDate>
	</item>
</rss>
