Debian Codegraph @

doc/examples/BreakableJoint.html

raw symbols SCIP
1 <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; "><em><span style="color:#236e25;">// Create the joint and set it's max force property.
2 </span></em>breakableJoint = <span style="color:#003369;">cpSpaceAddConstraint</span>(space, <span style="color:#003369;">cpPinJointNew</span>(body1, body2, <span style="color:#003369;">cpv</span>(<span style="color:#0000ff;">15</span>,<span style="color:#0000ff;">0</span>), <span style="color:#003369;">cpv</span>(-<span style="color:#0000ff;">15</span>,<span style="color:#0000ff;">0</span>)));
3 <span style="color:#003369;">cpConstraintSetMaxForce</span>(breakableJoint, <span style="color:#0000ff;">4000</span>);
4
5
6 <em><span style="color:#236e25;">// In your update function:
7 // Step your space normally...
8 </span></em>cpFloat dt = <span style="color:#0000ff;">1.0</span>/<span style="color:#0000ff;">60.0</span>;
9 <span style="color:#003369;">cpSpaceStep</span>(space, dt);
10
11 <strong><span style="color:#881350;">if</span></strong>(breakableJoint){
12 <em><span style="color:#236e25;">// Convert the impulse to a force by dividing it by the timestep.
13 </span></em> cpFloat force = <span style="color:#003369;">cpConstraintGetImpulse</span>(breakableJoint)/dt;
14 cpFloat maxForce = <span style="color:#003369;">cpConstraintGetMaxForce</span>(breakableJoint);
15
16 <em><span style="color:#236e25;">// If the force is almost as big as the joint's max force, break it.
17 </span></em> <strong><span style="color:#881350;">if</span></strong>(force &gt; <span style="color:#0000ff;">0.9</span>*maxForce){
18 <span style="color:#003369;">cpSpaceRemoveConstraint</span>(space, breakableJoint);
19 breakableJoint = <strong><span style="color:#881350;">NULL</span></strong>;
20 }
21 }
22 </pre>