1 /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 #include "chipmunk/chipmunk_private.h"
26 void cpConstraintDestroy(cpConstraint *constraint){}
29 cpConstraintFree(cpConstraint *constraint)
32 cpConstraintDestroy(constraint);
38 cpConstraintInit(cpConstraint *constraint, const cpConstraintClass *klass, cpBody *a, cpBody *b)
40 constraint->klass = klass;
44 constraint->space = NULL;
46 constraint->next_a = NULL;
47 constraint->next_b = NULL;
49 constraint->maxForce = (cpFloat)INFINITY;
50 constraint->errorBias = cpfpow(1.0f - 0.1f, 60.0f);
51 constraint->maxBias = (cpFloat)INFINITY;
53 constraint->collideBodies = cpTrue;
55 constraint->preSolve = NULL;
56 constraint->postSolve = NULL;
60 cpConstraintGetSpace(const cpConstraint *constraint)
62 return constraint->space;
66 cpConstraintGetBodyA(const cpConstraint *constraint)
72 cpConstraintGetBodyB(const cpConstraint *constraint)
78 cpConstraintGetMaxForce(const cpConstraint *constraint)
80 return constraint->maxForce;
84 cpConstraintSetMaxForce(cpConstraint *constraint, cpFloat maxForce)
86 cpAssertHard(maxForce >= 0.0f, "maxForce must be positive.");
87 cpConstraintActivateBodies(constraint);
88 constraint->maxForce = maxForce;
92 cpConstraintGetErrorBias(const cpConstraint *constraint)
94 return constraint->errorBias;
98 cpConstraintSetErrorBias(cpConstraint *constraint, cpFloat errorBias)
100 cpAssertHard(errorBias >= 0.0f, "errorBias must be positive.");
101 cpConstraintActivateBodies(constraint);
102 constraint->errorBias = errorBias;
106 cpConstraintGetMaxBias(const cpConstraint *constraint)
108 return constraint->maxBias;
112 cpConstraintSetMaxBias(cpConstraint *constraint, cpFloat maxBias)
114 cpAssertHard(maxBias >= 0.0f, "maxBias must be positive.");
115 cpConstraintActivateBodies(constraint);
116 constraint->maxBias = maxBias;
120 cpConstraintGetCollideBodies(const cpConstraint *constraint)
122 return constraint->collideBodies;
126 cpConstraintSetCollideBodies(cpConstraint *constraint, cpBool collideBodies)
128 cpConstraintActivateBodies(constraint);
129 constraint->collideBodies = collideBodies;
132 cpConstraintPreSolveFunc
133 cpConstraintGetPreSolveFunc(const cpConstraint *constraint)
135 return constraint->preSolve;
139 cpConstraintSetPreSolveFunc(cpConstraint *constraint, cpConstraintPreSolveFunc preSolveFunc)
141 constraint->preSolve = preSolveFunc;
144 cpConstraintPostSolveFunc
145 cpConstraintGetPostSolveFunc(const cpConstraint *constraint)
147 return constraint->postSolve;
151 cpConstraintSetPostSolveFunc(cpConstraint *constraint, cpConstraintPostSolveFunc postSolveFunc)
153 constraint->postSolve = postSolveFunc;
157 cpConstraintGetUserData(const cpConstraint *constraint)
159 return constraint->userData;
163 cpConstraintSetUserData(cpConstraint *constraint, cpDataPointer userData)
165 constraint->userData = userData;
170 cpConstraintGetImpulse(cpConstraint *constraint)
172 return constraint->klass->getImpulse(constraint);