| 1 | /* Copyright (c) 2007 Scott Lembcke |
| 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.h"cxx . . $ `<file>/include/chipmunk/chipmunk.h`/ |
| 23 | #include "ChipmunkDemo.h"cxx . . $ `<file>/demo/ChipmunkDemo.h`/ |
| 24 | |
| 25 | static cpConstraintcxx . . $ cpConstraint# *motorcxx . . $ motor.; |
| 26 | |
| 27 | #define numBallscxx . . $ `demo/Pump.c:27:9`! 5 |
| 28 | static cpBodycxx . . $ cpBody# *ballscxx . . $ balls.[numBallscxx . . $ `demo/Pump.c:27:9`!]; |
| 29 | |
| 30 | static void |
| 31 | updatecxx . . $ update(fa66a0a48611083e).(cpSpacecxx . . $ cpSpace# *space, double dt) |
| 32 | { |
| 33 | cpFloatcxx . . $ cpFloat# coef = (2.0f + ChipmunkDemoKeyboardcxx . . $ ChipmunkDemoKeyboard..ycxx . . $ cpVect#y.)/3.0f; |
| 34 | cpFloatcxx . . $ cpFloat# rate = ChipmunkDemoKeyboardcxx . . $ ChipmunkDemoKeyboard..xcxx . . $ cpVect#x.*30.0f*coef; |
| 35 | |
| 36 | cpSimpleMotorSetRatecxx . . $ cpSimpleMotorSetRate(dfce55250ba9e4fa).(motorcxx . . $ motor., rate); |
| 37 | cpConstraintSetMaxForcecxx . . $ cpConstraintSetMaxForce(dfce55250ba9e4fa).(motorcxx . . $ motor., rate ? 1000000.0f : 0.0f); |
| 38 | |
| 39 | cpSpaceStepcxx . . $ cpSpaceStep(fa66a0a48611083e).(space, dt); |
| 40 | |
| 41 | for(int i=0; i<numBallscxx . . $ `demo/Pump.c:27:9`!; i++){ |
| 42 | cpBodycxx . . $ cpBody# *ball = ballscxx . . $ balls.[i]; |
| 43 | cpVectcxx . . $ cpVect# pos = cpBodyGetPositioncxx . . $ cpBodyGetPosition(2e8d436bcfa5d74b).(ball); |
| 44 | |
| 45 | if(pos.xcxx . . $ cpVect#x. > 320.0f){ |
| 46 | cpBodySetVelocitycxx . . $ cpBodySetVelocity(864e17bcbe059b08).(ball, cpvzerocxx . . $ cpvzero.); |
| 47 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(ball, cpvcxx . . $ cpv(3142d57d978b2176).(-224.0f, 200.0f)); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | static cpBodycxx . . $ cpBody# * |
| 53 | add_ballcxx . . $ add_ball(b314a1699273f84).(cpSpacecxx . . $ cpSpace# *space, cpVectcxx . . $ cpVect# pos) |
| 54 | { |
| 55 | cpBodycxx . . $ cpBody# *body = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(1.0f, cpMomentForCirclecxx . . $ cpMomentForCircle(a539e2d95614f770).(1.0f, 30, 0, cpvzerocxx . . $ cpvzero.))); |
| 56 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(body, pos); |
| 57 | |
| 58 | cpShapecxx . . $ cpShape# *shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpCircleShapeNewcxx . . $ cpCircleShapeNew(e5e4e3a52c89533b).(body, 30, cpvzerocxx . . $ cpvzero.)); |
| 59 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 60 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 61 | |
| 62 | return body; |
| 63 | } |
| 64 | |
| 65 | static cpSpacecxx . . $ cpSpace# * |
| 66 | initcxx . . $ init(1f0082e822a7ce76).(void) |
| 67 | { |
| 68 | ChipmunkDemoMessageStringcxx . . $ ChipmunkDemoMessageString. = "Use the arrow keys to control the machine."; |
| 69 | |
| 70 | cpSpacecxx . . $ cpSpace# *space = cpSpaceNewcxx . . $ cpSpaceNew(1f0082e822a7ce76).(); |
| 71 | cpSpaceSetGravitycxx . . $ cpSpaceSetGravity(7561685522e3e327).(space, cpvcxx . . $ cpv(3142d57d978b2176).(0, -600)); |
| 72 | |
| 73 | cpBodycxx . . $ cpBody# *staticBody = cpSpaceGetStaticBodycxx . . $ cpSpaceGetStaticBody(d6ad68aaf406e51f).(space); |
| 74 | cpShapecxx . . $ cpShape# *shape; |
| 75 | |
| 76 | // beveling all of the line segments slightly helps prevent things from getting stuck on cracks |
| 77 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(staticBody, cpvcxx . . $ cpv(3142d57d978b2176).(-256,16), cpvcxx . . $ cpv(3142d57d978b2176).(-256,300), 2.0f)); |
| 78 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 79 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 80 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 81 | |
| 82 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(staticBody, cpvcxx . . $ cpv(3142d57d978b2176).(-256,16), cpvcxx . . $ cpv(3142d57d978b2176).(-192,0), 2.0f)); |
| 83 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 84 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 85 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 86 | |
| 87 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(staticBody, cpvcxx . . $ cpv(3142d57d978b2176).(-192,0), cpvcxx . . $ cpv(3142d57d978b2176).(-192, -64), 2.0f)); |
| 88 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 89 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 90 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 91 | |
| 92 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(staticBody, cpvcxx . . $ cpv(3142d57d978b2176).(-128,-64), cpvcxx . . $ cpv(3142d57d978b2176).(-128,144), 2.0f)); |
| 93 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 94 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 95 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 96 | |
| 97 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(staticBody, cpvcxx . . $ cpv(3142d57d978b2176).(-192,80), cpvcxx . . $ cpv(3142d57d978b2176).(-192,176), 2.0f)); |
| 98 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 99 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 100 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 101 | |
| 102 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(staticBody, cpvcxx . . $ cpv(3142d57d978b2176).(-192,176), cpvcxx . . $ cpv(3142d57d978b2176).(-128,240), 2.0f)); |
| 103 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 104 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 105 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 106 | |
| 107 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(staticBody, cpvcxx . . $ cpv(3142d57d978b2176).(-128,144), cpvcxx . . $ cpv(3142d57d978b2176).(192,64), 2.0f)); |
| 108 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 109 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 110 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 111 | |
| 112 | cpVectcxx . . $ cpVect# verts[] = { |
| 113 | cpvcxx . . $ cpv(3142d57d978b2176).(-30,-80), |
| 114 | cpvcxx . . $ cpv(3142d57d978b2176).(-30, 80), |
| 115 | cpvcxx . . $ cpv(3142d57d978b2176).( 30, 64), |
| 116 | cpvcxx . . $ cpv(3142d57d978b2176).( 30,-80), |
| 117 | }; |
| 118 | |
| 119 | cpBodycxx . . $ cpBody# *plunger = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(1.0f, INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!)); |
| 120 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(plunger, cpvcxx . . $ cpv(3142d57d978b2176).(-160,-80)); |
| 121 | |
| 122 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpPolyShapeNewcxx . . $ cpPolyShapeNew(119891a3da20e8eb).(plunger, 4, verts, cpTransformIdentitycxx . . $ cpTransformIdentity., 0.0)); |
| 123 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 1.0f); |
| 124 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.5f); |
| 125 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, cpShapeFilterNewcxx . . $ cpShapeFilterNew(d4cd326b51c6d7a3).(CP_NO_GROUPcxx . . $ `include/chipmunk/chipmunk_types.h:228:10`!, 1, 1)); |
| 126 | |
| 127 | // add balls to hopper |
| 128 | for(int i=0; i<numBallscxx . . $ `demo/Pump.c:27:9`!; i++) |
| 129 | ballscxx . . $ balls.[i] = add_ballcxx . . $ add_ball(b314a1699273f84).(space, cpvcxx . . $ cpv(3142d57d978b2176).(-224 + i,80 + 64*i)); |
| 130 | |
| 131 | // add small gear |
| 132 | cpBodycxx . . $ cpBody# *smallGear = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(10.0f, cpMomentForCirclecxx . . $ cpMomentForCircle(a539e2d95614f770).(10.0f, 80, 0, cpvzerocxx . . $ cpvzero.))); |
| 133 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(smallGear, cpvcxx . . $ cpv(3142d57d978b2176).(-160,-160)); |
| 134 | cpBodySetAnglecxx . . $ cpBodySetAngle(797bd3bb7a653b39).(smallGear, -CP_PIcxx . . $ `include/chipmunk/chipmunk_types.h:115:9`!/2.0f); |
| 135 | |
| 136 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpCircleShapeNewcxx . . $ cpCircleShapeNew(e5e4e3a52c89533b).(smallGear, 80.0f, cpvzerocxx . . $ cpvzero.)); |
| 137 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, CP_SHAPE_FILTER_NONEcxx . . $ CP_SHAPE_FILTER_NONE.); |
| 138 | |
| 139 | cpSpaceAddConstraintcxx . . $ cpSpaceAddConstraint(9bcc8bada2b14254).(space, cpPivotJointNew2cxx . . $ cpPivotJointNew2(74f6d8fa0e302020).(staticBody, smallGear, cpvcxx . . $ cpv(3142d57d978b2176).(-160,-160), cpvzerocxx . . $ cpvzero.)); |
| 140 | |
| 141 | // add big gear |
| 142 | cpBodycxx . . $ cpBody# *bigGear = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(40.0f, cpMomentForCirclecxx . . $ cpMomentForCircle(a539e2d95614f770).(40.0f, 160, 0, cpvzerocxx . . $ cpvzero.))); |
| 143 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(bigGear, cpvcxx . . $ cpv(3142d57d978b2176).(80,-160)); |
| 144 | cpBodySetAnglecxx . . $ cpBodySetAngle(797bd3bb7a653b39).(bigGear, CP_PIcxx . . $ `include/chipmunk/chipmunk_types.h:115:9`!/2.0f); |
| 145 | |
| 146 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpCircleShapeNewcxx . . $ cpCircleShapeNew(e5e4e3a52c89533b).(bigGear, 160.0f, cpvzerocxx . . $ cpvzero.)); |
| 147 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, CP_SHAPE_FILTER_NONEcxx . . $ CP_SHAPE_FILTER_NONE.); |
| 148 | |
| 149 | cpSpaceAddConstraintcxx . . $ cpSpaceAddConstraint(9bcc8bada2b14254).(space, cpPivotJointNew2cxx . . $ cpPivotJointNew2(74f6d8fa0e302020).(staticBody, bigGear, cpvcxx . . $ cpv(3142d57d978b2176).(80,-160), cpvzerocxx . . $ cpvzero.)); |
| 150 | |
| 151 | // connect the plunger to the small gear. |
| 152 | cpSpaceAddConstraintcxx . . $ cpSpaceAddConstraint(9bcc8bada2b14254).(space, cpPinJointNewcxx . . $ cpPinJointNew(74f6d8fa0e302020).(smallGear, plunger, cpvcxx . . $ cpv(3142d57d978b2176).(80,0), cpvcxx . . $ cpv(3142d57d978b2176).(0,0))); |
| 153 | // connect the gears. |
| 154 | cpSpaceAddConstraintcxx . . $ cpSpaceAddConstraint(9bcc8bada2b14254).(space, cpGearJointNewcxx . . $ cpGearJointNew(d029de5d93e4cb4a).(smallGear, bigGear, -CP_PIcxx . . $ `include/chipmunk/chipmunk_types.h:115:9`!/2.0f, -2.0f)); |
| 155 | |
| 156 | |
| 157 | // feeder mechanism |
| 158 | cpFloatcxx . . $ cpFloat# bottom = -300.0f; |
| 159 | cpFloatcxx . . $ cpFloat# top = 32.0f; |
| 160 | cpBodycxx . . $ cpBody# *feeder = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(1.0f, cpMomentForSegmentcxx . . $ cpMomentForSegment(13ad460f360d98d3).(1.0f, cpvcxx . . $ cpv(3142d57d978b2176).(-224.0f, bottom), cpvcxx . . $ cpv(3142d57d978b2176).(-224.0f, top), 0.0f))); |
| 161 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(feeder, cpvcxx . . $ cpv(3142d57d978b2176).(-224, (bottom + top)/2.0f)); |
| 162 | |
| 163 | cpFloatcxx . . $ cpFloat# len = top - bottom; |
| 164 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(feeder, cpvcxx . . $ cpv(3142d57d978b2176).(0.0f, len/2.0f), cpvcxx . . $ cpv(3142d57d978b2176).(0.0f, -len/2.0f), 20.0f)); |
| 165 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, GRAB_FILTERcxx . . $ GRAB_FILTER.); |
| 166 | |
| 167 | cpSpaceAddConstraintcxx . . $ cpSpaceAddConstraint(9bcc8bada2b14254).(space, cpPivotJointNew2cxx . . $ cpPivotJointNew2(74f6d8fa0e302020).(staticBody, feeder, cpvcxx . . $ cpv(3142d57d978b2176).(-224.0f, bottom), cpvcxx . . $ cpv(3142d57d978b2176).(0.0f, -len/2.0f))); |
| 168 | cpVectcxx . . $ cpVect# anchr = cpBodyWorldToLocalcxx . . $ cpBodyWorldToLocal(4ff4900d49a97e73).(feeder, cpvcxx . . $ cpv(3142d57d978b2176).(-224.0f, -160.0f)); |
| 169 | cpSpaceAddConstraintcxx . . $ cpSpaceAddConstraint(9bcc8bada2b14254).(space, cpPinJointNewcxx . . $ cpPinJointNew(74f6d8fa0e302020).(feeder, smallGear, anchr, cpvcxx . . $ cpv(3142d57d978b2176).(0.0f, 80.0f))); |
| 170 | |
| 171 | // motorize the second gear |
| 172 | motorcxx . . $ motor. = cpSpaceAddConstraintcxx . . $ cpSpaceAddConstraint(9bcc8bada2b14254).(space, cpSimpleMotorNewcxx . . $ cpSimpleMotorNew(fc786efe5abab4f7).(staticBody, bigGear, 3.0f)); |
| 173 | |
| 174 | return space; |
| 175 | } |
| 176 | |
| 177 | static void |
| 178 | destroycxx . . $ destroy(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space) |
| 179 | { |
| 180 | ChipmunkDemoFreeSpaceChildrencxx . . $ ChipmunkDemoFreeSpaceChildren(728b9c9a69722ef8).(space); |
| 181 | cpSpaceFreecxx . . $ cpSpaceFree(728b9c9a69722ef8).(space); |
| 182 | } |
| 183 | |
| 184 | ChipmunkDemocxx . . $ ChipmunkDemo# Pumpcxx . . $ Pump. = { |
| 185 | "Pump", |
| 186 | 1.0/120.0, |
| 187 | initcxx . . $ init(1f0082e822a7ce76)., |
| 188 | updatecxx . . $ update(fa66a0a48611083e)., |
| 189 | ChipmunkDemoDefaultDrawImplcxx . . $ ChipmunkDemoDefaultDrawImpl(728b9c9a69722ef8)., |
| 190 | destroycxx . . $ destroy(728b9c9a69722ef8)., |
| 191 | }; |