aatish [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=32237 Spring Physics 0.1 <p> <table><tr><td> <a href="/bbs/?pid=84525#p"> <img src="/bbs/thumbs/pico8_springphysics-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=84525#p"> Spring Physics 0.1</a><br><br> by <a href="/bbs/?uid=32237"> aatish</a> <br><br><br> <a href="/bbs/?pid=84525#p"> [Click to Play]</a> </td></tr></table> </p> <p>Hi all. I put together a work in progress demo of a simple physics engine that can handle particles connected by springs. This uses a method known as <a href="https://en.wikipedia.org/wiki/Verlet_integration">Verlet integration</a> which is stable and efficient, so you can simulate dozens of springs in real time.</p> <p>The cart includes 4 demos: a pendulum, a string, a cloth, and a deformable rigid body.</p> <ul> <li> <img style="margin-bottom:16px" border=0 src="/media/32237/pendulum.gif" alt="" /> <img style="margin-bottom:16px" border=0 src="/media/32237/string.gif" alt="" /> </li> <li> <img style="margin-bottom:16px" border=0 src="/media/32237/5_cloth.gif" alt="" /> <img style="margin-bottom:16px" border=0 src="/media/32237/softbody.gif" alt="" /> </li> </ul> <p>The library implements the approach laid out by Thomas Jakobsen in the article <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.206.4908&amp;amp;rep=rep1&amp;amp;type=pdf">Advanced Character Physics</a>. The syntax is inspired by the physics simulation library <a href="http://toxiclibs.org/">toxiclibs</a>.</p> <p>Here's an example of the syntax to create two particles connected by a rigid spring (i.e. a pendulum).</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> -- create particles p1 = particle(64,10) p2 = particle(10,10) p1:lock() -- create a spring, which takes 4 arguments -- particle 1, particle 2, length, stiffness (between 0 and 1) s = spring(p1, p2, 50, 0.5) -- add gravity physics:setforce(0,10) -- add particles and spring to the physics world physics:addparticle(p1) physics:addparticle(p2) physics:addspring(s)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>I haven't implemented drag, friction, or collisions. But I figured I'd share this as is, in case it's helpful to folks. Feedback welcome.</p> https://www.lexaloffle.com/bbs/?tid=40507 https://www.lexaloffle.com/bbs/?tid=40507 Fri, 20 Nov 2020 11:25:12 UTC