Debian Codegraph @

src/cpSimpleMotor.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(a299d8ce07cd59f0).(cpSimpleMotorcxx . . $ cpSimpleMotor# *joint, cpFloatcxx . . $ cpFloat# dt)
26 {
27 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpSimpleMotor#constraint..acxx . . $ cpConstraint#a.;
28 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpSimpleMotor#constraint..bcxx . . $ cpConstraint#b.;
29
30 // calculate moment of inertia coefficient.
31 joint->iSumcxx . . $ cpSimpleMotor#iSum. = 1.0f/(a->i_invcxx . . $ cpBody#i_inv. + b->i_invcxx . . $ cpBody#i_inv.);
32 }
33
34 static void
35 applyCachedImpulsecxx . . $ applyCachedImpulse(a299d8ce07cd59f0).(cpSimpleMotorcxx . . $ cpSimpleMotor# *joint, cpFloatcxx . . $ cpFloat# dt_coef)
36 {
37 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpSimpleMotor#constraint..acxx . . $ cpConstraint#a.;
38 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpSimpleMotor#constraint..bcxx . . $ cpConstraint#b.;
39
40 cpFloatcxx . . $ cpFloat# j = joint->jAcccxx . . $ cpSimpleMotor#jAcc.*dt_coef;
41 a->wcxx . . $ cpBody#w. -= j*a->i_invcxx . . $ cpBody#i_inv.;
42 b->wcxx . . $ cpBody#w. += j*b->i_invcxx . . $ cpBody#i_inv.;
43 }
44
45 static void
46 applyImpulsecxx . . $ applyImpulse(a299d8ce07cd59f0).(cpSimpleMotorcxx . . $ cpSimpleMotor# *joint, cpFloatcxx . . $ cpFloat# dt)
47 {
48 cpBodycxx . . $ cpBody# *a = joint->constraintcxx . . $ cpSimpleMotor#constraint..acxx . . $ cpConstraint#a.;
49 cpBodycxx . . $ cpBody# *b = joint->constraintcxx . . $ cpSimpleMotor#constraint..bcxx . . $ cpConstraint#b.;
50
51 // compute relative rotational velocity
52 cpFloatcxx . . $ cpFloat# wr = b->wcxx . . $ cpBody#w. - a->wcxx . . $ cpBody#w. + joint->ratecxx . . $ cpSimpleMotor#rate.;
53
54 cpFloatcxx . . $ cpFloat# jMax = joint->constraintcxx . . $ cpSimpleMotor#constraint..maxForcecxx . . $ cpConstraint#maxForce.*dt;
55
56 // compute normal impulse
57 cpFloatcxx . . $ cpFloat# j = -wr*joint->iSumcxx . . $ cpSimpleMotor#iSum.;
58 cpFloatcxx . . $ cpFloat# jOld = joint->jAcccxx . . $ cpSimpleMotor#jAcc.;
59 joint->jAcccxx . . $ cpSimpleMotor#jAcc. = cpfclampcxx . . $ cpfclamp(7678bba071383ab).(jOld + j, -jMax, jMax);
60 j = joint->jAcccxx . . $ cpSimpleMotor#jAcc. - jOld;
61
62 // apply impulse
63 a->wcxx . . $ cpBody#w. -= j*a->i_invcxx . . $ cpBody#i_inv.;
64 b->wcxx . . $ cpBody#w. += j*b->i_invcxx . . $ cpBody#i_inv.;
65 }
66
67 static cpFloatcxx . . $ cpFloat#
68 getImpulsecxx . . $ getImpulse(f34d55023f8735d5).(cpSimpleMotorcxx . . $ cpSimpleMotor# *joint)
69 {
70 return cpfabscxx . . $ cpfabs(447c67c6676f75c3).(joint->jAcccxx . . $ cpSimpleMotor#jAcc.);
71 }
72
73 static const cpConstraintClasscxx . . $ cpConstraintClass# klasscxx . . $ klass. = {
74 (cpConstraintPreStepImplcxx . . $ cpConstraintPreStepImpl#)preStepcxx . . $ preStep(a299d8ce07cd59f0).,
75 (cpConstraintApplyCachedImpulseImplcxx . . $ cpConstraintApplyCachedImpulseImpl#)applyCachedImpulsecxx . . $ applyCachedImpulse(a299d8ce07cd59f0).,
76 (cpConstraintApplyImpulseImplcxx . . $ cpConstraintApplyImpulseImpl#)applyImpulsecxx . . $ applyImpulse(a299d8ce07cd59f0).,
77 (cpConstraintGetImpulseImplcxx . . $ cpConstraintGetImpulseImpl#)getImpulsecxx . . $ getImpulse(f34d55023f8735d5).,
78 };
79
80 cpSimpleMotorcxx . . $ cpSimpleMotor# *
81 cpSimpleMotorAlloccxx . . $ cpSimpleMotorAlloc(f3110f881e8a7b52).(void)
82 {
83 return (cpSimpleMotorcxx . . $ cpSimpleMotor# *)cpcalloccxx . . $ `include/chipmunk/chipmunk.h:72:10`!(1, sizeof(cpSimpleMotorcxx . . $ cpSimpleMotor#));
84 }
85
86 cpSimpleMotorcxx . . $ cpSimpleMotor# *
87 cpSimpleMotorInitcxx . . $ cpSimpleMotorInit(ea315103d189713d).(cpSimpleMotorcxx . . $ cpSimpleMotor# *joint, cpBodycxx . . $ cpBody# *a, cpBodycxx . . $ cpBody# *b, cpFloatcxx . . $ cpFloat# rate)
88 {
89 cpConstraintInitcxx . . $ cpConstraintInit(540fb6eaa94f170).((cpConstraintcxx . . $ cpConstraint# *)joint, &klasscxx . . $ klass., a, b);
90
91 joint->ratecxx . . $ cpSimpleMotor#rate. = rate;
92
93 joint->jAcccxx . . $ cpSimpleMotor#jAcc. = 0.0f;
94
95 return joint;
96 }
97
98 cpConstraintcxx . . $ cpConstraint# *
99 cpSimpleMotorNewcxx . . $ cpSimpleMotorNew(fc786efe5abab4f7).(cpBodycxx . . $ cpBody# *a, cpBodycxx . . $ cpBody# *b, cpFloatcxx . . $ cpFloat# rate)
100 {
101 return (cpConstraintcxx . . $ cpConstraint# *)cpSimpleMotorInitcxx . . $ cpSimpleMotorInit(ea315103d189713d).(cpSimpleMotorAlloccxx . . $ cpSimpleMotorAlloc(f3110f881e8a7b52).(), a, b, rate);
102 }
103
104 cpBoolcxx . . $ cpBool#
105 cpConstraintIsSimpleMotorcxx . . $ cpConstraintIsSimpleMotor(ca4e56e976f68364).(const cpConstraintcxx . . $ cpConstraint# *constraint)
106 {
107 return (constraint->klasscxx . . $ cpConstraint#klass. == &klasscxx . . $ klass.);
108 }
109
110 cpFloatcxx . . $ cpFloat#
111 cpSimpleMotorGetRatecxx . . $ cpSimpleMotorGetRate(9c3ac5f8d34d584e).(const cpConstraintcxx . . $ cpConstraint# *constraint)
112 {
113 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsSimpleMotor(constraint), "Constraint is not a pin joint.");
114 return ((cpSimpleMotorcxx . . $ cpSimpleMotor# *)constraint)->ratecxx . . $ cpSimpleMotor#rate.;
115 }
116
117 void
118 cpSimpleMotorSetRatecxx . . $ cpSimpleMotorSetRate(dfce55250ba9e4fa).(cpConstraintcxx . . $ cpConstraint# *constraint, cpFloatcxx . . $ cpFloat# rate)
119 {
120 cpAssertHardcxx . . $ `include/chipmunk/chipmunk.h:58:9`!(cpConstraintIsSimpleMotor(constraint), "Constraint is not a pin joint.");
121 cpConstraintActivateBodiescxx . . $ cpConstraintActivateBodies(ce362f6e378064c6).(constraint);
122 ((cpSimpleMotorcxx . . $ cpSimpleMotor# *)constraint)->ratecxx . . $ cpSimpleMotor#rate. = rate;
123 }