Debian Codegraph @

demo/Plink.c

raw symbols SCIP
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 cpFloatcxx . . $ cpFloat# pentagon_masscxx . . $ pentagon_mass. = 0.0f;
26 static cpFloatcxx . . $ cpFloat# pentagon_momentcxx . . $ pentagon_moment. = 0.0f;
27
28 // Iterate over all of the bodies and reset the ones that have fallen offscreen.
29 static void
30 eachBodycxx . . $ eachBody(3eac74103e9ce6d).(cpBodycxx . . $ cpBody# *body, void *unused)
31 {
32 cpVectcxx . . $ cpVect# pos = cpBodyGetPositioncxx . . $ cpBodyGetPosition(2e8d436bcfa5d74b).(body);
33 if(pos.ycxx . . $ cpVect#y. < -260 || cpfabscxx . . $ cpfabs(447c67c6676f75c3).(pos.xcxx . . $ cpVect#x.) > 340){
34 cpFloatcxx . . $ cpFloat# x = randcxx . . $ rand(b126dc7c1de90089).()/(cpFloatcxx . . $ cpFloat#)RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:91:9`!*640 - 320;
35 cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(body, cpvcxx . . $ cpv(3142d57d978b2176).(x, 260));
36 }
37 }
38
39 static void
40 updatecxx . . $ update(fa66a0a48611083e).(cpSpacecxx . . $ cpSpace# *space, double dt)
41 {
42 if(ChipmunkDemoRightDowncxx . . $ ChipmunkDemoRightDown.){
43 cpShapecxx . . $ cpShape# *nearest = cpSpacePointQueryNearestcxx . . $ cpSpacePointQueryNearest(b0e549d484789d).(space, ChipmunkDemoMousecxx . . $ ChipmunkDemoMouse., 0.0, GRAB_FILTERcxx . . $ GRAB_FILTER., NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
44 if(nearest){
45 cpBodycxx . . $ cpBody# *body = cpShapeGetBodycxx . . $ cpShapeGetBody(abc772114277478f).(nearest);
46 if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(body) == CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC.){
47 cpBodySetTypecxx . . $ cpBodySetType(f2bd8afc8ccfe52).(body, CP_BODY_TYPE_DYNAMICcxx . . $ CP_BODY_TYPE_DYNAMIC.);
48 cpBodySetMasscxx . . $ cpBodySetMass(797bd3bb7a653b39).(body, pentagon_masscxx . . $ pentagon_mass.);
49 cpBodySetMomentcxx . . $ cpBodySetMoment(797bd3bb7a653b39).(body, pentagon_momentcxx . . $ pentagon_moment.);
50 } else if(cpBodyGetTypecxx . . $ cpBodyGetType(ea52de4c196d619c).(body) == CP_BODY_TYPE_DYNAMICcxx . . $ CP_BODY_TYPE_DYNAMIC.) {
51 cpBodySetTypecxx . . $ cpBodySetType(f2bd8afc8ccfe52).(body, CP_BODY_TYPE_STATICcxx . . $ CP_BODY_TYPE_STATIC.);
52 }
53 }
54 }
55
56 cpSpaceEachBodycxx . . $ cpSpaceEachBody(ac08ffee037ef35).(space, &eachBodycxx . . $ eachBody(3eac74103e9ce6d)., NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
57 cpSpaceStepcxx . . $ cpSpaceStep(fa66a0a48611083e).(space, dt);
58 }
59
60 #define NUM_VERTScxx . . $ `demo/Plink.c:60:9`! 5
61
62 static cpSpacecxx . . $ cpSpace# *
63 initcxx . . $ init(1f0082e822a7ce76).(void)
64 {
65 ChipmunkDemoMessageStringcxx . . $ ChipmunkDemoMessageString. = "Right click to make pentagons static/dynamic.";
66
67 cpSpacecxx . . $ cpSpace# *space = cpSpaceNewcxx . . $ cpSpaceNew(1f0082e822a7ce76).();
68 cpSpaceSetIterationscxx . . $ cpSpaceSetIterations(3274f250b6e81e27).(space, 5);
69 cpSpaceSetGravitycxx . . $ cpSpaceSetGravity(7561685522e3e327).(space, cpvcxx . . $ cpv(3142d57d978b2176).(0, -100));
70
71 cpBodycxx . . $ cpBody# *body, *staticBody = cpSpaceGetStaticBodycxx . . $ cpSpaceGetStaticBody(d6ad68aaf406e51f).(space);
72 cpShapecxx . . $ cpShape# *shape;
73
74 // Vertexes for a triangle shape.
75 cpVectcxx . . $ cpVect# tris[] = {
76 cpvcxx . . $ cpv(3142d57d978b2176).(-15,-15),
77 cpvcxx . . $ cpv(3142d57d978b2176).( 0, 10),
78 cpvcxx . . $ cpv(3142d57d978b2176).( 15,-15),
79 };
80
81 // Create the static triangles.
82 for(int i=0; i<9; i++){
83 for(int j=0; j<6; j++){
84 cpFloatcxx . . $ cpFloat# stagger = (j%2)*40;
85 cpVectcxx . . $ cpVect# offset = cpvcxx . . $ cpv(3142d57d978b2176).(i*80 - 320 + stagger, j*70 - 240);
86 shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpPolyShapeNewcxx . . $ cpPolyShapeNew(119891a3da20e8eb).(staticBody, 3, tris, cpTransformTranslatecxx . . $ cpTransformTranslate(9ddf098b65af1f2f).(offset), 0.0));
87 cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 1.0f);
88 cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 1.0f);
89 cpShapeSetFiltercxx . . $ cpShapeSetFilter(ec7e03c52efe89d5).(shape, NOT_GRABBABLE_FILTERcxx . . $ NOT_GRABBABLE_FILTER.);
90 }
91 }
92
93 // Create vertexes for a pentagon shape.
94 cpVectcxx . . $ cpVect# verts[NUM_VERTScxx . . $ `demo/Plink.c:60:9`!];
95 for(int i=0; i<NUM_VERTScxx . . $ `demo/Plink.c:60:9`!; i++){
96 cpFloatcxx . . $ cpFloat# angle = -2.0f*CP_PIcxx . . $ `include/chipmunk/chipmunk_types.h:115:9`!*i/((cpFloatcxx . . $ cpFloat#) NUM_VERTScxx . . $ `demo/Plink.c:60:9`!);
97 verts[i] = cpvcxx . . $ cpv(3142d57d978b2176).(10*coscxx . . $ cos(447c67c6676f75c3).(angle), 10*sincxx . . $ sin(447c67c6676f75c3).(angle));
98 }
99
100 pentagon_masscxx . . $ pentagon_mass. = 1.0;
101 pentagon_momentcxx . . $ pentagon_moment. = cpMomentForPolycxx . . $ cpMomentForPoly(89d843ff16ae6b28).(1.0f, NUM_VERTScxx . . $ `demo/Plink.c:60:9`!, verts, cpvzerocxx . . $ cpvzero., 0.0f);
102
103 // Add lots of pentagons.
104 for(int i=0; i<300; i++){
105 body = cpSpaceAddBodycxx . . $ cpSpaceAddBody(1a8396fd971b33e7).(space, cpBodyNewcxx . . $ cpBodyNew(51915e6cc8310751).(pentagon_masscxx . . $ pentagon_mass., pentagon_momentcxx . . $ pentagon_moment.));
106 cpFloatcxx . . $ cpFloat# x = randcxx . . $ rand(b126dc7c1de90089).()/(cpFloatcxx . . $ cpFloat#)RAND_MAXcxx . . $ `<external>/10696550936717951914/stdlib.h:91:9`!*640 - 320;
107 cpBodySetPositioncxx . . $ cpBodySetPosition(864e17bcbe059b08).(body, cpvcxx . . $ cpv(3142d57d978b2176).(x, 350));
108
109 shape = cpSpaceAddShapecxx . . $ cpSpaceAddShape(a8063921f8ae51c0).(space, cpPolyShapeNewcxx . . $ cpPolyShapeNew(119891a3da20e8eb).(body, NUM_VERTScxx . . $ `demo/Plink.c:60:9`!, verts, cpTransformIdentitycxx . . $ cpTransformIdentity., 0.0));
110 cpShapeSetElasticitycxx . . $ cpShapeSetElasticity(2eca2465ee202d41).(shape, 0.0f);
111 cpShapeSetFrictioncxx . . $ cpShapeSetFriction(2eca2465ee202d41).(shape, 0.4f);
112 }
113
114 return space;
115 }
116
117 static void
118 destroycxx . . $ destroy(728b9c9a69722ef8).(cpSpacecxx . . $ cpSpace# *space)
119 {
120 ChipmunkDemoFreeSpaceChildrencxx . . $ ChipmunkDemoFreeSpaceChildren(728b9c9a69722ef8).(space);
121 cpSpaceFreecxx . . $ cpSpaceFree(728b9c9a69722ef8).(space);
122 }
123
124 ChipmunkDemocxx . . $ ChipmunkDemo# Plinkcxx . . $ Plink. = {
125 "Plink",
126 1.0/60.0,
127 initcxx . . $ init(1f0082e822a7ce76).,
128 updatecxx . . $ update(fa66a0a48611083e).,
129 ChipmunkDemoDefaultDrawImplcxx . . $ ChipmunkDemoDefaultDrawImpl(728b9c9a69722ef8).,
130 destroycxx . . $ destroy(728b9c9a69722ef8).,
131 };