MCPcopy Create free account
hub / github.com/axmolengine/axmol / ClipCell

Function ClipCell

tests/cpp-tests/Source/ChipmunkTestBed/demo/Shatter.cpp:65–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65static int ClipCell(cpShape* shape,
66 cpVect center,
67 int i,
68 int j,
69 struct WorleyContex* context,
70 cpVect* verts,
71 cpVect* clipped,
72 int count)
73{
74 cpVect other = WorleyPoint(i, j, context);
75 // printf(" other %dx%d: (% 5.2f, % 5.2f) ", i, j, other.x, other.y);
76 if (cpShapePointQuery(shape, other, NULL) > 0.0f)
77 {
78 // printf("excluded\n");
79 memcpy(clipped, verts, count * sizeof(cpVect));
80 return count;
81 }
82 else
83 {
84 // printf("clipped\n");
85 }
86
87 cpVect n = cpvsub(other, center);
88 cpFloat dist = cpvdot(n, cpvlerp(center, other, 0.5f));
89
90 int clipped_count = 0;
91 for (int j = 0, i = count - 1; j < count; i = j, j++)
92 {
93 cpVect a = verts[i];
94 cpFloat a_dist = cpvdot(a, n) - dist;
95
96 if (a_dist <= 0.0)
97 {
98 clipped[clipped_count] = a;
99 clipped_count++;
100 }
101
102 cpVect b = verts[j];
103 cpFloat b_dist = cpvdot(b, n) - dist;
104
105 if (a_dist * b_dist < 0.0f)
106 {
107 cpFloat t = cpfabs(a_dist) / (cpfabs(a_dist) + cpfabs(b_dist));
108
109 clipped[clipped_count] = cpvlerp(a, b, t);
110 clipped_count++;
111 }
112 }
113
114 return clipped_count;
115}
116
117static void ShatterCell(cpSpace* space,
118 cpShape* shape,

Callers 1

ShatterCellFunction · 0.85

Calls 6

WorleyPointFunction · 0.85
cpShapePointQueryFunction · 0.85
cpvsubFunction · 0.85
cpvdotFunction · 0.85
cpvlerpFunction · 0.85
cpfabsFunction · 0.85

Tested by

no test coverage detected