00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00024
00025 typedef struct cpConstraintClass cpConstraintClass;
00026
00027 typedef void (*cpConstraintPreStepImpl)(cpConstraint *constraint, cpFloat dt);
00028 typedef void (*cpConstraintApplyCachedImpulseImpl)(cpConstraint *constraint, cpFloat dt_coef);
00029 typedef void (*cpConstraintApplyImpulseImpl)(cpConstraint *constraint);
00030 typedef cpFloat (*cpConstraintGetImpulseImpl)(cpConstraint *constraint);
00031
00033 struct cpConstraintClass {
00034 cpConstraintPreStepImpl preStep;
00035 cpConstraintApplyCachedImpulseImpl applyCachedImpulse;
00036 cpConstraintApplyImpulseImpl applyImpulse;
00037 cpConstraintGetImpulseImpl getImpulse;
00038 };
00039
00041 typedef void (*cpConstraintPreSolveFunc)(cpConstraint *constraint, cpSpace *space);
00043 typedef void (*cpConstraintPostSolveFunc)(cpConstraint *constraint, cpSpace *space);
00044
00045
00047 struct cpConstraint {
00048 CP_PRIVATE(const cpConstraintClass *klass);
00049
00051 cpBody *a;
00053 cpBody *b;
00054
00055 CP_PRIVATE(cpSpace *space);
00056
00057 CP_PRIVATE(cpConstraint *next_a);
00058 CP_PRIVATE(cpConstraint *next_b);
00059
00062 cpFloat maxForce;
00066 cpFloat errorBias;
00069 cpFloat maxBias;
00070
00073 cpConstraintPreSolveFunc preSolve;
00074
00077 cpConstraintPostSolveFunc postSolve;
00078
00082 cpDataPointer data;
00083 };
00084
00086 void cpConstraintDestroy(cpConstraint *constraint);
00088 void cpConstraintFree(cpConstraint *constraint);
00089
00091 static inline void cpConstraintActivateBodies(cpConstraint *constraint)
00092 {
00093 cpBody *a = constraint->a; if(a) cpBodyActivate(a);
00094 cpBody *b = constraint->b; if(b) cpBodyActivate(b);
00095 }
00096
00098 #define CP_DefineConstraintStructGetter(type, member, name) \
00099 static inline type cpConstraint##Get##name(const cpConstraint *constraint){return constraint->member;}
00100
00102 #define CP_DefineConstraintStructSetter(type, member, name) \
00103 static inline void cpConstraint##Set##name(cpConstraint *constraint, type value){ \
00104 cpConstraintActivateBodies(constraint); \
00105 constraint->member = value; \
00106 }
00107
00109 #define CP_DefineConstraintStructProperty(type, member, name) \
00110 CP_DefineConstraintStructGetter(type, member, name) \
00111 CP_DefineConstraintStructSetter(type, member, name)
00112
00113 CP_DefineConstraintStructGetter(cpBody*, a, A);
00114 CP_DefineConstraintStructGetter(cpBody*, b, B);
00115 CP_DefineConstraintStructProperty(cpFloat, maxForce, MaxForce);
00116 CP_DefineConstraintStructProperty(cpFloat, errorBias, ErrorBias);
00117 CP_DefineConstraintStructProperty(cpFloat, maxBias, MaxBias);
00118 CP_DefineConstraintStructProperty(cpConstraintPreSolveFunc, preSolve, PreSolveFunc);
00119 CP_DefineConstraintStructProperty(cpConstraintPostSolveFunc, postSolve, PostSolveFunc);
00120 CP_DefineConstraintStructProperty(cpDataPointer, data, UserData);
00121
00122
00123 static inline cpFloat cpConstraintGetImpulse(cpConstraint *constraint)
00124 {
00125 return constraint->CP_PRIVATE(klass)->getImpulse(constraint);
00126 }
00127
00129
00130 #define cpConstraintCheckCast(constraint, struct) \
00131 cpAssertHard(constraint->CP_PRIVATE(klass) == struct##GetClass(), "Constraint is not a "#struct)
00132
00133 #define CP_DefineConstraintGetter(struct, type, member, name) \
00134 static inline type struct##Get##name(const cpConstraint *constraint){ \
00135 cpConstraintCheckCast(constraint, struct); \
00136 return ((struct *)constraint)->member; \
00137 }
00138
00139 #define CP_DefineConstraintSetter(struct, type, member, name) \
00140 static inline void struct##Set##name(cpConstraint *constraint, type value){ \
00141 cpConstraintCheckCast(constraint, struct); \
00142 cpConstraintActivateBodies(constraint); \
00143 ((struct *)constraint)->member = value; \
00144 }
00145
00146 #define CP_DefineConstraintProperty(struct, type, member, name) \
00147 CP_DefineConstraintGetter(struct, type, member, name) \
00148 CP_DefineConstraintSetter(struct, type, member, name)
00149
00150 #include "cpPinJoint.h"
00151 #include "cpSlideJoint.h"
00152 #include "cpPivotJoint.h"
00153 #include "cpGrooveJoint.h"
00154 #include "cpDampedSpring.h"
00155 #include "cpDampedRotarySpring.h"
00156 #include "cpRotaryLimitJoint.h"
00157 #include "cpRatchetJoint.h"
00158 #include "cpGearJoint.h"
00159 #include "cpSimpleMotor.h"