<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>2d only rope physics</title>
		<link>http://www.allegro.cc/forums/view/574094</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 29 Mar 2006 22:17:14 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve read NeHe&#39;s tutorial on rope physics, and it&#39;s a little over my head... I was wondering where I could get started on <b>strictly 2d rope physics.</b></p><p>Here&#39;s what I have in mind<br /><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/7/a7afe930c7748b7c2a8da832cf004734.gif" alt="image16dt.gif" width="154" height="190" /><br />This is a lamp attatched to a rope which is also attatched to the ceiling. Here&#39;s what I want to happen:<br /><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/7/574e42fe76b6eff925819d4e779255d8.gif" alt="image26lc.gif" width="154" height="190" /><br />The red vector would be the bullet, and the yellow path is just the result of the bullet falling after it has hit the lamp. I&#39;m trying to figure out the physics for the rope and lamp.</p><p>Where do I even begin with mounting the lamp on to the rope? I can see that the length, x, and y all stay constant during.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ceagon Xylas)</author>
		<pubDate>Tue, 21 Mar 2006 12:47:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think you should cheat <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /><br />What i mean is that you should try a simpler approach, no need for true rope physics! In the example of the lamp you must ask yourself, how would i expect it to react?<br />Most probably you would expect the lamp to go back and forth, much like a pendulum... so just make it follow a pendulum&#39;s movement!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (FMC)</author>
		<pubDate>Tue, 21 Mar 2006 14:38:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><i>Most probably you would expect the lamp to go back and forth, much like a pendulum... so just make it follow a pendulum&#39;s movement!</i></p><p>And, indeed after the initial impact, it will act just like a pendulum.  However the difference between &quot;rope physics&quot; and pendulum physics is that pendulums are assumed to be stiff.  The &quot;fun&quot; in the rope physics is the flexibility and how neat it will look upon initial impact when the &quot;pendulum weight&quot; is moving independently of the &quot;pendulum arm&quot; because it&#39;s a rope.  <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>I don&#39;t pretend to know how to implement this in code without studying up on it...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Birdeeoh)</author>
		<pubDate>Tue, 21 Mar 2006 23:49:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I know nothing about rope physics, but off the top of my head I have an idea for an approach.</p><p>1)When the rope is slack treat the lamp as it if is just a freefalling object (should be easy to do).</p><p>2)When the rope goes tight (i.e. the distance between the lamp and the ceiling where the rope is attached == the length of the rope) apply a normal force to the lamp. That is a force along the rope toward the ceiling to cancel out any movement in the direction  along the rope (plus any you want to add for the sake of elasticity in the rope). </p><p>If you&#39;re in a situation where the rope is staying taut at all times, then giving the lamp pendulum motion sounds like a good idea.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (FrankyR)</author>
		<pubDate>Tue, 21 Mar 2006 23:55:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The easiest way that I know of to simulate a rope is to approximate it as a sequence of connected weights.<br />In zero-th order approximation, the rope would be a stiff rod.<br />In first order approximation, it would be two rods connected together halfway through the length of the rope and allowed any motion relative to eachother as long as the ends stay connected.<br />The second order is three connected rods, <i>et cetera ad infinitum</i>.</p><p>Instead of stiff rods, you can use weights connected by massless springs. By varying the spring constant you can change how the rope reacts to being pulled and twisted - you can even vary it along the length of the rope to simulate a weak spot in the rope. In the limit where the spring constant becomes infinite you should get back the stiff rod.</p><p>Be warned though that this approach gives rise to a rather bothersome set of coupled equations that will need to be solved (because the force on the first mass element produces a torque and a force on the second mass element, which produces a force and a torque on the third... etc).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 22 Mar 2006 00:06:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Also beware of the ghastly effects that occur if you don&#39;t integrate with a fine enough timestep or don&#39;t account for friction properly.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Wed, 22 Mar 2006 00:25:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Couldn&#39;t you do something like plot three points, one at the top, one half way down and one at the bottom. Make the bottom one move further than the middle in a slight arc then join the top to the two points using catmull-rom spline?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 22 Mar 2006 01:03:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think for something like this it would be simpler in the end to implement some actual physics:</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Be warned though that this approach gives rise to a rather bothersome set of coupled equations that will need to be solved (because the force on the first mass element produces a torque and a force on the second mass element, which produces a force and a torque on the third... etc).
</p></div></div><p>

<a href="http://www.gamasutra.com/resource_guide/20030121/jacobson_01.shtml">Verlet! Verlet!</a> This is the type of thing verlet integration excels at from what I&#39;ve been able to gather....
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nonnus29)</author>
		<pubDate>Wed, 22 Mar 2006 07:07:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or you could download newton dynamic library or ODE and create a 2d rope rather easily with some hinged joints <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 22 Mar 2006 14:10:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ew ew ew, sorry guys. I stupidly posted this the day before Oblivion arrived at my front door. Of course I&#39;ve been doing that with all my free time. Back to programming <b>classic</b> games! =D<br />Lemme check this stuff out...</p><p>The reason I don&#39;t want a pendulum effect is precisely because of the stiffness. My game offers 360 degree directional shooting... So if you hit the lamp from the bottom, I want it to move up-wards into the ceiling and bounce off.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The easiest way that I know of to simulate a rope is to approximate it as a sequence of connected weights.
</p></div></div><p>
Yes, this sounds like the best choice to me. Would you know where I could see some code for it?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Or you could download newton dynamic library or ODE
</p></div></div><p>
Can I get some links for those? I searched and <b>bleh</b> nothing useful came up after a while of sifting through google pickups.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ceagon Xylas)</author>
		<pubDate>Tue, 28 Mar 2006 12:26:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t know if this is what you are looking for but just on the off chance:<a href="http://freespace.virgin.net/hugo.elias/models/m_main.htm">http://freespace.virgin.net/hugo.elias/models/m_main.htm</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (lambik)</author>
		<pubDate>Tue, 28 Mar 2006 13:03:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ooo...This is handy!</p><p>[edit]<br />Yes, this is very much what I was looking for! Thank you!</p><p>[edit again]<br />Okay, I&#39;ve got my rope working almost perfectly. The only problem is that both ends of the rope are static... I want only one static point [mounted to the ceiling] and the other to interact with the lamp. Here&#39;s my code.</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">class</span> rope<span class="k2">{</span></td></tr><tr><td class="number">2</td><td>public:</td></tr><tr><td class="number">3</td><td>  <span class="k1">class</span> joint<span class="k2">{</span></td></tr><tr><td class="number">4</td><td>  public:</td></tr><tr><td class="number">5</td><td>    <span class="k1">float</span> x1,y1,x2,y2<span class="k2">;</span></td></tr><tr><td class="number">6</td><td>    <span class="k1">float</span> velX,velY<span class="k2">;</span></td></tr><tr><td class="number">7</td><td>  <span class="k2">}</span>joint<span class="k2">[</span><span class="n">10</span><span class="k2">]</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>  <span class="k1">float</span> seg_length<span class="k2">;</span>     <span class="c">//length of segments between joints</span></td></tr><tr><td class="number">10</td><td>  <span class="k1">float</span> air_resistance<span class="k2">;</span> <span class="c">//air resistance [negating factor on gravity {9.8}]</span></td></tr><tr><td class="number">11</td><td>  <span class="k1">float</span> damping<span class="k2">;</span>        <span class="c">//self-explanitory</span></td></tr><tr><td class="number">12</td><td>  <span class="k1">float</span> speed<span class="k2">;</span>          <span class="c">//didn't know what else to name this</span></td></tr><tr><td class="number">13</td><td>  </td></tr><tr><td class="number">14</td><td>  <span class="k1">void</span> deploy<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//initializes the rope</span></td></tr><tr><td class="number">15</td><td>  <span class="k1">void</span> update<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//called every game-cycle</span></td></tr><tr><td class="number">16</td><td><span class="k2">}</span>rope<span class="k2">[</span><span class="n">20</span><span class="k2">]</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>&#160;</td></tr><tr><td class="number">18</td><td><span class="k1">void</span> rope::deploy<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">19</td><td>  <span class="k1">for</span><span class="k2">(</span><span class="k1">short</span> i<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> i<span class="k3">&lt;</span><span class="n">10</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">20</td><td>    joint<span class="k3">&lt;</span>i&gt;.x1<span class="k3">=</span><span class="n">320</span><span class="k3">+</span>i<span class="k2">;</span> joint<span class="k3">&lt;</span>i&gt;.y1<span class="k3">=</span>i<span class="k3">*</span><span class="n">3</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>    joint<span class="k3">&lt;</span>i&gt;.x2<span class="k3">=</span><span class="n">320</span><span class="k2">;</span> joint<span class="k3">&lt;</span>i&gt;.y2<span class="k3">=</span>i<span class="k3">*</span><span class="n">3</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>    joint<span class="k3">&lt;</span>i&gt;.velX<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> joint<span class="k3">&lt;</span>i&gt;.velY<span class="k3">=</span><span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">24</td><td>  seg_length<span class="k3">=</span><span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td>  air_resistance<span class="k3">=</span><span class="n">0</span>.<span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>  damping<span class="k3">=</span><span class="n">0</span>.<span class="n">95</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td>  speed<span class="k3">=</span><span class="n">0</span>.<span class="n">01</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td><span class="k2">}</span><span class="k2">;</span></td></tr><tr><td class="number">29</td><td>&#160;</td></tr><tr><td class="number">30</td><td><span class="k1">void</span> rope::update<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">31</td><td>  <span class="k1">for</span><span class="k2">(</span><span class="k1">short</span> i<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> i<span class="k3">&lt;</span><span class="n">10</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">32</td><td>    <span class="k1">if</span><span class="k2">(</span>i&gt;0 <span class="k3">&amp;</span><span class="k3">&amp;</span> i<span class="k3">&lt;</span><span class="n">10</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">33</td><td>      <span class="k1">float</span> vx1<span class="k3">=</span>joint<span class="k2">[</span>i-1<span class="k2">]</span>.x1-joint<span class="k3">&lt;</span>i&gt;.x1<span class="k2">;</span> <span class="c">//vector 1: diffrence between x's</span></td></tr><tr><td class="number">34</td><td>      <span class="k1">float</span> vy1<span class="k3">=</span>joint<span class="k2">[</span>i-1<span class="k2">]</span>.y1-joint<span class="k3">&lt;</span>i&gt;.y1<span class="k2">;</span> <span class="c">//vector 1: diffrence between y's</span></td></tr><tr><td class="number">35</td><td>      <span class="k1">int</span> vm1<span class="k3">=</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_83.html" target="_blank">ceil</a><span class="k2">(</span>vx1<span class="k3">*</span>vx1<span class="k3">+</span>vy1<span class="k3">*</span>vy1<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//vector 1: magnitude</span></td></tr><tr><td class="number">36</td><td>      <span class="k1">int</span> ve1<span class="k3">=</span>vm1-seg_length<span class="k2">;</span>              <span class="c">//vector 1: extention</span></td></tr><tr><td class="number">37</td><td>      </td></tr><tr><td class="number">38</td><td>      <span class="k1">float</span> vx2<span class="k3">=</span>joint<span class="k2">[</span>i<span class="k3">+</span><span class="n">1</span><span class="k2">]</span>.x1-joint<span class="k3">&lt;</span>i&gt;.x1<span class="k2">;</span> <span class="c">//vector 2: diffrence between x's</span></td></tr><tr><td class="number">39</td><td>      <span class="k1">float</span> vy2<span class="k3">=</span>joint<span class="k2">[</span>i<span class="k3">+</span><span class="n">1</span><span class="k2">]</span>.y1-joint<span class="k3">&lt;</span>i&gt;.y1<span class="k2">;</span> <span class="c">//vector 2: diffrence between y's</span></td></tr><tr><td class="number">40</td><td>      <span class="k1">int</span> vm2<span class="k3">=</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_83.html" target="_blank">ceil</a><span class="k2">(</span>vx2<span class="k3">*</span>vx2<span class="k3">+</span>vy2<span class="k3">*</span>vy2<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//vector 2: magnitude</span></td></tr><tr><td class="number">41</td><td>      <span class="k1">int</span> ve2<span class="k3">=</span>vm2-seg_length<span class="k2">;</span>              <span class="c">//vector 2: extention</span></td></tr><tr><td class="number">42</td><td>      </td></tr><tr><td class="number">43</td><td>      <span class="k1">float</span> vx<span class="k3">=</span><span class="k2">(</span>vx1<span class="k3">/</span>vm1<span class="k3">*</span>ve1<span class="k2">)</span><span class="k3">+</span><span class="k2">(</span>vx2<span class="k3">/</span>vm2<span class="k3">*</span>ve2<span class="k2">)</span><span class="k2">;</span>                    <span class="c">//x's reactant</span></td></tr><tr><td class="number">44</td><td>      <span class="k1">float</span> vy<span class="k3">=</span><span class="k2">(</span>vy1<span class="k3">/</span>vm1<span class="k3">*</span>ve1<span class="k2">)</span><span class="k3">+</span><span class="k2">(</span>vy2<span class="k3">/</span>vm2<span class="k3">*</span>ve2<span class="k2">)</span><span class="k3">+</span><span class="n">9</span>.<span class="n">8</span><span class="k3">-</span>air_resistance<span class="k2">;</span> <span class="c">//y's reactant</span></td></tr><tr><td class="number">45</td><td>      </td></tr><tr><td class="number">46</td><td>      joint<span class="k3">&lt;</span>i&gt;.velX<span class="k3">=</span>joint<span class="k3">&lt;</span>i&gt;.velX<span class="k3">*</span>damping<span class="k3">+</span><span class="k2">(</span>vx<span class="k3">*</span>speed<span class="k2">)</span><span class="k2">;</span> <span class="c">//set velocity x accordingly</span></td></tr><tr><td class="number">47</td><td>      joint<span class="k3">&lt;</span>i&gt;.velY<span class="k3">=</span>joint<span class="k3">&lt;</span>i&gt;.velY<span class="k3">*</span>damping<span class="k3">+</span><span class="k2">(</span>vy<span class="k3">*</span>speed<span class="k2">)</span><span class="k2">;</span> <span class="c">//set velocity y accordingly</span></td></tr><tr><td class="number">48</td><td>      joint<span class="k3">&lt;</span>i&gt;.x2<span class="k3">=</span>joint<span class="k3">&lt;</span>i&gt;.x1<span class="k3">+</span>joint<span class="k3">&lt;</span>i&gt;.velX<span class="k2">;</span>          <span class="c">//buffer x</span></td></tr><tr><td class="number">49</td><td>      joint<span class="k3">&lt;</span>i&gt;.y2<span class="k3">=</span>joint<span class="k3">&lt;</span>i&gt;.y1<span class="k3">+</span>joint<span class="k3">&lt;</span>i&gt;.velY<span class="k2">;</span>          <span class="c">//buffer y</span></td></tr><tr><td class="number">50</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">51</td><td>    joint<span class="k3">&lt;</span>i&gt;.x1<span class="k3">=</span>joint<span class="k3">&lt;</span>i&gt;.x2<span class="k2">;</span>                          <span class="c">//copy buffer to physical</span></td></tr><tr><td class="number">52</td><td>    joint<span class="k3">&lt;</span>i&gt;.y1<span class="k3">=</span>joint<span class="k3">&lt;</span>i&gt;.y2<span class="k2">;</span>                          <span class="c">//copy buffer to physical</span></td></tr><tr><td class="number">53</td><td>    </td></tr><tr><td class="number">54</td><td>    <span class="c">//draw joint and lines between</span></td></tr><tr><td class="number">55</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">56</td><td><span class="k2">}</span><span class="k2">;</span></td></tr></tbody></table></div></div><p>

http://img93.imageshack.us/img93/1467/rope0ue.gif</p><p>My brain can almost grasp it... <tt>joint[0]</tt>&#39;s x and y are controlled by up, down, left, and right; and will be assigned a static point later on in the coding of <tt>deploy();</tt>. So I need to make <tt>joint[max]</tt>&#39;s x and y controllable by the lamp. But how?!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ceagon Xylas)</author>
		<pubDate>Tue, 28 Mar 2006 14:16:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>looks just like the old lamps in elevator action! <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (fuzinavl)</author>
		<pubDate>Wed, 29 Mar 2006 22:17:14 +0000</pubDate>
	</item>
</rss>
