chipmunk 5.2.2 → 5.3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/LICENSE +21 -19
  2. data/README +67 -60
  3. data/Rakefile +85 -50
  4. data/ext/chipmunk/extconf.rb +42 -35
  5. data/ext/chipmunk/rb_chipmunk.c +250 -125
  6. data/ext/chipmunk/rb_chipmunk.h +105 -96
  7. data/ext/chipmunk/rb_cpArbiter.c +253 -225
  8. data/ext/chipmunk/rb_cpBB.c +210 -174
  9. data/ext/chipmunk/rb_cpBody.c +504 -347
  10. data/ext/chipmunk/rb_cpConstraint.c +336 -346
  11. data/ext/chipmunk/rb_cpShape.c +433 -455
  12. data/ext/chipmunk/rb_cpSpace.c +711 -544
  13. data/ext/chipmunk/rb_cpVect.c +346 -321
  14. data/lib/chipmunk.rb +183 -30
  15. metadata +12 -66
  16. data/ext/chipmunk/chipmunk.c +0 -105
  17. data/ext/chipmunk/cpArbiter.c +0 -274
  18. data/ext/chipmunk/cpArray.c +0 -128
  19. data/ext/chipmunk/cpBB.c +0 -47
  20. data/ext/chipmunk/cpBody.c +0 -188
  21. data/ext/chipmunk/cpCollision.c +0 -391
  22. data/ext/chipmunk/cpConstraint.c +0 -54
  23. data/ext/chipmunk/cpDampedRotarySpring.c +0 -106
  24. data/ext/chipmunk/cpDampedSpring.c +0 -117
  25. data/ext/chipmunk/cpGearJoint.c +0 -114
  26. data/ext/chipmunk/cpGrooveJoint.c +0 -138
  27. data/ext/chipmunk/cpHashSet.c +0 -253
  28. data/ext/chipmunk/cpPinJoint.c +0 -117
  29. data/ext/chipmunk/cpPivotJoint.c +0 -114
  30. data/ext/chipmunk/cpPolyShape.c +0 -241
  31. data/ext/chipmunk/cpRatchetJoint.c +0 -128
  32. data/ext/chipmunk/cpRotaryLimitJoint.c +0 -122
  33. data/ext/chipmunk/cpShape.c +0 -400
  34. data/ext/chipmunk/cpSimpleMotor.c +0 -99
  35. data/ext/chipmunk/cpSlideJoint.c +0 -131
  36. data/ext/chipmunk/cpSpace.c +0 -899
  37. data/ext/chipmunk/cpSpaceHash.c +0 -541
  38. data/ext/chipmunk/cpVect.c +0 -71
  39. data/ext/chipmunk/include/chipmunk/chipmunk.h +0 -148
  40. data/ext/chipmunk/include/chipmunk/chipmunk_ffi.h +0 -42
  41. data/ext/chipmunk/include/chipmunk/chipmunk_types.h +0 -80
  42. data/ext/chipmunk/include/chipmunk/chipmunk_unsafe.h +0 -54
  43. data/ext/chipmunk/include/chipmunk/constraints/cpConstraint.h +0 -92
  44. data/ext/chipmunk/include/chipmunk/constraints/cpDampedRotarySpring.h +0 -46
  45. data/ext/chipmunk/include/chipmunk/constraints/cpDampedSpring.h +0 -53
  46. data/ext/chipmunk/include/chipmunk/constraints/cpGearJoint.h +0 -41
  47. data/ext/chipmunk/include/chipmunk/constraints/cpGrooveJoint.h +0 -44
  48. data/ext/chipmunk/include/chipmunk/constraints/cpPinJoint.h +0 -43
  49. data/ext/chipmunk/include/chipmunk/constraints/cpPivotJoint.h +0 -42
  50. data/ext/chipmunk/include/chipmunk/constraints/cpRatchetJoint.h +0 -40
  51. data/ext/chipmunk/include/chipmunk/constraints/cpRotaryLimitJoint.h +0 -39
  52. data/ext/chipmunk/include/chipmunk/constraints/cpSimpleMotor.h +0 -37
  53. data/ext/chipmunk/include/chipmunk/constraints/cpSlideJoint.h +0 -44
  54. data/ext/chipmunk/include/chipmunk/constraints/util.h +0 -116
  55. data/ext/chipmunk/include/chipmunk/cpArbiter.h +0 -136
  56. data/ext/chipmunk/include/chipmunk/cpArray.h +0 -46
  57. data/ext/chipmunk/include/chipmunk/cpBB.h +0 -74
  58. data/ext/chipmunk/include/chipmunk/cpBody.h +0 -160
  59. data/ext/chipmunk/include/chipmunk/cpCollision.h +0 -23
  60. data/ext/chipmunk/include/chipmunk/cpHashSet.h +0 -82
  61. data/ext/chipmunk/include/chipmunk/cpPolyShape.h +0 -103
  62. data/ext/chipmunk/include/chipmunk/cpShape.h +0 -174
  63. data/ext/chipmunk/include/chipmunk/cpSpace.h +0 -180
  64. data/ext/chipmunk/include/chipmunk/cpSpaceHash.h +0 -109
  65. data/ext/chipmunk/include/chipmunk/cpVect.h +0 -157
  66. data/ext/chipmunk/prime.h +0 -68
  67. data/lib/chipmunk/version.rb +0 -3
data/LICENSE CHANGED
@@ -1,20 +1,22 @@
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.
1
+ /* Copyright (c) 2007 Scott Lembcke
2
+ * Copyright (c) 2010-2011 John Mair
3
+ * Copyright (c) 2010-2011 Beoran (beoran@rubyforge.org)
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
20
22
  */
data/README CHANGED
@@ -1,60 +1,67 @@
1
- Ruby Bindings to Chipmunk Physics Version 5.2.0
2
-
3
- (C) Scott Lembcke, Beoran and John Mair (banisterfiend)
4
-
5
- IMPORTANT NOTICE:
6
- These are bindings for MRI Ruby 1.8.x and 1.9.x to Chipmunk version 5.2.0
7
-
8
- (1) 1/10/09 Cross-Platform Gem built by John Mair (banisterfiend)
9
- * Just go: gem install chipmunk
10
-
11
- (2) Patched for 1.9.1 by Beoran (beoran@rubyforge.org)
12
-
13
- (3) How to build the gems? (maintainers only)
14
- * Install rake-compiler (http://github.com/luislavena/rake-compiler)
15
- * Install 1.9.1 and 1.8.6 mingw ruby versions (instructions above)
16
- * Type: rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.1
17
- * Upload new gems to rubyforge and gemcutter.
18
-
19
- FORUM:
20
-
21
- http://www.slembcke.net/forums
22
-
23
- CONTACT:
24
- slembcke@gmail.com (also on Google Talk) for Chipmunk
25
- beoran@rubyforge.org for these bindings
26
-
27
- ABOUT:
28
- Chipmunk is a simple, lightweight and fast 2D rigid body physics library
29
- written in C. It's licensed under the unrestrictive, OSI approved MIT license. My aim is to give 2D developers access the same quality of physics you find in newer 3D games. I hope you enjoy using Chipmunk, and please consider donating to help make it worth our time to continue to support Chipmunk with great new features.
30
-
31
- These bindings are intened to as an alternative for the chipmunk-ffi bindings when performance is of the utmost importance, as it may be for games. The intent is for it to be source code compatibe with the ffi bindings. If you have any problems with these bindings, please contact the maintainer at beoran@rubyforge.org.
32
-
33
- CONTRACTING:
34
- Howling Moon Software (Slembke's company) is available for contracting if you want to make the physics in your game really stand out. Feel free to contact them through their webpage: http://howlingmoonsoftware.com/contracting.php
35
-
36
- CHANGES SINCE 4.x:
37
- * Brand new Joint/Constraint API: New constraints can be added easily and are much more flexible than the old joint system.
38
- * Efficient Segment Queries - Like raycasting, but with line segments.
39
- * Brand new collision callback API: Collision begin/separate events, API for removal of objects within callbacks, more programable control over collision handling.
40
-
41
- CHANGES SINCE RELEASE 3:
42
-
43
- * Rational versioning scheme: (major.minor.build) Small changes
44
- increment the build number. Significant changes that don't affect
45
- backwards compatibility increment the minor number. Major changes
46
- that will break backwards compatibility will increment the major
47
- number.
48
-
49
- * Optimizations: Speed increases of 5-10% should be common.
50
-
51
- * Groove Joint: Similar to a pivot joint, but one of the anchors is
52
- on a linear slide instead of being fixed.
53
-
54
- * Comments/cleanup. The code should be much more readable now.
55
-
56
- * Official build paths for working on Linux and MSVC.
57
-
58
-
59
-
60
-
1
+ Ruby Bindings to Chipmunk Physics Version 5.3.4
2
+
3
+ (C) Scott Lembcke, Beoran and John Mair (banisterfiend)
4
+
5
+ IMPORTANT NOTICE:
6
+ These are bindings for MRI Ruby 1.8.x and 1.9.x to Chipmunk version 5.3.4
7
+
8
+ (1) 1/10/09 Cross-Platform Gem built by John Mair (banisterfiend)
9
+ * Just go: gem install chipmunk
10
+
11
+ FORUM:
12
+ http://www.slembcke.net/forums
13
+
14
+ CONTACT:
15
+ slembcke@gmail.com (also on Google Talk) for Chipmunk.
16
+ beoran@rubyforge.org for these bindings to Ruby.
17
+
18
+ ABOUT CHIPMUNK:
19
+ Chipmunk is a simple, lightweight and fast 2D rigid body physics library
20
+ written in C by Slembcke. It's licensed under the unrestrictive, OSI approved
21
+ MIT license.
22
+
23
+ ABOUT THESE RUBY BINDINGS:
24
+ Although chipmunk comes with ruby bindings, they are not always up to date
25
+ with regards to the functionality of the C library, and historically, they
26
+ have been incompatible with recent versions of Ruby.
27
+
28
+ Therefore, these bindings are intended to as an enhanced version with more
29
+ features and better compatibility with recent versions of Ruby. They are also
30
+ intended to be an alternative to the chipmunk-ffi bindings when performance
31
+ is of the utmost importance, as it may be for games.
32
+
33
+ The intent is for these bindings to be mostly source code compatible with both
34
+ Slembcke's and ffi's bindings. Main exceptions are where I dislike either API.
35
+ In that case, I made an API that is pleasing to myself, and similar in naming
36
+ to the C API adjusted to ruby conventions. If you have any problems with these bindings, please contact the maintainer at beoran@rubyforge.org.
37
+
38
+ INCOMPATIBILITIES:
39
+ There are no bindings to SpaceHash since I fail to see the use of it, but
40
+ if someone is using them, I'll probably implement them.
41
+
42
+ CONTRACTING:
43
+ Howling Moon Software (Slembke's company) is available for contracting if you
44
+ want to make the physics in your game really stand out. Feel free to contact
45
+ them through their webpage: http://howlingmoonsoftware.com/contracting.php
46
+
47
+ TODO:
48
+ * More functionality.
49
+ * Specs for the new functionality I've wrapped and will wrap.
50
+ * Better documentation, perhaps based on C API documentation.
51
+
52
+
53
+ INFO FOR MAINTAINERS:
54
+
55
+ (1) 1/10/09 Cross-Platform Gem built by John Mair (banisterfiend)
56
+ * Just go: gem install chipmunk
57
+
58
+ (2) Patched for 1.9.1 by Beoran (beoran@rubyforge.org)
59
+
60
+ (3) How to build the gems? (maintainers only)
61
+ * Install rake-compiler (http://github.com/luislavena/rake-compiler)
62
+ * Install 1.9.1 and 1.8.6 mingw ruby versions (instructions above)
63
+ * Type: rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.1
64
+ * Upload new gems to rubyforge and gemcutter.
65
+
66
+
67
+
data/Rakefile CHANGED
@@ -1,50 +1,85 @@
1
- # Rakefile added by John Mair (banisterfiend)
2
-
3
- require 'rake/gempackagetask'
4
- require 'rake/clean'
5
- require 'lib/chipmunk/version.rb'
6
-
7
- dlext = Config::CONFIG['DLEXT']
8
-
9
- CLEAN.include("ext/**/*.#{dlext}", "ext/**/.log", "ext/**/.o", "ext/**/*~", "ext/**/*#*", "ext/**/.obj", "ext/**/.def", "ext/**/.pdb")
10
- CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o", "doc/**")
11
-
12
-
13
- def apply_spec_defaults(s)
14
- s.name = "chipmunk"
15
- s.summary = "ruby bindings for the chipmunk 5.1.0 physics engine"
16
- s.description = s.summary
17
- s.version = Chipmunk::VERSION
18
- s.author = "Scott Lembcke, Beoran, John Mair (banisterfiend)"
19
- s.email = 'beoran@rubyforge.com'
20
- s.date = Time.now.strftime '%Y-%m-%d'
21
- s.require_path = 'lib'
22
- s.homepage = "http://code.google.com/p/chipmunk-physics/"
23
- end
24
-
25
-
26
- # common tasks
27
- task :compile => :clean
28
-
29
- # spec = Gem::Specification.new do |s|
30
- # apply_spec_defaults(s)
31
- # s.platform = 'i386-mswin32'
32
- # s.files = ["Rakefile", "README", "LICENSE", "lib/chipmunk.rb", "lib/1.8/chipmunk.#{dlext}", "lib/1.9/chipmunk.#{dlext}", "lib/chipmunk/version.rb"]
33
- # end
34
-
35
-
36
-
37
-
38
-
39
- spec = Gem::Specification.new do |s|
40
- apply_spec_defaults(s)
41
- s.platform = Gem::Platform::RUBY
42
- s.extensions = FileList["ext/**/extconf.rb"]
43
- s.files = ["Rakefile", "README", "LICENSE", "lib/chipmunk.rb", "lib/chipmunk/version.rb"] +
44
- FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
45
- end
46
-
47
- Rake::GemPackageTask.new(spec) do |pkg|
48
- pkg.need_zip = false
49
- pkg.need_tar = false
50
- end
1
+ # Rakefile added by John Mair (banisterfiend)
2
+
3
+ require 'rake/gempackagetask'
4
+ require 'rake/clean'
5
+
6
+ begin
7
+ require 'rake/extensiontask'
8
+ rescue LoadError
9
+ puts "rake-compiler not found! Please install the rake-compiler gem!"
10
+ # `/bin/bash -l -c "gem1.9 install rake-compiler"`
11
+ # require 'rake/extensiontask'
12
+ # puts "...done!"
13
+ end
14
+
15
+ CHIPMUNK_VERSION = "5.3.4.0"
16
+
17
+ dlext = Config::CONFIG['DLEXT']
18
+
19
+ CLEAN.include("ext/**/*.#{dlext}", "ext/**/.log", "ext/**/.o", "ext/**/*~", "ext/**/*#*", "ext/**/.obj", "ext/**/.def", "ext/**/.pdb")
20
+ CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o", "doc/**")
21
+
22
+
23
+ def apply_spec_defaults(s)
24
+ s.name = "chipmunk"
25
+ s.summary = "Enhanced ruby bindings for the chipmunk 5.3.4 game physics engine."
26
+ s.description = s.summary + " "
27
+ s.version = CHIPMUNK_VERSION
28
+ s.author = "Scott Lembcke, Beoran, John Mair (banisterfiend)"
29
+ s.email = 'beoran@rubyforge.com'
30
+ s.date = Time.now.strftime '%Y-%m-%d'
31
+ s.require_path = 'lib'
32
+ s.homepage = "https://github.com/beoran/chipmunk"
33
+ end
34
+
35
+
36
+ # common tasks
37
+ task :compile => :clean
38
+
39
+ # platform dependent tasks
40
+ if RUBY_PLATFORM =~ /darwin/
41
+
42
+ spec = Gem::Specification.new do |s|
43
+ apply_spec_defaults(s)
44
+ s.platform = Gem::Platform::CURRENT
45
+ s.files = ["Rakefile", "README", "LICENSE", "lib/chipmunk.rb", "lib/1.8/chipmunk.#{dlext}", "lib/1.9/chipmunk.#{dlext}"]
46
+ end
47
+
48
+ Rake::ExtensionTask.new('chipmunk') do |ext|
49
+ ext.ext_dir = "ext"
50
+ ext.lib_dir = "lib/#{RUBY_VERSION[0..2]}"
51
+ ext.config_script = 'extconf.rb'
52
+ ext.config_options << 'macosx'
53
+ end
54
+
55
+ task :compile_multi => :clean do
56
+ `/bin/bash -l -c "rvm 1.8.6,1.9.1 rake compile"`
57
+ end
58
+
59
+ task :gem => :compile_multi
60
+ Rake::GemPackageTask.new(spec) do |pkg|
61
+ pkg.need_zip = false
62
+ pkg.need_tar = false
63
+ end
64
+
65
+ else
66
+
67
+ spec = Gem::Specification.new do |s|
68
+ apply_spec_defaults(s)
69
+ s.platform = Gem::Platform::RUBY
70
+ s.extensions = FileList["ext/**/extconf.rb"]
71
+ s.files = ["Rakefile", "README", "LICENSE", "lib/chipmunk.rb"] +
72
+ FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
73
+ end
74
+
75
+ Rake::ExtensionTask.new('chipmunk', spec) do |ext|
76
+ ext.config_script = 'extconf.rb'
77
+ ext.cross_compile = true
78
+ ext.cross_platform = 'i386-mswin32'
79
+ end
80
+
81
+ Rake::GemPackageTask.new(spec) do |pkg|
82
+ pkg.need_zip = false
83
+ pkg.need_tar = false
84
+ end
85
+ end
@@ -1,35 +1,42 @@
1
- require 'mkmf'
2
-
3
- #dir_config('chipmunk')
4
-
5
- # CHIPMUNK_HEADER = 'chipmunk.h'
6
- # CHIPMUNK_NAME = 'chipmunk'
7
- # CHIPMUNK_FUNCTION = 'cpMomentForPoly'
8
- # CHIPMUNK_INCLUDE = ['/usr/include',
9
- # '/usr/local/include',
10
- # '/usr/include/chipmunk',
11
- # '/usr/local/include/chipmunk'
12
- # ]
13
- # CHIPMUNK_LIBDIR = ['/usr/lib', '/usr/local/lib']
14
-
15
- # find_header(CHIPMUNK_HEADER, *CHIPMUNK_INCLUDE)
16
- # find_library(CHIPMUNK_NAME, CHIPMUNK_FUNCTION, *CHIPMUNK_LIBDIR)
17
-
18
- =begin
19
- unless have_library('chipmunk', 'cpMomentForPoly')
20
- raise "Could not link to Chipmunk library!"
21
- end
22
-
23
- have_header('chipmunk.h', include_dirs)
24
- =end
25
-
26
- if ARGV[0] == "macosx"
27
- $CFLAGS += ' -arch ppc -arch i386 -arch x86_64'
28
- $LDFLAGS += ' -arch x86_64 -arch i386 -arch ppc'
29
- end
30
-
31
- $CFLAGS += ' -std=gnu99 -ffast-math'
32
- $CFLAGS += ' -Iinclude/chipmunk/'
33
- $CFLAGS += ' -DNDEBUG'
34
- create_makefile('chipmunk')
35
-
1
+ require 'mkmf'
2
+
3
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
4
+
5
+ dir_config('chipmunk')
6
+
7
+ MINGW = '/usr/i586-mingw32msvc'
8
+ CHIPMUNK_HEADER = 'chipmunk.h'
9
+ CHIPMUNK_NAME = 'chipmunk'
10
+ CHIPMUNK_FUNCTION = 'cpMomentForPoly'
11
+ CHIPMUNK_INCLUDE = ['/usr/include',
12
+ File.join(MINGW, 'include'),
13
+ File.join(MINGW, 'include', 'chipmunk'),
14
+ '/usr/local/include',
15
+ '/usr/include/chipmunk',
16
+ '/usr/local/include/chipmunk'
17
+ ]
18
+ CHIPMUNK_LIBDIR = ['/usr/lib',
19
+ File.join(MINGW, 'lib'),
20
+ '/usr/local/lib']
21
+
22
+ unless find_header(CHIPMUNK_HEADER, *CHIPMUNK_INCLUDE)
23
+ raise "Could not find Chipmunk headers!"
24
+ end
25
+
26
+
27
+ unless find_library(CHIPMUNK_NAME, CHIPMUNK_FUNCTION, *CHIPMUNK_LIBDIR)
28
+ raise "Could not link to Chipmunk library!"
29
+ end
30
+
31
+ =begin
32
+ have_header('chipmunk.h', include_dirs)
33
+ =end
34
+
35
+ if ARGV[0] == "macosx"
36
+ $CFLAGS += ' -arch ppc -arch i386 -arch x86_64'
37
+ $LDFLAGS += ' -arch x86_64 -arch i386 -arch ppc'
38
+ end
39
+
40
+ $CFLAGS += ' -std=gnu99 -ffast-math'
41
+ create_makefile('chipmunk')
42
+
@@ -1,125 +1,250 @@
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 <stdlib.h>
23
-
24
- #include "chipmunk.h"
25
-
26
- #include "ruby.h"
27
- #include "rb_chipmunk.h"
28
-
29
- VALUE m_Chipmunk;
30
-
31
- ID id_parent;
32
-
33
- static VALUE
34
- rb_get_cp_bias_coef(VALUE self)
35
- {
36
- return rb_float_new(cp_bias_coef);
37
- }
38
-
39
- static VALUE
40
- rb_set_cp_bias_coef(VALUE self, VALUE num)
41
- {
42
- cp_bias_coef = NUM2DBL(num);
43
- return num;
44
- }
45
-
46
- static VALUE
47
- rb_get_cp_collision_slop(VALUE self)
48
- {
49
- return rb_float_new(cp_collision_slop);
50
- }
51
-
52
- static VALUE
53
- rb_set_cp_collision_slop(VALUE self, VALUE num)
54
- {
55
- cp_collision_slop = NUM2DBL(num);
56
- return num;
57
- }
58
-
59
- static VALUE
60
- rb_momentForCircle(VALUE self, VALUE m, VALUE r1, VALUE r2, VALUE offset)
61
- {
62
- cpFloat i = cpMomentForCircle(NUM2DBL(m), NUM2DBL(r1), NUM2DBL(r2), *VGET(offset));
63
- return rb_float_new(i);
64
- }
65
-
66
- static VALUE
67
- rb_momentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset)
68
- {
69
- Check_Type(arr, T_ARRAY);
70
- int numVerts = RARRAY_LEN(arr);
71
- VALUE *ary_ptr = RARRAY_PTR(arr);
72
- cpVect verts[numVerts];
73
-
74
- for(int i=0; i<numVerts; i++)
75
- verts[i] = *VGET(ary_ptr[i]);
76
-
77
- cpFloat inertia = cpMomentForPoly(NUM2DBL(m), numVerts, verts, *VGET(offset));
78
- return rb_float_new(inertia);
79
- }
80
-
81
- static VALUE
82
- rb_momentForSegment(VALUE self, VALUE m, VALUE a, VALUE b)
83
- {
84
- cpFloat i = cpMomentForSegment(NUM2DBL(m), *VGET(a), *VGET(b));
85
- return rb_float_new(i);
86
- }
87
-
88
-
89
- void
90
- Init_chipmunk(void)
91
- {
92
- id_parent = rb_intern("parent");
93
-
94
- cpInitChipmunk();
95
-
96
- rb_eval_string("Float::INFINITY = 1.0/0.0");
97
-
98
- m_Chipmunk = rb_define_module("CP");
99
- rb_define_module_function(m_Chipmunk, "bias_coef",
100
- rb_get_cp_bias_coef, 0);
101
- rb_define_module_function(m_Chipmunk, "bias_coef=",
102
- rb_set_cp_bias_coef, 1);
103
- rb_define_module_function(m_Chipmunk, "collision_slop",
104
- rb_get_cp_collision_slop, 0);
105
- rb_define_module_function(m_Chipmunk, "collision_slop=",
106
- rb_set_cp_collision_slop, 1);
107
- rb_define_module_function(m_Chipmunk, "moment_for_circle",
108
- rb_momentForCircle, 4);
109
- rb_define_module_function(m_Chipmunk, "moment_for_poly",
110
- rb_momentForPoly, 3);
111
- rb_define_module_function(m_Chipmunk, "moment_for_segment",
112
- rb_momentForSegment, 3);
113
- rb_define_const(m_Chipmunk, "INFINITY", rb_float_new(INFINITY));
114
- rb_define_const(m_Chipmunk, "VERSION" ,
115
- rb_str_new2(cpVersionString));
116
-
117
- Init_cpVect();
118
- Init_cpArbiter();
119
- Init_cpBB();
120
- Init_cpBody();
121
- Init_cpShape();
122
- Init_cpConstraint();
123
- Init_cpSpace();
124
-
125
- }
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 <stdlib.h>
23
+
24
+ #include "chipmunk.h"
25
+
26
+ #include "ruby.h"
27
+ #include "rb_chipmunk.h"
28
+
29
+ VALUE m_Chipmunk;
30
+
31
+ ID id_parent;
32
+
33
+ static VALUE
34
+ rb_get_cp_bias_coef(VALUE self) {
35
+ return rb_float_new(cp_bias_coef);
36
+ }
37
+
38
+ static VALUE
39
+ rb_set_cp_bias_coef(VALUE self, VALUE num) {
40
+ cp_bias_coef = NUM2DBL(num);
41
+ return num;
42
+ }
43
+
44
+ static VALUE
45
+ rb_get_cp_collision_slop(VALUE self) {
46
+ return rb_float_new(cp_collision_slop);
47
+ }
48
+
49
+ static VALUE
50
+ rb_set_cp_collision_slop(VALUE self, VALUE num) {
51
+ cp_collision_slop = NUM2DBL(num);
52
+ return num;
53
+ }
54
+
55
+ static VALUE
56
+ rb_set_cp_contact_persistence(VALUE self, VALUE num) {
57
+ cp_contact_persistence = NUM2DBL(num);
58
+ return num;
59
+ }
60
+
61
+ static VALUE
62
+ rb_get_cp_contact_persistence(VALUE self) {
63
+ return rb_float_new(cp_contact_persistence);
64
+ }
65
+
66
+
67
+ static VALUE
68
+ rb_cpMomentForCircle(VALUE self, VALUE m, VALUE r1, VALUE r2, VALUE offset)
69
+ {
70
+ cpFloat i = cpMomentForCircle(NUM2DBL(m), NUM2DBL(r1), NUM2DBL(r2), *VGET(offset));
71
+ return rb_float_new(i);
72
+ }
73
+
74
+ static VALUE
75
+ rb_cpMomentForSegment(VALUE self, VALUE m, VALUE v1, VALUE v2)
76
+ {
77
+ cpFloat i = cpMomentForSegment(NUM2DBL(m), *VGET(v1), *VGET(v2));
78
+ return rb_float_new(i);
79
+ }
80
+
81
+ static VALUE
82
+ rb_cpMomentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset)
83
+ {
84
+ Check_Type(arr, T_ARRAY);
85
+ int numVerts = RARRAY_LEN(arr);
86
+ VALUE *ary_ptr = RARRAY_PTR(arr);
87
+ cpVect verts[numVerts];
88
+
89
+ for(int i=0; i<numVerts; i++)
90
+ verts[i] = *VGET(ary_ptr[i]);
91
+
92
+ cpFloat inertia = cpMomentForPoly(NUM2DBL(m), numVerts, verts, *VGET(offset));
93
+ return rb_float_new(inertia);
94
+ }
95
+
96
+ static VALUE
97
+ rb_cpMomentForBox(VALUE self, VALUE m, VALUE w, VALUE h) {
98
+ cpFloat i = cpMomentForBox(NUM2DBL(m), NUM2DBL(w), NUM2DBL(h));
99
+ return rb_float_new(i);
100
+ }
101
+
102
+ static VALUE
103
+ rb_cpAreaForCircle(VALUE self, VALUE r1, VALUE r2)
104
+ {
105
+ cpFloat i = cpAreaForCircle(NUM2DBL(r1), NUM2DBL(r2));
106
+ return rb_float_new(i);
107
+ }
108
+
109
+ static VALUE
110
+ rb_cpAreaForSegment(VALUE self, VALUE v1, VALUE v2, VALUE r)
111
+ {
112
+ cpFloat i = cpAreaForSegment(*VGET(v1), *VGET(v2), NUM2DBL(r));
113
+ return rb_float_new(i);
114
+ }
115
+
116
+ static VALUE
117
+ rb_cpAreaForPoly(VALUE self, VALUE arr)
118
+ {
119
+ Check_Type(arr, T_ARRAY);
120
+ int numVerts = RARRAY_LEN(arr);
121
+ VALUE *ary_ptr = RARRAY_PTR(arr);
122
+ cpVect verts[numVerts];
123
+
124
+ for(int i=0; i<numVerts; i++)
125
+ verts[i] = *VGET(ary_ptr[i]);
126
+
127
+ cpFloat area = cpAreaForPoly(numVerts, verts);
128
+ return rb_float_new(area);
129
+ }
130
+
131
+ static VALUE
132
+ rb_cpAreaForBox(VALUE self, VALUE w, VALUE h) {
133
+ cpFloat i = NUM2DBL(w) * NUM2DBL(h);
134
+ return rb_float_new(i);
135
+ }
136
+
137
+
138
+ static VALUE rb_cpfclamp(VALUE self, VALUE f, VALUE min, VALUE max) {
139
+ cpFloat result = cpfclamp(NUM2DBL(f), NUM2DBL(min), NUM2DBL(max));
140
+ return rb_float_new(result);
141
+ }
142
+
143
+ static VALUE rb_cpflerp(VALUE self, VALUE f1, VALUE f2, VALUE t) {
144
+ cpFloat result = cpflerp(NUM2DBL(f1), NUM2DBL(f2), NUM2DBL(t));
145
+ return rb_float_new(result);
146
+ }
147
+
148
+ static VALUE rb_cpflerpconst(VALUE self, VALUE f1, VALUE f2, VALUE d) {
149
+ cpFloat result = cpflerpconst(NUM2DBL(f1), NUM2DBL(f2), NUM2DBL(d));
150
+ return rb_float_new(result);
151
+ }
152
+
153
+ static VALUE
154
+ rb_cpCentroidForPoly(VALUE self, VALUE arr)
155
+ {
156
+ Check_Type(arr, T_ARRAY);
157
+ int numVerts = RARRAY_LEN(arr);
158
+ VALUE *ary_ptr = RARRAY_PTR(arr);
159
+ cpVect verts[numVerts];
160
+
161
+ for(int i=0; i<numVerts; i++)
162
+ verts[i] = *VGET(ary_ptr[i]);
163
+
164
+ return VNEW(cpCentroidForPoly(numVerts, verts));
165
+ }
166
+
167
+ static VALUE
168
+ rb_cpRecenterPoly(VALUE self, VALUE arr)
169
+ {
170
+ Check_Type(arr, T_ARRAY);
171
+ int numVerts = RARRAY_LEN(arr);
172
+ VALUE *ary_ptr = RARRAY_PTR(arr);
173
+ cpVect verts[numVerts];
174
+
175
+ for(int i=0; i<numVerts; i++)
176
+ verts[i] = *VGET(ary_ptr[i]);
177
+
178
+ cpRecenterPoly(numVerts, verts);
179
+
180
+ for(int i=0; i<numVerts; i++)
181
+ ary_ptr[i] = VNEW(verts[i]);
182
+ return arr;
183
+ }
184
+
185
+
186
+
187
+
188
+ void
189
+ Init_chipmunk(void)
190
+ {
191
+ id_parent = rb_intern("parent");
192
+
193
+ cpInitChipmunk();
194
+
195
+
196
+
197
+ m_Chipmunk = rb_define_module("CP");
198
+ rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0);
199
+ rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1);
200
+ rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0);
201
+ rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1);
202
+ rb_define_module_function(m_Chipmunk, "contact_persistence", rb_get_cp_contact_persistence, 0);
203
+ rb_define_module_function(m_Chipmunk, "contact_persistence=", rb_set_cp_contact_persistence, 1);
204
+
205
+
206
+
207
+ rb_define_module_function(m_Chipmunk, "clamp", rb_cpfclamp, 3);
208
+ rb_define_module_function(m_Chipmunk, "flerp", rb_cpflerp, 3);
209
+ rb_define_module_function(m_Chipmunk, "flerpconst", rb_cpflerpconst, 3);
210
+
211
+ rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_cpMomentForCircle, 4);
212
+ rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_cpMomentForPoly, 3);
213
+ rb_define_module_function(m_Chipmunk, "moment_for_segment", rb_cpMomentForSegment, 3);
214
+ rb_define_module_function(m_Chipmunk, "moment_for_box", rb_cpMomentForBox, 3);
215
+
216
+ rb_define_module_function(m_Chipmunk, "circle_moment", rb_cpMomentForCircle, 4);
217
+ rb_define_module_function(m_Chipmunk, "poly_moment", rb_cpMomentForPoly, 3);
218
+ rb_define_module_function(m_Chipmunk, "segment_moment", rb_cpMomentForSegment, 3);
219
+ rb_define_module_function(m_Chipmunk, "box_moment", rb_cpMomentForBox, 3);
220
+
221
+
222
+ rb_define_module_function(m_Chipmunk, "area_for_circle", rb_cpAreaForCircle, 2);
223
+ rb_define_module_function(m_Chipmunk, "area_for_poly", rb_cpAreaForPoly, 1);
224
+ rb_define_module_function(m_Chipmunk, "centroid_for_poly",
225
+ rb_cpCentroidForPoly, 1);
226
+ rb_define_module_function(m_Chipmunk, "recenter_poly",
227
+ rb_cpRecenterPoly, 1);
228
+
229
+ rb_define_module_function(m_Chipmunk, "area_for_segment", rb_cpAreaForSegment, 3);
230
+ rb_define_module_function(m_Chipmunk, "area_for_box", rb_cpAreaForBox, 2);
231
+
232
+ rb_define_module_function(m_Chipmunk, "circle_area", rb_cpAreaForCircle, 2);
233
+ rb_define_module_function(m_Chipmunk, "poly_area", rb_cpAreaForPoly, 1);
234
+ rb_define_module_function(m_Chipmunk, "segment_area", rb_cpAreaForSegment, 3);
235
+ rb_define_module_function(m_Chipmunk, "box_area", rb_cpAreaForBox, 2);
236
+
237
+ rb_define_const(m_Chipmunk, "ALL_LAYERS", UINT2NUM((unsigned int)CP_ALL_LAYERS));
238
+ rb_define_const(m_Chipmunk, "NO_GROUP" , UINT2NUM(CP_NO_GROUP));
239
+
240
+ rb_eval_string("Float::INFINITY = 1.0/0.0 unless Float.const_defined? :INFINITY");
241
+ rb_eval_string("CP::INFINITY = 1.0/0.0 unless CP.const_defined? :INFINITY");
242
+
243
+ Init_cpVect();
244
+ Init_cpBB();
245
+ Init_cpBody();
246
+ Init_cpShape();
247
+ Init_cpConstraint();
248
+ Init_cpSpace();
249
+ Init_cpArbiter();
250
+ }