<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/10418" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2015-03-09T23:38:06+00:00</updated>

	<author><name><![CDATA[Real-Time Physics Simulation Forum]]></name></author>
	<id>https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/10418</id>

		<entry>
		<author><name><![CDATA[Dirk Gregorius]]></name></author>
		<updated>2015-03-09T23:38:06+00:00</updated>

		<published>2015-03-09T23:38:06+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35087#p35087</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35087#p35087"/>
		<title type="html"><![CDATA[Re: Physics Engine Questions (GJK+EPA, SI/PGS)]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35087#p35087"><![CDATA[
This question is way too long. You need to break into smaller parts.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=14">Dirk Gregorius</a> — Mon Mar 09, 2015 11:38 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[glitchyme]]></name></author>
		<updated>2015-03-08T06:29:58+00:00</updated>

		<published>2015-03-08T06:29:58+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35077#p35077</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35077#p35077"/>
		<title type="html"><![CDATA[Re: Physics Engine Questions (GJK+EPA, SI/PGS)]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35077#p35077"><![CDATA[
I could really use some advice, but haven't heard anything yet. I've forwarded the post to gamedev: <a href="http://www.gamedev.net/topic/666447-3d-physics-engine-absolute-beginner-absolutely-stuck/" class="postlink">http://www.gamedev.net/topic/666447-3d- ... ely-stuck/</a>  with some updates. Please feel free to look there and reply either there or here. Any insight into this could really help me out, thanks  <img class="smilies" src="https://pybullet.org/Bullet/phpBB3/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11188">glitchyme</a> — Sun Mar 08, 2015 6:29 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[glitchyme]]></name></author>
		<updated>2015-03-04T22:47:31+00:00</updated>

		<published>2015-03-04T22:47:31+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35074#p35074</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35074#p35074"/>
		<title type="html"><![CDATA[Physics Engine Questions (GJK+EPA, SI/PGS)]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=35074#p35074"><![CDATA[
Hey all, I'm getting to that point in my 3d rigid body simulator where things are getting pretty hairy. I've got some weird issues, and I'm hoping that somebody can confirm my understanding for the simulation process.<br><br><br><strong class="text-strong">Main Physics Update</strong><ol style="list-style-type:decimal"><li> Update velocity (add external forces, eg. gravity)</li><li> Predict position for all bodies (temporarily update position)</li><li> Collision detection</li><li> Collision resolution</li><li> Restore positions for all bodies</li><li> Add stored impulses to velocity, reset impulses</li><li> Update position for all bodies (using the new velocity)</li></ol>I'm assuming that performing the position prediction is beneficial in allowing us to find collisions before they occur, and apply enough impulse in order to prevent those collisions. After the collision resolution procedure stores some impulse in each body, we apply those impulses directly to the linear/angular velocity and reset the stored impulse to 0. Dampening may or may not be applied to velocities afterwards (not sure if this is necessary?). <br><br><br><strong class="text-strong">Collision Detection</strong><ol style="list-style-type:decimal"><li> Broadphase detection</li><li> GJK+EPA</li><li> Add/update contacts to the contact manifold</li></ol>I believe my collision detection works, but the most important question is: is what I'm returning the same thing that SI/PGS is expecting? GJK+EPA returns a normal, a penetration depth, and 2 contact points: essentially EPA finishes with a support point and a triangle in the minkowski configuration. Those contact points can be found by first retrieving the bayesian coefficients (u, v, w) with respect to the last projected point, and multiplying those coefficients with the associated support points:<div class="codebox"><p>Code: </p><pre><code>contact.pointA = triangle.v1.support_a*u + triangle.v2.support_a*v + triangle.v3.support_a*wcontact.pointB = triangle.v1.support_b*u + triangle.v2.support_b*v + triangle.v3.support_b*w</code></pre></div>The new contact is added to the bodyA/bodyB manifold. If the same contact already exists (the pair of associated vertices for each support point {support_a.vertex_index, support_b.vertex_index} is the same in an existing contact) then that contact is updated with the new information. Otherwise the new contact is updated. If our manifold exceeds 4 points then delete the weakest contact. This also means that older (weaker) contacts are not updated whatsoever, so they're assumed to be persistent until the bodyA/bodyB are no longer colliding. I'm sure this is wrong, but I couldn't find any material in how to maintain manifolds with older contacts (is it still colliding? have the contacts moved? etc.)<br><br><br><strong class="text-strong">Collision Resolution</strong><ol style="list-style-type:decimal"><li> For each contact: solve penetrations, warmstart impulses, calculate b for baumgarte stabilization</li><li> For each contact: For each iteration: find delta lambda and add impulse</li></ol><strong class="text-strong">Solve Penetrations</strong><div class="codebox"><p>Code: </p><pre><code>contact.rA = contact.pointA - bodyA.positioncontact.tangent = contact.rA.cross(contact.normal)bodyA.d = bodyA.invMass + contact.normal.dot( contact.tangent.cross(contact.rA) * bodyA.invInertia )contact.d = 1.0 / (bodyA.d + bodyB.d)dVA = contact.normal.dot( bodyA.velocity ) + contact.tangent.dot( bodyA.angularVelocity )immediateLinearImpulse = contact.normal * body.invMass * (contact.depth - (dVA * contact.d) - (dVB * contact.d))immediateAngularImpulse = contact.tangent * body.invInertia * (contact.depth - (dVA * contact.d) - (dVB * contact.d))</code></pre></div>both of the immediate impulses are directly added to each body's linear/angular velocity.<br><br><strong class="text-strong">Warmstart Impulses</strong><br>Dampen contact's stored impulse and apply to each body<div class="codebox"><p>Code: </p><pre><code>contact.impulse *= warmstartbody.applyLinearImpulse( contact.normal * body.invMass * contact.impulse )body.applyAngularImpulse( contact.tangent * body.invInertia * contact.impulse )</code></pre></div>Note that the impulses don't affect the velocity until after the collision resolution.<br><br><strong class="text-strong">Baumgarte Stabilization</strong><div class="codebox"><p>Code: </p><pre><code>relativeVelocityA = contact.normal.dot(bodyA.velocity) + contact.tangent.dot(bodyA.angularVelocity)contact.b = contact.d * (contact.depth + slop) * baumgarte / dt + contact.d * (relativeVelocityA + relativeVelocityB) * damping</code></pre></div><strong class="text-strong">Sequential Impulses</strong><div class="codebox"><p>Code: </p><pre><code>delta = contact.b - contact.impulsedVA = contact.normal.dot(bodyA.impulseV) + contact.tangent.dot(bodyA.impulseW)delta -= dVA * contact.d + dVB * contact.dcontact.impulse = clamp(contact.impulse + delta, 0, Infinity)body.applyLinearImpulse( contact.normal * body.invMass * delta )body.applyAngularImpulse( contact.tangent * body.invInertia * delta )</code></pre></div>Note that contact.impulse is stored for the next time around, and the body's impulses are reset by the end of the physics engine update. <br><br><br>I could really use some advice, if anybody here knows what I'm doing wrong or if I misunderstood something please let me know.<br><br><br>Video 1: <a href="https://www.youtube.com/watch?v=nA8X4PINldE" class="postlink">https://www.youtube.com/watch?v=nA8X4PINldE</a><br>Notice that the first two attempts the body simply topples over. The 3rd attempt the body stabilizes but runs into the resting contact problem.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11188">glitchyme</a> — Wed Mar 04, 2015 10:47 pm</p><hr />
]]></content>
	</entry>
	</feed>
