26 typedef struct cpShapeClass cpShapeClass;
52 typedef enum cpShapeType{
60 typedef void (*cpShapeDestroyImpl)(
cpShape *shape);
68 cpShapeCacheDataImpl cacheData;
69 cpShapeDestroyImpl destroy;
70 cpShapeNearestPointQueryImpl nearestPointQuery;
71 cpShapeSegmentQueryImpl segmentQuery;
76 CP_PRIVATE(
const cpShapeClass *klass);
147 #define CP_DefineShapeStructGetter(type, member, name) \
148 static inline type cpShapeGet##name(const cpShape *shape){return shape->member;}
150 #define CP_DefineShapeStructSetter(type, member, name, activates) \
151 static inline void cpShapeSet##name(cpShape *shape, type value){ \
152 if(activates && shape->body) cpBodyActivate(shape->body); \
153 shape->member = value; \
156 #define CP_DefineShapeStructProperty(type, member, name, activates) \
157 CP_DefineShapeStructGetter(type, member, name) \
158 CP_DefineShapeStructSetter(type, member, name, activates)
160 CP_DefineShapeStructGetter(
cpSpace*, CP_PRIVATE(space), Space)
162 CP_DefineShapeStructGetter(
cpBody*, body, Body)
163 void cpShapeSetBody(
cpShape *shape, cpBody *body);
165 CP_DefineShapeStructGetter(
cpBB, bb, BB)
166 CP_DefineShapeStructProperty(
cpBool, sensor, Sensor,
cpTrue)
168 CP_DefineShapeStructProperty(cpFloat, u, Friction,
cpTrue)
169 CP_DefineShapeStructProperty(
cpVect, surface_v, SurfaceVelocity,
cpTrue)
180 #define CP_DeclareShapeGetter(struct, type, name) type struct##Get##name(const cpShape *shape)
186 typedef struct cpCircleShape {
194 cpCircleShape* cpCircleShapeAlloc(
void);
196 cpCircleShape* cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset);
198 cpShape* cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset);
200 CP_DeclareShapeGetter(cpCircleShape, cpVect, Offset);
201 CP_DeclareShapeGetter(cpCircleShape, cpFloat, Radius);
207 typedef struct cpSegmentShape {
214 cpVect a_tangent, b_tangent;
218 cpSegmentShape* cpSegmentShapeAlloc(
void);
220 cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, cpVect b, cpFloat radius);
222 cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
225 void cpSegmentShapeSetNeighbors(
cpShape *shape, cpVect prev, cpVect next);
227 CP_DeclareShapeGetter(cpSegmentShape, cpVect, A);
228 CP_DeclareShapeGetter(cpSegmentShape, cpVect, B);
229 CP_DeclareShapeGetter(cpSegmentShape, cpVect, Normal);
230 CP_DeclareShapeGetter(cpSegmentShape, cpFloat, Radius);