26 typedef struct cpShapeClass cpShapeClass;
49 typedef enum cpShapeType{
57 typedef void (*cpShapeDestroyImpl)(
cpShape *shape);
65 cpShapeCacheDataImpl cacheData;
66 cpShapeDestroyImpl destroy;
67 cpShapeNearestPointQueryImpl nearestPointQuery;
68 cpShapeSegmentQueryImpl segmentQuery;
73 CP_PRIVATE(
const cpShapeClass *klass);
144 #define CP_DefineShapeStructGetter(type, member, name) \
145 static inline type cpShapeGet##name(const cpShape *shape){return shape->member;}
147 #define CP_DefineShapeStructSetter(type, member, name, activates) \
148 static inline void cpShapeSet##name(cpShape *shape, type value){ \
149 if(activates && shape->body) cpBodyActivate(shape->body); \
150 shape->member = value; \
153 #define CP_DefineShapeStructProperty(type, member, name, activates) \
154 CP_DefineShapeStructGetter(type, member, name) \
155 CP_DefineShapeStructSetter(type, member, name, activates)
157 CP_DefineShapeStructGetter(
cpSpace*, CP_PRIVATE(space), Space)
159 CP_DefineShapeStructGetter(
cpBody*, body, Body)
160 void cpShapeSetBody(
cpShape *shape, cpBody *body);
162 CP_DefineShapeStructGetter(
cpBB, bb, BB)
163 CP_DefineShapeStructProperty(
cpBool, sensor, Sensor,
cpTrue)
165 CP_DefineShapeStructProperty(cpFloat, u, Friction,
cpTrue)
166 CP_DefineShapeStructProperty(
cpVect, surface_v, SurfaceVelocity,
cpTrue)
177 #define CP_DeclareShapeGetter(struct, type, name) type struct##Get##name(const cpShape *shape)
183 typedef struct cpCircleShape {
191 cpCircleShape* cpCircleShapeAlloc(
void);
193 cpCircleShape* cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset);
195 cpShape* cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset);
197 CP_DeclareShapeGetter(cpCircleShape, cpVect, Offset);
198 CP_DeclareShapeGetter(cpCircleShape, cpFloat, Radius);
204 typedef struct cpSegmentShape {
211 cpVect a_tangent, b_tangent;
215 cpSegmentShape* cpSegmentShapeAlloc(
void);
217 cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, cpVect b, cpFloat radius);
219 cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
221 void cpSegmentShapeSetNeighbors(
cpShape *shape, cpVect prev, cpVect next);
223 CP_DeclareShapeGetter(cpSegmentShape, cpVect, A);
224 CP_DeclareShapeGetter(cpSegmentShape, cpVect, B);
225 CP_DeclareShapeGetter(cpSegmentShape, cpVect, Normal);
226 CP_DeclareShapeGetter(cpSegmentShape, cpFloat, Radius);