File: cpConvexHull.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 (25 lines) | stat: -rw-r--r-- 1,984 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<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;">int</span></strong> first = <span style="color:#0000ff;">0</span>;

<em><span style="color:#236e25;">// Create space to store the convex hull.
// An alloca(), or a variable length array would be a better, but not always portable choice.
</span></em>cpVect *hullVerts = (cpVect *)<span style="color:#003369;">calloc</span>(vertCount, <strong><span style="color:#881350;">sizeof</span></strong>(cpVect));
<strong><span style="color:#881350;">int</span></strong> hullCount = <span style="color:#003369;">cpConvexHull</span>(vertCount, verts, hullVerts, &amp;first, <span style="color:#0000ff;">0.0</span>);

<em><span style="color:#236e25;">// hullVerts[0] will be equal to verts[first] here.
// If you don't care, pass NULL instead of the 'first' pointer.
</span></em>
cpBody *body = <span style="color:#003369;">cpBodyNew</span>(mass, <span style="color:#003369;">cpMomentForPoly</span>(mass, hullCount, hullVerts, cpvzero));
cpShape *shape = <span style="color:#003369;">cpPolyShapeNew</span>(body, hullCount, hullVerts, cpvzero);

<span style="color:#003369;">free</span>(hullVerts);

<em><span style="color:#236e25;">// *********
// Altenatively you can use the CP_CONVEX_HULL() macro to save yourself a little work
</span></em>
<em><span style="color:#236e25;">// The macro will declare the hullCount and hullVerts variables.
// hullVerts is allocated on the stack and does not need to be freed.
</span></em><span style="color:#003369;">CP_CONVEX_HULL</span>(count, verts, hullCount, hullVerts)

cpBody *body = <span style="color:#003369;">cpBodyNew</span>(mass, <span style="color:#003369;">cpMomentForPoly</span>(mass, hullCount, hullVerts, cpvzero));
cpShape *shape = <span style="color:#003369;">cpPolyShapeNew</span>(body, hullCount, hullVerts, cpvzero);
</pre>