Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit b0090c8f4c7c59b3f39707b45b2df5f3ee2c1d84 @singpolyma committed Nov 16, 2008
Showing with 11,466 additions and 0 deletions.
  1. +7 −0 CMakeLists.txt
  2. +63 −0 Demo/CMakeLists.txt
  3. +124 −0 Demo/Demo1.c
  4. +100 −0 Demo/Demo2.c
  5. +108 −0 Demo/Demo3.c
  6. +114 −0 Demo/Demo4.c
  7. +124 −0 Demo/Demo5.c
  8. +143 −0 Demo/Demo6.c
  9. +262 −0 Demo/Demo7.c
  10. +141 −0 Demo/Demo8.c
  11. +1 −0 Demo/build.sh
  12. +419 −0 Demo/main.c
  13. +20 −0 LICENSE.txt
  14. BIN MSVCSolution/Chipmunk4MSVC2k3.ncb
  15. +34 −0 MSVCSolution/Chipmunk4MSVC2k3.sln
  16. BIN MSVCSolution/Chipmunk4MSVC2k3.suo
  17. +464 −0 MSVCSolution/Chipmunk4MSVC2k3/ChipmunkMSVC.vcproj
  18. +126 −0 MSVCSolution/glut.def
  19. +716 −0 MSVCSolution/glut.h
  20. BIN MSVCSolution/glut32.dll
  21. BIN MSVCSolution/glut32.lib
  22. +47 −0 README.txt
  23. +821 −0 docsrc/chipmunk-docs.textile
  24. +349 −0 docsrc/doc_dummy.rb
  25. +19 −0 docsrc/makedocs.rb
  26. +727 −0 macosx/Chipmunk.xcodeproj/project.pbxproj
  27. +24 −0 macosx/main-Info.plist
  28. +12 −0 ruby/configure
  29. +6 −0 ruby/debian/changelog
  30. +1 −0 ruby/debian/compat
  31. +14 −0 ruby/debian/control
  32. +42 −0 ruby/debian/copyright
  33. +1 −0 ruby/debian/docs
  34. +41 −0 ruby/debian/postinit
  35. +39 −0 ruby/debian/postrm
  36. +37 −0 ruby/debian/preinst
  37. +40 −0 ruby/debian/prerm
  38. +106 −0 ruby/debian/rules
  39. +1 −0 ruby/debian/shlibs.local
  40. +6 −0 ruby/extconf.rb
  41. +109 −0 ruby/rb_chipmunk.c
  42. +77 −0 ruby/rb_chipmunk.h
  43. +154 −0 ruby/rb_cpBB.c
  44. +239 −0 ruby/rb_cpBody.c
  45. +136 −0 ruby/rb_cpJoint.c
  46. +292 −0 ruby/rb_cpShape.c
  47. +330 −0 ruby/rb_cpSpace.c
  48. +250 −0 ruby/rb_cpVect.c
  49. +58 −0 src/CMakeLists.txt
  50. +69 −0 src/chipmunk.c
  51. +91 −0 src/chipmunk.h
  52. +263 −0 src/cpArbiter.c
  53. +85 −0 src/cpArbiter.h
  54. +114 −0 src/cpArray.c
  55. +45 −0 src/cpArray.h
  56. +46 −0 src/cpBB.c
  57. +53 −0 src/cpBB.h
  58. +180 −0 src/cpBody.c
  59. +132 −0 src/cpBody.h
  60. +390 −0 src/cpCollision.c
  61. +23 −0 src/cpCollision.h
  62. +219 −0 src/cpHashSet.c
  63. +79 −0 src/cpHashSet.h
  64. +553 −0 src/cpJoint.c
  65. +122 −0 src/cpJoint.h
  66. +139 −0 src/cpPolyShape.c
  67. +92 −0 src/cpPolyShape.h
  68. +244 −0 src/cpShape.c
  69. +141 −0 src/cpShape.h
  70. +530 −0 src/cpSpace.c
  71. +120 −0 src/cpSpace.h
  72. +455 −0 src/cpSpaceHash.c
  73. +100 −0 src/cpSpaceHash.h
  74. +63 −0 src/cpVect.c
  75. +106 −0 src/cpVect.h
  76. +68 −0 src/prime.h
@@ -0,0 +1,7 @@
+PROJECT(CHIPMUNK)
+
+SET(CMAKE_C_FLAGS_RELEASE "-O3 -ffast-math -std=gnu99")
+
+SUBDIRS(src Demo)
+
+SET (CMAKE_BUILD_TYPE Release)
@@ -0,0 +1,63 @@
+INCLUDE_DIRECTORIES(${CHIPMUNK_SOURCE_DIR}/src)
+
+INCLUDE(FindOpenGL)
+INCLUDE(FindGLUT)
+
+Find_Package ( OpenGL REQUIRED )
+Find_Package ( GLUT REQUIRED )
+
+#Declare any external dependencies that your project may have here.
+#examples include: ITK, VTK, JPEG, PNG, OpenGL, ZLIB, Perl, Java
+#If you're not sure what name to use, look in the Modules directory of your
+#cmake install and check that a file named Find(Package).cmake exists
+SET(Required_Packages
+#list packages here
+OpenGL GLUT
+)
+
+IF(GLUT_FOUND)
+ MESSAGE("libglut found. ${GLUT_INCLUDE_DIR} ${GLUT_LIBRARIES}")
+ LINK_DIRECTORIES(${GLUT_LIBRARIES})
+ELSE(GLUT_FOUND)
+ MESSAGE(FATAL_ERROR "libglut requested but not found. Please install freeglut")
+ENDIF(GLUT_FOUND)
+
+
+IF(OPENGL_FOUND)
+ MESSAGE("libGL found. ${OPENGL_INCLUDE_DIR} ${OPENGL_LIBRARIES}")
+ LINK_DIRECTORIES(${OPENGL_LIBRARIES})
+ELSE(OPENGL_FOUND)
+ MESSAGE(FATAL_ERROR "libGL requested but not found. Please install OpenGL libraries")
+ENDIF(OPENGL_FOUND)
+
+#Set any libraries that your project depends on.
+#examples: ITKCommon, VTKRendering, etc
+SET(Libraries
+#list libraries here
+GL glut
+)
+
+#LINK_DIRECTORIES(${CHIPMUNK_SOURCE_DIR}/build/source)
+
+#the following block of code is an example of how to build an executable in
+#cmake. Unmodified, it will add an executable called "MyExe" to the project.
+#MyExe will be built using the files MyClass.h and MyClass.cxx, and it will
+#be linked to all the libraries you specified above.
+#You can build more than one executable per project
+SET(CurrentExe "../chipmunk_demos")
+ADD_EXECUTABLE(${CurrentExe} Demo1.c Demo2.c Demo3.c Demo4.c Demo5.c Demo6.c Demo7.c main.c)
+
+TARGET_LINK_LIBRARIES(${CurrentExe} ${Libraries} chipmunk_static)
+
+#the following line is an example of how to add a test to your project.
+#Testname is the title for this particular test. ExecutableToRun is the
+#program which will be running this test. It can either be a part of this
+#project or an external executable. After that list any args that are needed
+#for this test. Include as many tests as you like. If your project doesn't have
+#any tests you can comment out or delete the following line.
+#ADD_TEST(Testname ExecutableToRun arg1 arg2 arg3)
+
+#Once you're done modifying this template, you should rename it to "CMakeLists.txt"
+SET (CMAKE_BUILD_TYPE Release)
+
+
@@ -0,0 +1,124 @@
+/* Copyright (c) 2007 Scott Lembcke
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "chipmunk.h"
+
+extern cpSpace *space;
+extern cpBody *staticBody;
+
+void demo1_update(int ticks)
+{
+ int steps = 2;
+ cpFloat dt = 1.0/60.0/(cpFloat)steps;
+
+ for(int i=0; i<steps; i++){
+ cpSpaceStep(space, dt);
+ }
+}
+
+int some_value = 42;
+
+static int
+collFunc(cpShape *a, cpShape *b, cpContact *contacts, int numContacts, cpFloat normal_coef, void *data)
+{
+ int *some_ptr = (int *)data;
+
+// Do various things with the contact information.
+// Make particle effects, estimate the impact damage from the relative velocities, etc.
+// for(int i=0; i<numContacts; i++)
+// printf("Collision at %s. (%d - %d) %d\n", cpvstr(contacts[i].p), a->collision_type, b->collision_type, *some_ptr);
+
+ // Returning 0 will cause the collision to be discarded. This allows you to do conditional collisions.
+ return 1;
+}
+
+void demo1_init(void)
+{
+ // Initialize a static body with infinite mass and moment of inertia
+ // to attach the static geometry to.
+ staticBody = cpBodyNew(INFINITY, INFINITY);
+
+ // Optional. Read the docs to see what this really does.
+ cpResetShapeIdCounter();
+
+ // Create a space and adjust some of it's parameters.
+ space = cpSpaceNew();
+ cpSpaceResizeStaticHash(space, 20.0, 999);
+ space->gravity = cpv(0, -100);
+
+ cpBody *body;
+ cpShape *shape;
+
+ // Vertexes we'll use to create a box.
+ // Note that the vertexes are in counterclockwise order.
+ int num = 4;
+ cpVect verts[] = {
+ cpv(-15,-15),
+ cpv(-15, 15),
+ cpv( 15, 15),
+ cpv( 15,-15),
+ };
+
+ // Create some segments around the edges of the screen.
+ shape = cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f);
+ shape->e = 1.0; shape->u = 1.0;
+ cpSpaceAddStaticShape(space, shape);
+
+ shape = cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f);
+ shape->e = 1.0; shape->u = 1.0;
+ cpSpaceAddStaticShape(space, shape);
+
+ shape = cpSegmentShapeNew(staticBody,cpv(-320,-240), cpv(320,-240), 0.0f);
+ shape->e = 1.0; shape->u = 1.0;
+ cpSpaceAddStaticShape(space, shape);
+
+ // Create the stair steps.
+ for(int i=0; i<50; i++){
+ int j = i + 1;
+ cpVect a = cpv(i*10 - 320, i*-10 + 240);
+ cpVect b = cpv(j*10 - 320, i*-10 + 240);
+ cpVect c = cpv(j*10 - 320, j*-10 + 240);
+
+ shape = cpSegmentShapeNew(staticBody, a, b, 0.0f);
+ shape->e = 1.0; shape->u = 1.0;
+ cpSpaceAddStaticShape(space, shape);
+
+ shape = cpSegmentShapeNew(staticBody, b, c, 0.0f);
+ shape->e = 1.0; shape->u = 1.0;
+ cpSpaceAddStaticShape(space, shape);
+ }
+
+ // Create a box and initialize some of its parameters.
+ body = cpBodyNew(1.0, cpMomentForPoly(1.0, num, verts, cpvzero));
+ body->p = cpv(-280, 240);
+ cpSpaceAddBody(space, body);
+ shape = cpPolyShapeNew(body, num, verts, cpvzero);
+ shape->e = 0.0; shape->u = 1.5;
+ shape->collision_type = 1;
+ cpSpaceAddShape(space, shape);
+
+ // Add a collision callback between objects of the default type and the box.
+ cpSpaceAddCollisionPairFunc(space, 1, 0, &collFunc, &some_value);
+}
@@ -0,0 +1,100 @@
+/* Copyright (c) 2007 Scott Lembcke
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "chipmunk.h"
+
+#define SLEEP_TICKS 16
+
+extern cpSpace *space;
+extern cpBody *staticBody;
+
+void demo2_update(int ticks)
+{
+ int steps = 1;
+ cpFloat dt = 1.0/60.0/(cpFloat)steps;
+
+ for(int i=0; i<steps; i++){
+ cpSpaceStep(space, dt);
+ }
+}
+
+void demo2_init(void)
+{
+ staticBody = cpBodyNew(INFINITY, INFINITY);
+
+ cpResetShapeIdCounter();
+
+ space = cpSpaceNew();
+ space->iterations = 20;
+ cpSpaceResizeStaticHash(space, 40.0, 1000);
+ cpSpaceResizeActiveHash(space, 40.0, 1000);
+ space->gravity = cpv(0, -100);
+
+ cpBody *body;
+ cpShape *shape;
+
+ int num = 4;
+ cpVect verts[] = {
+ cpv(-15,-15),
+ cpv(-15, 15),
+ cpv( 15, 15),
+ cpv( 15,-15),
+ };
+
+ // Create segments around the edge of the screen.
+ shape = cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f);
+ shape->e = 1.0; shape->u = 1.0;
+ cpSpaceAddStaticShape(space, shape);
+
+ shape = cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f);
+ shape->e = 1.0; shape->u = 1.0;
+ cpSpaceAddStaticShape(space, shape);
+
+ shape = cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f);
+ shape->e = 1.0; shape->u = 1.0;
+ cpSpaceAddStaticShape(space, shape);
+
+ // Add lots of boxes.
+ for(int i=0; i<14; i++){
+ for(int j=0; j<=i; j++){
+ body = cpBodyNew(1.0, cpMomentForPoly(1.0, num, verts, cpvzero));
+ body->p = cpv(j*32 - i*16, 300 - i*32);
+ cpSpaceAddBody(space, body);
+ shape = cpPolyShapeNew(body, num, verts, cpvzero);
+ shape->e = 0.0; shape->u = 0.8;
+ cpSpaceAddShape(space, shape);
+ }
+ }
+
+ // Add a ball to make things more interesting
+ cpFloat radius = 15.0;
+ body = cpBodyNew(10.0, cpMomentForCircle(10.0, 0.0, radius, cpvzero));
+ body->p = cpv(0, -240 + radius);
+// body->v = cpv(10, 0);
+ cpSpaceAddBody(space, body);
+ shape = cpCircleShapeNew(body, radius, cpvzero);
+ shape->e = 0.0; shape->u = 0.9;
+ cpSpaceAddShape(space, shape);
+}
Oops, something went wrong.

0 comments on commit b0090c8

Please sign in to comment.