Debian Codegraph @

src/cpRotaryLimitJoint.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"cxx . . $ `<file>/include/chipmunk/chipmunk_private.h`/
23
24 static void
25 preStepcxx . . $ preStep(62760de1fc819a91).(cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *joint, cpFloatcxx . . $ cpFloat# dt)
26 {
27 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..acxx . . $ cpConstraint#a.;
28 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..bcxx . . $ cpConstraint#b.;
29
30 cpFloatcxx . . $ cpFloat# dist = b->acxx . . $ cpBody#a. - a->acxx . . $ cpBody#a.;
31 cpFloatcxx . . $ cpFloat# pdist = 0.0f;
32 if(dist > joint->maxcxx . . $ cpRotaryLimitJoint#max.) {
33 pdist = joint->maxcxx . . $ cpRotaryLimitJoint#max. - dist;
34 } else if(dist < joint->mincxx . . $ cpRotaryLimitJoint#min.) {
35 pdist = joint->mincxx . . $ cpRotaryLimitJoint#min. - dist;
36 }
37
38 // calculate moment of inertia coefficient.
39 joint->iSumcxx . . $ cpRotaryLimitJoint#iSum. = 1.0f/(a->i_invcxx . . $ cpBody#i_inv. + b->i_invcxx . . $ cpBody#i_inv.);
40
41 // calculate bias velocity
42 cpFloatcxx . . $ cpFloat# maxBias = joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..maxBiascxx . . $ cpConstraint#maxBias.;
43 joint->biascxx . . $ cpRotaryLimitJoint#bias. = cpfclampcxx . . $ cpfclamp(7678bba071383ab).(-bias_coefcxx . . $ bias_coef(d8e7e0733fa41c87).(joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..errorBiascxx . . $ cpConstraint#errorBias., dt)*pdist/dt, -maxBias, maxBias);
44
45 // If the bias is 0, the joint is not at a limit. Reset the impulse.
46 if(!joint->biascxx . . $ cpRotaryLimitJoint#bias.) joint->jAcccxx . . $ cpRotaryLimitJoint#jAcc. = 0.0f;
47 }
48
49 static void
50 applyCachedImpulsecxx . . $ applyCachedImpulse(62760de1fc819a91).(cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *joint, cpFloatcxx . . $ cpFloat# dt_coef)
51 {
52 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..acxx . . $ cpConstraint#a.;
53 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..bcxx . . $ cpConstraint#b.;
54
55 cpFloatcxx . . $ cpFloat# j = joint->jAcccxx . . $ cpRotaryLimitJoint#jAcc.*dt_coef;
56 a->wcxx . . $ cpBody#w. -= j*a->i_invcxx . . $ cpBody#i_inv.;
57 b->wcxx . . $ cpBody#w. += j*b->i_invcxx . . $ cpBody#i_inv.;
58 }
59
60 static void
61 applyImpulsecxx . . $ applyImpulse(62760de1fc819a91).(cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *joint, cpFloatcxx . . $ cpFloat# dt)
62 {
63 if(!joint->biascxx . . $ cpRotaryLimitJoint#bias.) return; // early exit
64
65 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..acxx . . $ cpConstraint#a.;
66 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..bcxx . . $ cpConstraint#b.;
67
68 // compute relative rotational velocity
69 cpFloatcxx . . $ cpFloat# wr = b->wcxx . . $ cpBody#w. - a->wcxx . . $ cpBody#w.;
70
71 cpFloatcxx . . $ cpFloat# jMax = joint->constraintcxx . . $ cpRotaryLimitJoint#constraint..maxForcecxx . . $ cpConstraint#maxForce.*dt;
72
73 // compute normal impulse
74 cpFloatcxx . . $ cpFloat# j = -(joint->biascxx . . $ cpRotaryLimitJoint#bias. + wr)*joint->iSumcxx . . $ cpRotaryLimitJoint#iSum.;
75 cpFloatcxx . . $ cpFloat# jOld = joint->jAcccxx . . $ cpRotaryLimitJoint#jAcc.;
76 if(joint->biascxx . . $ cpRotaryLimitJoint#bias. < 0.0f){
77 joint->jAcccxx . . $ cpRotaryLimitJoint#jAcc. = cpfclampcxx . . $ cpfclamp(7678bba071383ab).(jOld + j, 0.0f, jMax);
78 } else {
79 joint->jAcccxx . . $ cpRotaryLimitJoint#jAcc. = cpfclampcxx . . $ cpfclamp(7678bba071383ab).(jOld + j, -jMax, 0.0f);
80 }
81 j = joint->jAcccxx . . $ cpRotaryLimitJoint#jAcc. - jOld;
82
83 // apply impulse
84 a->wcxx . . $ cpBody#w. -= j*a->i_invcxx . . $ cpBody#i_inv.;
85 b->wcxx . . $ cpBody#w. += j*b->i_invcxx . . $ cpBody#i_inv.;
86 }
87
88 static cpFloatcxx . . $ cpFloat#
89 getImpulsecxx . . $ getImpulse(f61404198a907524).(cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *joint)
90 {
91 return cpfabscxx . . $ cpfabs(447c67c6676f75c3).(joint->jAcccxx . . $ cpRotaryLimitJoint#jAcc.);
92 }
93
94 static const cpConstraintClasscxx . . $ cpConstraintClass# klasscxx . . $ klass. = {
95 (cpConstraintPreStepImplcxx . . $ cpConstraintPreStepImpl#)preStepcxx . . $ preStep(62760de1fc819a91).,
96 (cpConstraintApplyCachedImpulseImplcxx . . $ cpConstraintApplyCachedImpulseImpl#)applyCachedImpulsecxx . . $ applyCachedImpulse(62760de1fc819a91).,
97 (cpConstraintApplyImpulseImplcxx . . $ cpConstraintApplyImpulseImpl#)applyImpulsecxx . . $ applyImpulse(62760de1fc819a91).,
98 (cpConstraintGetImpulseImplcxx . . $ cpConstraintGetImpulseImpl#)getImpulsecxx . . $ getImpulse(f61404198a907524).,
99 };
100
101 cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *
102 cpRotaryLimitJointAlloccxx . . $ cpRotaryLimitJointAlloc(cafc89440707b089).(void)
103 {
104 return (cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, sizeof(cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint#));
105 }
106
107 cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *
108 cpRotaryLimitJointInitcxx . . $ cpRotaryLimitJointInit(9caeaaa981fc55d8).(cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *joint, cpBodycxx . . $ cpBody# *a, cpBodycxx . . $ cpBody# *b, cpFloatcxx . . $ cpFloat# min, cpFloatcxx . . $ cpFloat# max)
109 {
110 cpConstraintInitcxx . . $ cpConstraintInit(540fb6eaa94f170).((cpConstraintcxx . . $ cpConstraint# *)joint, &klasscxx . . $ klass., a, b);
111
112 joint->mincxx . . $ cpRotaryLimitJoint#min. = min;
113 joint->maxcxx . . $ cpRotaryLimitJoint#max. = max;
114
115 joint->jAcccxx . . $ cpRotaryLimitJoint#jAcc. = 0.0f;
116
117 return joint;
118 }
119
120 cpConstraintcxx . . $ cpConstraint# *
121 cpRotaryLimitJointNewcxx . . $ cpRotaryLimitJointNew(d029de5d93e4cb4a).(cpBodycxx . . $ cpBody# *a, cpBodycxx . . $ cpBody# *b, cpFloatcxx . . $ cpFloat# min, cpFloatcxx . . $ cpFloat# max)
122 {
123 return (cpConstraintcxx . . $ cpConstraint# *)cpRotaryLimitJointInitcxx . . $ cpRotaryLimitJointInit(9caeaaa981fc55d8).(cpRotaryLimitJointAlloccxx . . $ cpRotaryLimitJointAlloc(cafc89440707b089).(), a, b, min, max);
124 }
125
126 cpBoolcxx . . $ cpBool#
127 cpConstraintIsRotaryLimitJointcxx . . $ cpConstraintIsRotaryLimitJoint(ca4e56e976f68364).(const cpConstraintcxx . . $ cpConstraint# *constraint)
128 {
129 return (constraint->klasscxx . . $ cpConstraint#klass. == &klasscxx . . $ klass.);
130 }
131
132 cpFloatcxx . . $ cpFloat#
133 cpRotaryLimitJointGetMincxx . . $ cpRotaryLimitJointGetMin(9c3ac5f8d34d584e).(const cpConstraintcxx . . $ cpConstraint# *constraint)
134 {
135 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsRotaryLimitJoint(constraint), "Constraint is not a rotary limit joint.");
136 return ((cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *)constraint)->mincxx . . $ cpRotaryLimitJoint#min.;
137 }
138
139 void
140 cpRotaryLimitJointSetMincxx . . $ cpRotaryLimitJointSetMin(dfce55250ba9e4fa).(cpConstraintcxx . . $ cpConstraint# *constraint, cpFloatcxx . . $ cpFloat# min)
141 {
142 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsRotaryLimitJoint(constraint), "Constraint is not a rotary limit joint.");
143 cpConstraintActivateBodiescxx . . $ cpConstraintActivateBodies(ce362f6e378064c6).(constraint);
144 ((cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *)constraint)->mincxx . . $ cpRotaryLimitJoint#min. = min;
145 }
146
147 cpFloatcxx . . $ cpFloat#
148 cpRotaryLimitJointGetMaxcxx . . $ cpRotaryLimitJointGetMax(9c3ac5f8d34d584e).(const cpConstraintcxx . . $ cpConstraint# *constraint)
149 {
150 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsRotaryLimitJoint(constraint), "Constraint is not a rotary limit joint.");
151 return ((cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *)constraint)->maxcxx . . $ cpRotaryLimitJoint#max.;
152 }
153
154 void
155 cpRotaryLimitJointSetMaxcxx . . $ cpRotaryLimitJointSetMax(dfce55250ba9e4fa).(cpConstraintcxx . . $ cpConstraint# *constraint, cpFloatcxx . . $ cpFloat# max)
156 {
157 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsRotaryLimitJoint(constraint), "Constraint is not a rotary limit joint.");
158 cpConstraintActivateBodiescxx . . $ cpConstraintActivateBodies(ce362f6e378064c6).(constraint);
159 ((cpRotaryLimitJointcxx . . $ cpRotaryLimitJoint# *)constraint)->maxcxx . . $ cpRotaryLimitJoint#max. = max;
160 }