25 typedef struct cpConstraintClass cpConstraintClass;
28 typedef void (*cpConstraintApplyCachedImpulseImpl)(
cpConstraint *constraint,
cpFloat dt_coef);
33 struct cpConstraintClass {
34 cpConstraintPreStepImpl preStep;
35 cpConstraintApplyCachedImpulseImpl applyCachedImpulse;
36 cpConstraintApplyImpulseImpl applyImpulse;
37 cpConstraintGetImpulseImpl getImpulse;
48 CP_PRIVATE(
const cpConstraintClass *klass);
91 static inline void cpConstraintActivateBodies(
cpConstraint *constraint)
98 #define CP_DefineConstraintStructGetter(type, member, name) \
99 static inline type cpConstraint##Get##name(const cpConstraint *constraint){return constraint->member;}
102 #define CP_DefineConstraintStructSetter(type, member, name) \
103 static inline void cpConstraint##Set##name(cpConstraint *constraint, type value){ \
104 cpConstraintActivateBodies(constraint); \
105 constraint->member = value; \
109 #define CP_DefineConstraintStructProperty(type, member, name) \
110 CP_DefineConstraintStructGetter(type, member, name) \
111 CP_DefineConstraintStructSetter(type, member, name)
113 CP_DefineConstraintStructGetter(
cpSpace*, CP_PRIVATE(space), Space)
115 CP_DefineConstraintStructGetter(
cpBody*, a, A)
116 CP_DefineConstraintStructGetter(cpBody*, b, B)
117 CP_DefineConstraintStructProperty(
cpFloat, maxForce, MaxForce)
118 CP_DefineConstraintStructProperty(cpFloat, errorBias, ErrorBias)
119 CP_DefineConstraintStructProperty(cpFloat, maxBias, MaxBias)
122 CP_DefineConstraintStructProperty(
cpDataPointer, data, UserData)
125 static inline cpFloat cpConstraintGetImpulse(
cpConstraint *constraint)
127 return constraint->CP_PRIVATE(klass)->getImpulse(constraint);
132 #define cpConstraintCheckCast(constraint, struct) \
133 cpAssertHard(constraint->CP_PRIVATE(klass) == struct##GetClass(), "Constraint is not a "#struct)
135 #define CP_DefineConstraintGetter(struct, type, member, name) \
136 static inline type struct##Get##name(const cpConstraint *constraint){ \
137 cpConstraintCheckCast(constraint, struct); \
138 return ((struct *)constraint)->member; \
141 #define CP_DefineConstraintSetter(struct, type, member, name) \
142 static inline void struct##Set##name(cpConstraint *constraint, type value){ \
143 cpConstraintCheckCast(constraint, struct); \
144 cpConstraintActivateBodies(constraint); \
145 ((struct *)constraint)->member = value; \
148 #define CP_DefineConstraintProperty(struct, type, member, name) \
149 CP_DefineConstraintGetter(struct, type, member, name) \
150 CP_DefineConstraintSetter(struct, type, member, name)
152 #include "cpPinJoint.h"
153 #include "cpSlideJoint.h"
154 #include "cpPivotJoint.h"
155 #include "cpGrooveJoint.h"
156 #include "cpDampedSpring.h"
157 #include "cpDampedRotarySpring.h"
158 #include "cpRotaryLimitJoint.h"
159 #include "cpRatchetJoint.h"
160 #include "cpGearJoint.h"
161 #include "cpSimpleMotor.h"