File: Crushing.html

package info (click to toggle)
chipmunk 7.0.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,968 kB
  • sloc: ansic: 29,265; objc: 4,313; ruby: 409; makefile: 10; sh: 1
file content (23 lines) | stat: -rw-r--r-- 1,557 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<pre style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><strong><span style="color:#881350;">struct</span></strong> CrushingContext {
  cpFloat magnitudeSum;
  cpVect vectorSum;
};

<strong><span style="color:#881350;">static</span></strong> <strong><span style="color:#881350;">void</span></strong>
<span style="color:#003369;">EstimateCrushingHelper</span>(cpBody *body, cpArbiter *arb, <strong><span style="color:#881350;">struct</span></strong> CrushingContext *context)
{
  cpVect j = <span style="color:#003369;">cpArbiterTotalImpulseWithFriction</span>(arb);
  context-&gt;magnitudeSum += <span style="color:#003369;">cpvlength</span>(j);
  context-&gt;vectorSum = <span style="color:#003369;">cpvadd</span>(context-&gt;vectorSum, j);
}

cpFloat
<span style="color:#003369;">EstimateCrushForce</span>(cpBody *body, cpFloat dt)
{
  <strong><span style="color:#881350;">struct</span></strong> CrushingContext crush = {<span style="color:#0000ff;">0.0f</span>, cpvzero};
  <span style="color:#003369;">cpBodyEachArbiter</span>(body, (cpBodyArbiterIteratorFunc)EstimateCrushingHelper, &amp;crush);
  
  <span style="color:#236e25;"><em>// Compare the vector sum magnitude and magnitude sum to see if
</em></span>  <span style="color:#236e25;"><em>// how much the collision forces oppose one another.
</em></span>  cpFloat crushForce = (crush.magnitudeSum - <span style="color:#003369;">cpvlength</span>(crush.vectorSum))*dt;
}</pre>