| 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 cpBodycxx . . $ cpBody# *KinematicBoxBodycxx . . $ KinematicBoxBody.; |
| 26 | |
| 27 | static void |
| 28 | updatecxx . . $ update(fa66a0a48611083e).(cpSpacecxx . . $ cpSpace# *space, double dt) |
| 29 | { |
| 30 | cpSpaceStepcxx . . $ cpSpaceStep(fa66a0a48611083e).(space, dt); |
| 31 | } |
| 32 | |
| 33 | static void |
| 34 | AddBoxcxx . . $ AddBox(40a7ed2591acc671).(cpSpacecxx . . $ cpSpace# *space, cpVectcxx . . $ cpVect# pos, cpFloatcxx . . $ cpFloat# mass, cpFloatcxx . . $ cpFloat# width, cpFloatcxx . . $ cpFloat# height) |
| 35 | { |
| 36 | cpBodycxx . . $ cpBody# *body = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(mass, cpMomentForBoxcxx . . $ cpMomentForBox(7678bba071383ab).(mass, width, height))); |
| 37 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(body, pos); |
| 38 | |
| 39 | cpShapecxx . . $ cpShape# *shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpBoxShapeNewcxx . . $ cpBoxShapeNew(94c4f8982441e75a).(body, width, height, 0.0)); |
| 40 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 41 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.7f); |
| 42 | } |
| 43 | |
| 44 | static void |
| 45 | AddSegmentcxx . . $ AddSegment(40a7ed2591acc671).(cpSpacecxx . . $ cpSpace# *space, cpVectcxx . . $ cpVect# pos, cpFloatcxx . . $ cpFloat# mass, cpFloatcxx . . $ cpFloat# width, cpFloatcxx . . $ cpFloat# height) |
| 46 | { |
| 47 | cpBodycxx . . $ cpBody# *body = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(mass, cpMomentForBoxcxx . . $ cpMomentForBox(7678bba071383ab).(mass, width, height))); |
| 48 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(body, pos); |
| 49 | |
| 50 | cpShapecxx . . $ cpShape# *shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(body, cpvcxx . . $ cpv(3142d57d978b2176).(0.0, (height - width)/2.0), cpvcxx . . $ cpv(3142d57d978b2176).(0.0, (width - height)/2.0), width/2.0)); |
| 51 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 52 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.7f); |
| 53 | } |
| 54 | |
| 55 | static void |
| 56 | AddCirclecxx . . $ AddCircle(acd22e8a3b14f235).(cpSpacecxx . . $ cpSpace# *space, cpVectcxx . . $ cpVect# pos, cpFloatcxx . . $ cpFloat# mass, cpFloatcxx . . $ cpFloat# radius) |
| 57 | { |
| 58 | cpBodycxx . . $ cpBody# *body = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(mass, cpMomentForCirclecxx . . $ cpMomentForCircle(a539e2d95614f770).(mass, 0.0, radius, cpvzerocxx . . $ cpvzero.))); |
| 59 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(body, pos); |
| 60 | |
| 61 | cpShapecxx . . $ cpShape# *shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpCircleShapeNewcxx . . $ cpCircleShapeNew(e5e4e3a52c89533b).(body, radius, cpvzerocxx . . $ cpvzero.)); |
| 62 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f); |
| 63 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.7f); |
| 64 | } |
| 65 | |
| 66 | static cpSpacecxx . . $ cpSpace# * |
| 67 | initcxx . . $ init(1f0082e822a7ce76).(void) |
| 68 | { |
| 69 | cpSpacecxx . . $ cpSpace# *space = cpSpaceNewcxx . . $ cpSpaceNew(1f0082e822a7ce76).(); |
| 70 | cpSpaceSetGravitycxx . . $ cpSpaceSetGravity(7561685522e3e327).(space, cpvcxx . . $ cpv(3142d57d978b2176).(0, -600)); |
| 71 | |
| 72 | cpShapecxx . . $ cpShape# *shape; |
| 73 | |
| 74 | // We create an infinite mass rogue body to attach the line segments too |
| 75 | // This way we can control the rotation however we want. |
| 76 | KinematicBoxBodycxx . . $ KinematicBoxBody. = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewKinematiccxx . . $ cpBodyNewKinematic(af6db6e743345a49).()); |
| 77 | cpBodySetAngularVelocitycxx . . $ cpBodySetAngularVelocity(797bd3bb7a653b39).(KinematicBoxBodycxx . . $ KinematicBoxBody., 0.4f); |
| 78 | |
| 79 | // Set up the static box. |
| 80 | cpVectcxx . . $ cpVect# a = cpvcxx . . $ cpv(3142d57d978b2176).(-200, -200); |
| 81 | cpVectcxx . . $ cpVect# b = cpvcxx . . $ cpv(3142d57d978b2176).(-200, 200); |
| 82 | cpVectcxx . . $ cpVect# c = cpvcxx . . $ cpv(3142d57d978b2176).( 200, 200); |
| 83 | cpVectcxx . . $ cpVect# d = cpvcxx . . $ cpv(3142d57d978b2176).( 200, -200); |
| 84 | |
| 85 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(KinematicBoxBodycxx . . $ KinematicBoxBody., a, b, 0.0f)); |
| 86 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 1.0f); |
| 87 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 1.0f); |
| 88 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 89 | |
| 90 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(KinematicBoxBodycxx . . $ KinematicBoxBody., b, c, 0.0f)); |
| 91 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 1.0f); |
| 92 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 1.0f); |
| 93 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 94 | |
| 95 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(KinematicBoxBodycxx . . $ KinematicBoxBody., c, d, 0.0f)); |
| 96 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 1.0f); |
| 97 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 1.0f); |
| 98 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 99 | |
| 100 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpSegmentShapeNewcxx . . $ cpSegmentShapeNew(3a41acb06b39b945).(KinematicBoxBodycxx . . $ KinematicBoxBody., d, a, 0.0f)); |
| 101 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 1.0f); |
| 102 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 1.0f); |
| 103 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 104 | |
| 105 | cpFloatcxx . . $ cpFloat# mass = 1; |
| 106 | cpFloatcxx . . $ cpFloat# width = 30; |
| 107 | cpFloatcxx . . $ cpFloat# height = width*2; |
| 108 | |
| 109 | // Add the bricks. |
| 110 | for(int i=0; i<7; i++){ |
| 111 | for(int j=0; j<3; j++){ |
| 112 | cpVectcxx . . $ cpVect# pos = cpvcxx . . $ cpv(3142d57d978b2176).(i*width - 150, j*height - 150); |
| 113 | |
| 114 | int type = (randcxx . . $ rand(b126dc7c1de90089).()%3000)/1000; |
| 115 | if(type ==0){ |
| 116 | AddBoxcxx . . $ AddBox(40a7ed2591acc671).(space, pos, mass, width, height); |
| 117 | } else if(type == 1){ |
| 118 | AddSegmentcxx . . $ AddSegment(40a7ed2591acc671).(space, pos, mass, width, height); |
| 119 | } else { |
| 120 | AddCirclecxx . . $ AddCircle(acd22e8a3b14f235).(space, cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(pos, cpvcxx . . $ cpv(3142d57d978b2176).(0.0, (height - width)/2.0)), mass, width/2.0); |
| 121 | AddCirclecxx . . $ AddCircle(acd22e8a3b14f235).(space, cpvaddcxx . . $ cpvadd(47eb3f105675e23c).(pos, cpvcxx . . $ cpv(3142d57d978b2176).(0.0, (width - height)/2.0)), mass, width/2.0); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return space; |
| 127 | } |
| 128 | |
| 129 | static void |
| 130 | destroycxx . . $ destroy(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space) |
| 131 | { |
| 132 | ChipmunkDemoFreeSpaceChildrencxx . . $ ChipmunkDemoFreeSpaceChildren(728b9c9a69722ef8).(space); |
| 133 | cpSpaceFreecxx . . $ cpSpaceFree(728b9c9a69722ef8).(space); |
| 134 | } |
| 135 | |
| 136 | ChipmunkDemocxx . . $ ChipmunkDemo# Tumblecxx . . $ Tumble. = { |
| 137 | "Tumble", |
| 138 | 1.0/180.0, |
| 139 | initcxx . . $ init(1f0082e822a7ce76)., |
| 140 | updatecxx . . $ update(fa66a0a48611083e)., |
| 141 | ChipmunkDemoDefaultDrawImplcxx . . $ ChipmunkDemoDefaultDrawImpl(728b9c9a69722ef8)., |
| 142 | destroycxx . . $ destroy(728b9c9a69722ef8)., |
| 143 | }; |