| 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 const int image_widthcxx . . $ image_width. = 188; |
| 26 | static const int image_heightcxx . . $ image_height. = 35; |
| 27 | static const int image_row_lengthcxx . . $ image_row_length. = 24; |
| 28 | |
| 29 | static const unsigned char image_bitmapcxx . . $ image_bitmap.[] = { |
| 30 | 15,-16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,-64,15,63,-32,-2,0,0,0,0,0,0,0, |
| 31 | 0,0,0,0,0,0,0,0,0,0,0,31,-64,15,127,-125,-1,-128,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 32 | 0,0,0,127,-64,15,127,15,-1,-64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,-1,-64,15,-2, |
| 33 | 31,-1,-64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,-1,-64,0,-4,63,-1,-32,0,0,0,0,0,0, |
| 34 | 0,0,0,0,0,0,0,0,0,0,1,-1,-64,15,-8,127,-1,-32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 35 | 1,-1,-64,0,-8,-15,-1,-32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,-31,-1,-64,15,-8,-32, |
| 36 | -1,-32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,-15,-1,-64,9,-15,-32,-1,-32,0,0,0,0,0, |
| 37 | 0,0,0,0,0,0,0,0,0,0,31,-15,-1,-64,0,-15,-32,-1,-32,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| 38 | 0,0,63,-7,-1,-64,9,-29,-32,127,-61,-16,63,15,-61,-1,-8,31,-16,15,-8,126,7,-31, |
| 39 | -8,31,-65,-7,-1,-64,9,-29,-32,0,7,-8,127,-97,-25,-1,-2,63,-8,31,-4,-1,15,-13, |
| 40 | -4,63,-1,-3,-1,-64,9,-29,-32,0,7,-8,127,-97,-25,-1,-2,63,-8,31,-4,-1,15,-13, |
| 41 | -2,63,-1,-3,-1,-64,9,-29,-32,0,7,-8,127,-97,-25,-1,-1,63,-4,63,-4,-1,15,-13, |
| 42 | -2,63,-33,-1,-1,-32,9,-25,-32,0,7,-8,127,-97,-25,-1,-1,63,-4,63,-4,-1,15,-13, |
| 43 | -1,63,-33,-1,-1,-16,9,-25,-32,0,7,-8,127,-97,-25,-1,-1,63,-4,63,-4,-1,15,-13, |
| 44 | -1,63,-49,-1,-1,-8,9,-57,-32,0,7,-8,127,-97,-25,-8,-1,63,-2,127,-4,-1,15,-13, |
| 45 | -1,-65,-49,-1,-1,-4,9,-57,-32,0,7,-8,127,-97,-25,-8,-1,63,-2,127,-4,-1,15,-13, |
| 46 | -1,-65,-57,-1,-1,-2,9,-57,-32,0,7,-8,127,-97,-25,-8,-1,63,-2,127,-4,-1,15,-13, |
| 47 | -1,-1,-57,-1,-1,-1,9,-57,-32,0,7,-1,-1,-97,-25,-8,-1,63,-1,-1,-4,-1,15,-13,-1, |
| 48 | -1,-61,-1,-1,-1,-119,-57,-32,0,7,-1,-1,-97,-25,-8,-1,63,-1,-1,-4,-1,15,-13,-1, |
| 49 | -1,-61,-1,-1,-1,-55,-49,-32,0,7,-1,-1,-97,-25,-8,-1,63,-1,-1,-4,-1,15,-13,-1, |
| 50 | -1,-63,-1,-1,-1,-23,-49,-32,127,-57,-1,-1,-97,-25,-1,-1,63,-1,-1,-4,-1,15,-13, |
| 51 | -1,-1,-63,-1,-1,-1,-16,-49,-32,-1,-25,-1,-1,-97,-25,-1,-1,63,-33,-5,-4,-1,15, |
| 52 | -13,-1,-1,-64,-1,-9,-1,-7,-49,-32,-1,-25,-8,127,-97,-25,-1,-1,63,-33,-5,-4,-1, |
| 53 | 15,-13,-1,-1,-64,-1,-13,-1,-32,-49,-32,-1,-25,-8,127,-97,-25,-1,-2,63,-49,-13, |
| 54 | -4,-1,15,-13,-1,-1,-64,127,-7,-1,-119,-17,-15,-1,-25,-8,127,-97,-25,-1,-2,63, |
| 55 | -49,-13,-4,-1,15,-13,-3,-1,-64,127,-8,-2,15,-17,-1,-1,-25,-8,127,-97,-25,-1, |
| 56 | -8,63,-49,-13,-4,-1,15,-13,-3,-1,-64,63,-4,120,0,-17,-1,-1,-25,-8,127,-97,-25, |
| 57 | -8,0,63,-57,-29,-4,-1,15,-13,-4,-1,-64,63,-4,0,15,-17,-1,-1,-25,-8,127,-97, |
| 58 | -25,-8,0,63,-57,-29,-4,-1,-1,-13,-4,-1,-64,31,-2,0,0,103,-1,-1,-57,-8,127,-97, |
| 59 | -25,-8,0,63,-57,-29,-4,-1,-1,-13,-4,127,-64,31,-2,0,15,103,-1,-1,-57,-8,127, |
| 60 | -97,-25,-8,0,63,-61,-61,-4,127,-1,-29,-4,127,-64,15,-8,0,0,55,-1,-1,-121,-8, |
| 61 | 127,-97,-25,-8,0,63,-61,-61,-4,127,-1,-29,-4,63,-64,15,-32,0,0,23,-1,-2,3,-16, |
| 62 | 63,15,-61,-16,0,31,-127,-127,-8,31,-1,-127,-8,31,-128,7,-128,0,0 |
| 63 | }; |
| 64 | |
| 65 | static inline int |
| 66 | get_pixelcxx . . $ get_pixel(9b79fb6aee4c0440).(int x, int y) |
| 67 | { |
| 68 | return (image_bitmapcxx . . $ image_bitmap.[(x>>3) + y*image_row_lengthcxx . . $ image_row_length.]>>(~x&0x7)) & 1; |
| 69 | } |
| 70 | |
| 71 | static int bodyCountcxx . . $ bodyCount. = 0; |
| 72 | |
| 73 | static void |
| 74 | updatecxx . . $ update(fa66a0a48611083e).(cpSpacecxx . . $ cpSpace# *space, double dt) |
| 75 | { |
| 76 | cpSpaceStepcxx . . $ cpSpaceStep(fa66a0a48611083e).(space, dt); |
| 77 | } |
| 78 | |
| 79 | static void |
| 80 | DrawDotcxx . . $ DrawDot(3eac74103e9ce6d).(cpBodycxx . . $ cpBody# *body, void *unused) |
| 81 | { |
| 82 | ChipmunkDebugDrawDotcxx . . $ ChipmunkDebugDrawDot(227e9b49eafe2913).(3.5/ChipmunkDebugDrawPointLineScalecxx . . $ ChipmunkDebugDrawPointLineScale., cpBodyGetPositioncxx . . $ cpBodyGetPosition(2e8d436bcfa5d74b).(body), RGBAColorcxx . . $ RGBAColor(54765961e0537a31).(0xee/255.0f, 0xe8/255.0f, 0xd5/255.0f, 1.0f)); |
| 83 | } |
| 84 | |
| 85 | static void |
| 86 | drawcxx . . $ draw(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space) |
| 87 | { |
| 88 | cpSpaceEachBodycxx . . $ cpSpaceEachBody(ac08ffee037ef35).(space, DrawDotcxx . . $ DrawDot(3eac74103e9ce6d)., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 89 | |
| 90 | // ChipmunkDebugDrawCollisionPoints(space); |
| 91 | } |
| 92 | |
| 93 | static cpShapecxx . . $ cpShape# * |
| 94 | make_ballcxx . . $ make_ball(ec5644bf9f5c702f).(cpFloatcxx . . $ cpFloat# x, cpFloatcxx . . $ cpFloat# y) |
| 95 | { |
| 96 | cpBodycxx . . $ cpBody# *body = cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(1.0, INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!); |
| 97 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(body, cpvcxx . . $ cpv(3142d57d978b2176).(x, y)); |
| 98 | |
| 99 | cpShapecxx . . $ cpShape# *shape = cpCircleShapeNewcxx . . $ cpCircleShapeNew(e5e4e3a52c89533b).(body, 0.95, cpvzerocxx . . $ cpvzero.); |
| 100 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0); |
| 101 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.0); |
| 102 | |
| 103 | return shape; |
| 104 | } |
| 105 | |
| 106 | static cpSpacecxx . . $ cpSpace# * |
| 107 | initcxx . . $ init(1f0082e822a7ce76).(void) |
| 108 | { |
| 109 | cpSpacecxx . . $ cpSpace# *space = cpSpaceNewcxx . . $ cpSpaceNew(1f0082e822a7ce76).(); |
| 110 | cpSpaceSetIterationscxx . . $ cpSpaceSetIterations(3274f250b6e81e27).(space, 1); |
| 111 | |
| 112 | // The space will contain a very large number of similary sized objects. |
| 113 | // This is the perfect candidate for using the spatial hash. |
| 114 | // Generally you will never need to do this. |
| 115 | cpSpaceUseSpatialHashcxx . . $ cpSpaceUseSpatialHash(3cef60747bc5c4ee).(space, 2.0, 10000); |
| 116 | |
| 117 | bodyCountcxx . . $ bodyCount. = 0; |
| 118 | |
| 119 | cpBodycxx . . $ cpBody# *body; |
| 120 | cpShapecxx . . $ cpShape# *shape; |
| 121 | |
| 122 | for(int y=0; y<image_heightcxx . . $ image_height.; y++){ |
| 123 | for(int x=0; x<image_widthcxx . . $ image_width.; x++){ |
| 124 | if(!get_pixelcxx . . $ get_pixel(9b79fb6aee4c0440).(x, y)) continue; |
| 125 | |
| 126 | cpFloatcxx . . $ cpFloat# x_jitter = 0.05*frandcxx . . $ frand(31fa7155c10fdd13).(); |
| 127 | cpFloatcxx . . $ cpFloat# y_jitter = 0.05*frandcxx . . $ frand(31fa7155c10fdd13).(); |
| 128 | |
| 129 | shape = make_ballcxx . . $ make_ball(ec5644bf9f5c702f).(2*(x - image_widthcxx . . $ image_width./2 + x_jitter), 2*(image_heightcxx . . $ image_height./2 - y + y_jitter)); |
| 130 | cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpShapeGetBodycxx . . $ cpShapeGetBody(abc772114277478f).(shape)); |
| 131 | cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, shape); |
| 132 | |
| 133 | bodyCountcxx . . $ bodyCount.++; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | body = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(1e9, INFINITYcxx . . $ `<external>/11263917310783833665/math.h:93:12`!)); |
| 138 | cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(body, cpvcxx . . $ cpv(3142d57d978b2176).(-1000, -10)); |
| 139 | cpBodySetVelocitycxx . . $ cpBodySetVelocity(864e17bcbe059b08).(body, cpvcxx . . $ cpv(3142d57d978b2176).(400, 0)); |
| 140 | |
| 141 | shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpCircleShapeNewcxx . . $ cpCircleShapeNew(e5e4e3a52c89533b).(body, 8.0f, cpvzerocxx . . $ cpvzero.)); |
| 142 | cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0); |
| 143 | cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.0); |
| 144 | cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.); |
| 145 | |
| 146 | bodyCountcxx . . $ bodyCount.++; |
| 147 | |
| 148 | return space; |
| 149 | } |
| 150 | |
| 151 | static void |
| 152 | destroycxx . . $ destroy(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space) |
| 153 | { |
| 154 | ChipmunkDemoFreeSpaceChildrencxx . . $ ChipmunkDemoFreeSpaceChildren(728b9c9a69722ef8).(space); |
| 155 | cpSpaceFreecxx . . $ cpSpaceFree(728b9c9a69722ef8).(space); |
| 156 | } |
| 157 | |
| 158 | ChipmunkDemocxx . . $ ChipmunkDemo# LogoSmashcxx . . $ LogoSmash. = { |
| 159 | "Logo Smash", |
| 160 | 1.0/60.0, |
| 161 | initcxx . . $ init(1f0082e822a7ce76)., |
| 162 | updatecxx . . $ update(fa66a0a48611083e)., |
| 163 | drawcxx . . $ draw(728b9c9a69722ef8)., |
| 164 | destroycxx . . $ destroy(728b9c9a69722ef8)., |
| 165 | }; |