Debian Codegraph @

src/cpPinJoint.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(b262349a1c295dfc).(cpPinJointcxx . . $ cpPinJoint# *joint, cpFloatcxx . . $ cpFloat# dt)
26 {
27 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpPinJoint#constraint..acxx . . $ cpConstraint#a.;
28 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpPinJoint#constraint..bcxx . . $ cpConstraint#b.;
29
30 joint->r1cxx . . $ cpPinJoint#r1. = cpTransformVectcxx . . $ cpTransformVect(7fc9e234cc6e750a).(a->transformcxx . . $ cpBody#transform., cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(joint->anchorAcxx . . $ cpPinJoint#anchorA., a->cogcxx . . $ cpBody#cog.));
31 joint->r2cxx . . $ cpPinJoint#r2. = cpTransformVectcxx . . $ cpTransformVect(7fc9e234cc6e750a).(b->transformcxx . . $ cpBody#transform., cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(joint->anchorBcxx . . $ cpPinJoint#anchorB., b->cogcxx . . $ cpBody#cog.));
32
33 cpVectcxx . . $ cpVect# delta = cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(b->pcxx . . $ cpBody#p., joint->r2cxx . . $ cpPinJoint#r2.), cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(a->pcxx . . $ cpBody#p., joint->r1cxx . . $ cpPinJoint#r1.));
34 cpFloatcxx . . $ cpFloat# dist = cpvlengthcxx . . $ cpvlength(c4ef53c170268e01).(delta);
35 joint->ncxx . . $ cpPinJoint#n. = cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(delta, 1.0f/(dist ? dist : (cpFloatcxx . . $ cpFloat#)INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!));
36
37 // calculate mass normal
38 joint->nMasscxx . . $ cpPinJoint#nMass. = 1.0f/k_scalarcxx . . $ k_scalar(d97a6b5999e6b615).(a, b, joint->r1cxx . . $ cpPinJoint#r1., joint->r2cxx . . $ cpPinJoint#r2., joint->ncxx . . $ cpPinJoint#n.);
39
40 // calculate bias velocity
41 cpFloatcxx . . $ cpFloat# maxBias = joint->constraintcxx . . $ cpPinJoint#constraint..maxBiascxx . . $ cpConstraint#maxBias.;
42 joint->biascxx . . $ cpPinJoint#bias. = cpfclampcxx . . $ cpfclamp(7678bba071383ab).(-bias_coefcxx . . $ bias_coef(d8e7e0733fa41c87).(joint->constraintcxx . . $ cpPinJoint#constraint..errorBiascxx . . $ cpConstraint#errorBias., dt)*(dist - joint->distcxx . . $ cpPinJoint#dist.)/dt, -maxBias, maxBias);
43 }
44
45 static void
46 applyCachedImpulsecxx . . $ applyCachedImpulse(b262349a1c295dfc).(cpPinJointcxx . . $ cpPinJoint# *joint, cpFloatcxx . . $ cpFloat# dt_coef)
47 {
48 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpPinJoint#constraint..acxx . . $ cpConstraint#a.;
49 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpPinJoint#constraint..bcxx . . $ cpConstraint#b.;
50
51 cpVectcxx . . $ cpVect# j = cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(joint->ncxx . . $ cpPinJoint#n., joint->jnAcccxx . . $ cpPinJoint#jnAcc.*dt_coef);
52 apply_impulsescxx . . $ apply_impulses(db940cdf68a6ac72).(a, b, joint->r1cxx . . $ cpPinJoint#r1., joint->r2cxx . . $ cpPinJoint#r2., j);
53 }
54
55 static void
56 applyImpulsecxx . . $ applyImpulse(b262349a1c295dfc).(cpPinJointcxx . . $ cpPinJoint# *joint, cpFloatcxx . . $ cpFloat# dt)
57 {
58 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpPinJoint#constraint..acxx . . $ cpConstraint#a.;
59 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpPinJoint#constraint..bcxx . . $ cpConstraint#b.;
60 cpVectcxx . . $ cpVect# n = joint->ncxx . . $ cpPinJoint#n.;
61
62 // compute relative velocity
63 cpFloatcxx . . $ cpFloat# vrn = normal_relative_velocitycxx . . $ normal_relative_velocity(d97a6b5999e6b615).(a, b, joint->r1cxx . . $ cpPinJoint#r1., joint->r2cxx . . $ cpPinJoint#r2., n);
64
65 cpFloatcxx . . $ cpFloat# jnMax = joint->constraintcxx . . $ cpPinJoint#constraint..maxForcecxx . . $ cpConstraint#maxForce.*dt;
66
67 // compute normal impulse
68 cpFloatcxx . . $ cpFloat# jn = (joint->biascxx . . $ cpPinJoint#bias. - vrn)*joint->nMasscxx . . $ cpPinJoint#nMass.;
69 cpFloatcxx . . $ cpFloat# jnOld = joint->jnAcccxx . . $ cpPinJoint#jnAcc.;
70 joint->jnAcccxx . . $ cpPinJoint#jnAcc. = cpfclampcxx . . $ cpfclamp(7678bba071383ab).(jnOld + jn, -jnMax, jnMax);
71 jn = joint->jnAcccxx . . $ cpPinJoint#jnAcc. - jnOld;
72
73 // apply impulse
74 apply_impulsescxx . . $ apply_impulses(db940cdf68a6ac72).(a, b, joint->r1cxx . . $ cpPinJoint#r1., joint->r2cxx . . $ cpPinJoint#r2., cpvmultcxx . . $ cpvmult(f5cc44da17d64838).(n, jn));
75 }
76
77 static cpFloatcxx . . $ cpFloat#
78 getImpulsecxx . . $ getImpulse(d9dec54f5056c0f2).(cpPinJointcxx . . $ cpPinJoint# *joint)
79 {
80 return cpfabscxx . . $ cpfabs(447c67c6676f75c3).(joint->jnAcccxx . . $ cpPinJoint#jnAcc.);
81 }
82
83 static const cpConstraintClasscxx . . $ cpConstraintClass# klasscxx . . $ klass. = {
84 (cpConstraintPreStepImplcxx . . $ cpConstraintPreStepImpl#)preStepcxx . . $ preStep(b262349a1c295dfc).,
85 (cpConstraintApplyCachedImpulseImplcxx . . $ cpConstraintApplyCachedImpulseImpl#)applyCachedImpulsecxx . . $ applyCachedImpulse(b262349a1c295dfc).,
86 (cpConstraintApplyImpulseImplcxx . . $ cpConstraintApplyImpulseImpl#)applyImpulsecxx . . $ applyImpulse(b262349a1c295dfc).,
87 (cpConstraintGetImpulseImplcxx . . $ cpConstraintGetImpulseImpl#)getImpulsecxx . . $ getImpulse(d9dec54f5056c0f2).,
88 };
89
90
91 cpPinJointcxx . . $ cpPinJoint# *
92 cpPinJointAlloccxx . . $ cpPinJointAlloc(ac7a0be7ad54e6e3).(void)
93 {
94 return (cpPinJointcxx . . $ cpPinJoint# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, sizeof(cpPinJointcxx . . $ cpPinJoint#));
95 }
96
97 cpPinJointcxx . . $ cpPinJoint# *
98 cpPinJointInitcxx . . $ cpPinJointInit(84ebac0c56dbf1).(cpPinJointcxx . . $ cpPinJoint# *joint, cpBodycxx . . $ cpBody# *a, cpBodycxx . . $ cpBody# *b, cpVectcxx . . $ cpVect# anchorA, cpVectcxx . . $ cpVect# anchorB)
99 {
100 cpConstraintInitcxx . . $ cpConstraintInit(540fb6eaa94f170).((cpConstraintcxx . . $ cpConstraint# *)joint, &klasscxx . . $ klass., a, b);
101
102 joint->anchorAcxx . . $ cpPinJoint#anchorA. = anchorA;
103 joint->anchorBcxx . . $ cpPinJoint#anchorB. = anchorB;
104
105 // STATIC_BODY_CHECK
106 cpVectcxx . . $ cpVect# p1 = (a ? cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(a->transformcxx . . $ cpBody#transform., anchorA) : anchorA);
107 cpVectcxx . . $ cpVect# p2 = (b ? cpTransformPointcxx . . $ cpTransformPoint(7fc9e234cc6e750a).(b->transformcxx . . $ cpBody#transform., anchorB) : anchorB);
108 joint->distcxx . . $ cpPinJoint#dist. = cpvlengthcxx . . $ cpvlength(c4ef53c170268e01).(cpvsubcxx . . $ cpvsub(47eb3f105675e23c).(p2, p1));
109
110 cpAssertWarncxx . . $ `include/chipmunk/chipmunk.h:50:10`!(joint->dist > 0.0, "You created a 0 length pin joint. A pivot joint will be much more stable.");
111
112 joint->jnAcccxx . . $ cpPinJoint#jnAcc. = 0.0f;
113
114 return joint;
115 }
116
117 cpConstraintcxx . . $ cpConstraint# *
118 cpPinJointNewcxx . . $ cpPinJointNew(74f6d8fa0e302020).(cpBodycxx . . $ cpBody# *a, cpBodycxx . . $ cpBody# *b, cpVectcxx . . $ cpVect# anchorA, cpVectcxx . . $ cpVect# anchorB)
119 {
120 return (cpConstraintcxx . . $ cpConstraint# *)cpPinJointInitcxx . . $ cpPinJointInit(84ebac0c56dbf1).(cpPinJointAlloccxx . . $ cpPinJointAlloc(ac7a0be7ad54e6e3).(), a, b, anchorA, anchorB);
121 }
122
123 cpBoolcxx . . $ cpBool#
124 cpConstraintIsPinJointcxx . . $ cpConstraintIsPinJoint(ca4e56e976f68364).(const cpConstraintcxx . . $ cpConstraint# *constraint)
125 {
126 return (constraint->klasscxx . . $ cpConstraint#klass. == &klasscxx . . $ klass.);
127 }
128
129 cpVectcxx . . $ cpVect#
130 cpPinJointGetAnchorAcxx . . $ cpPinJointGetAnchorA(faf0cf136ff270ad).(const cpConstraintcxx . . $ cpConstraint# *constraint)
131 {
132 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsPinJoint(constraint), "Constraint is not a pin joint.");
133 return ((cpPinJointcxx . . $ cpPinJoint# *)constraint)->anchorAcxx . . $ cpPinJoint#anchorA.;
134 }
135
136 void
137 cpPinJointSetAnchorAcxx . . $ cpPinJointSetAnchorA(dec37a28d0c61656).(cpConstraintcxx . . $ cpConstraint# *constraint, cpVectcxx . . $ cpVect# anchorA)
138 {
139 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsPinJoint(constraint), "Constraint is not a pin joint.");
140 cpConstraintActivateBodiescxx . . $ cpConstraintActivateBodies(ce362f6e378064c6).(constraint);
141 ((cpPinJointcxx . . $ cpPinJoint# *)constraint)->anchorAcxx . . $ cpPinJoint#anchorA. = anchorA;
142 }
143
144 cpVectcxx . . $ cpVect#
145 cpPinJointGetAnchorBcxx . . $ cpPinJointGetAnchorB(faf0cf136ff270ad).(const cpConstraintcxx . . $ cpConstraint# *constraint)
146 {
147 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsPinJoint(constraint), "Constraint is not a pin joint.");
148 return ((cpPinJointcxx . . $ cpPinJoint# *)constraint)->anchorBcxx . . $ cpPinJoint#anchorB.;
149 }
150
151 void
152 cpPinJointSetAnchorBcxx . . $ cpPinJointSetAnchorB(dec37a28d0c61656).(cpConstraintcxx . . $ cpConstraint# *constraint, cpVectcxx . . $ cpVect# anchorB)
153 {
154 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsPinJoint(constraint), "Constraint is not a pin joint.");
155 cpConstraintActivateBodiescxx . . $ cpConstraintActivateBodies(ce362f6e378064c6).(constraint);
156 ((cpPinJointcxx . . $ cpPinJoint# *)constraint)->anchorBcxx . . $ cpPinJoint#anchorB. = anchorB;
157 }
158
159 cpFloatcxx . . $ cpFloat#
160 cpPinJointGetDistcxx . . $ cpPinJointGetDist(9c3ac5f8d34d584e).(const cpConstraintcxx . . $ cpConstraint# *constraint)
161 {
162 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsPinJoint(constraint), "Constraint is not a pin joint.");
163 return ((cpPinJointcxx . . $ cpPinJoint# *)constraint)->distcxx . . $ cpPinJoint#dist.;
164 }
165
166 void
167 cpPinJointSetDistcxx . . $ cpPinJointSetDist(dfce55250ba9e4fa).(cpConstraintcxx . . $ cpConstraint# *constraint, cpFloatcxx . . $ cpFloat# dist)
168 {
169 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsPinJoint(constraint), "Constraint is not a pin joint.");
170 cpConstraintActivateBodiescxx . . $ cpConstraintActivateBodies(ce362f6e378064c6).(constraint);
171 ((cpPinJointcxx . . $ cpPinJoint# *)constraint)->distcxx . . $ cpPinJoint#dist. = dist;
172 }