Debian Codegraph @

src/cpConstraint.c

raw symbols SCIP
1 /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
2 *
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:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
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
19 * SOFTWARE.
20 */
21
22 #include "chipmunk/chipmunk_private.h"
23
24 // TODO: Comment me!
25
26 void cpConstraintDestroy(cpConstraint *constraint){}
27
28 void
29 cpConstraintFree(cpConstraint *constraint)
30 {
31 if(constraint){
32 cpConstraintDestroy(constraint);
33 cpfree(constraint);
34 }
35 }
36
37 void
38 cpConstraintInit(cpConstraint *constraint, const cpConstraintClass *klass, cpBody *a, cpBody *b)
39 {
40 constraint->klass = klass;
41
42 constraint->a = a;
43 constraint->b = b;
44 constraint->space = NULL;
45
46 constraint->next_a = NULL;
47 constraint->next_b = NULL;
48
49 constraint->maxForce = (cpFloat)INFINITY;
50 constraint->errorBias = cpfpow(1.0f - 0.1f, 60.0f);
51 constraint->maxBias = (cpFloat)INFINITY;
52
53 constraint->collideBodies = cpTrue;
54
55 constraint->preSolve = NULL;
56 constraint->postSolve = NULL;
57 }
58
59 cpSpace *
60 cpConstraintGetSpace(const cpConstraint *constraint)
61 {
62 return constraint->space;
63 }
64
65 cpBody *
66 cpConstraintGetBodyA(const cpConstraint *constraint)
67 {
68 return constraint->a;
69 }
70
71 cpBody *
72 cpConstraintGetBodyB(const cpConstraint *constraint)
73 {
74 return constraint->b;
75 }
76
77 cpFloat
78 cpConstraintGetMaxForce(const cpConstraint *constraint)
79 {
80 return constraint->maxForce;
81 }
82
83 void
84 cpConstraintSetMaxForce(cpConstraint *constraint, cpFloat maxForce)
85 {
86 cpAssertHard(maxForce >= 0.0f, "maxForce must be positive.");
87 cpConstraintActivateBodies(constraint);
88 constraint->maxForce = maxForce;
89 }
90
91 cpFloat
92 cpConstraintGetErrorBias(const cpConstraint *constraint)
93 {
94 return constraint->errorBias;
95 }
96
97 void
98 cpConstraintSetErrorBias(cpConstraint *constraint, cpFloat errorBias)
99 {
100 cpAssertHard(errorBias >= 0.0f, "errorBias must be positive.");
101 cpConstraintActivateBodies(constraint);
102 constraint->errorBias = errorBias;
103 }
104
105 cpFloat
106 cpConstraintGetMaxBias(const cpConstraint *constraint)
107 {
108 return constraint->maxBias;
109 }
110
111 void
112 cpConstraintSetMaxBias(cpConstraint *constraint, cpFloat maxBias)
113 {
114 cpAssertHard(maxBias >= 0.0f, "maxBias must be positive.");
115 cpConstraintActivateBodies(constraint);
116 constraint->maxBias = maxBias;
117 }
118
119 cpBool
120 cpConstraintGetCollideBodies(const cpConstraint *constraint)
121 {
122 return constraint->collideBodies;
123 }
124
125 void
126 cpConstraintSetCollideBodies(cpConstraint *constraint, cpBool collideBodies)
127 {
128 cpConstraintActivateBodies(constraint);
129 constraint->collideBodies = collideBodies;
130 }
131
132 cpConstraintPreSolveFunc
133 cpConstraintGetPreSolveFunc(const cpConstraint *constraint)
134 {
135 return constraint->preSolve;
136 }
137
138 void
139 cpConstraintSetPreSolveFunc(cpConstraint *constraint, cpConstraintPreSolveFunc preSolveFunc)
140 {
141 constraint->preSolve = preSolveFunc;
142 }
143
144 cpConstraintPostSolveFunc
145 cpConstraintGetPostSolveFunc(const cpConstraint *constraint)
146 {
147 return constraint->postSolve;
148 }
149
150 void
151 cpConstraintSetPostSolveFunc(cpConstraint *constraint, cpConstraintPostSolveFunc postSolveFunc)
152 {
153 constraint->postSolve = postSolveFunc;
154 }
155
156 cpDataPointer
157 cpConstraintGetUserData(const cpConstraint *constraint)
158 {
159 return constraint->userData;
160 }
161
162 void
163 cpConstraintSetUserData(cpConstraint *constraint, cpDataPointer userData)
164 {
165 constraint->userData = userData;
166 }
167
168
169 cpFloat
170 cpConstraintGetImpulse(cpConstraint *constraint)
171 {
172 return constraint->klass->getImpulse(constraint);
173 }