chipmunk-ffi 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/chipmunk-ffi.gemspec +43 -0
- data/lib/chipmunk-ffi.rb +219 -0
- metadata +77 -0
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "chipmunk-ffi"
|
5
|
+
gem.rubyforge_project = "chipmunk-ffi"
|
6
|
+
gem.summary = %Q{FFI bindings for chipmunk physics lib.}
|
7
|
+
gem.description = %Q{FFI bindings for chipmunk physics lib.}
|
8
|
+
gem.email = "shawn42@gmail.com"
|
9
|
+
gem.homepage = "http://shawn42.github.com/chipmunk-ffi"
|
10
|
+
gem.authors = ["Shawn Anderson"]
|
11
|
+
gem.add_development_dependency "rspec"
|
12
|
+
gem.add_development_dependency "jeweler"
|
13
|
+
gem.test_files = FileList['{spec,test}/**/*.rb']
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
desc "Run all rspecs"
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
24
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
25
|
+
end
|
26
|
+
task :default => :spec
|
27
|
+
|
28
|
+
# vim: syntax=Ruby
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{chipmunk-ffi}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Shawn Anderson"]
|
12
|
+
s.date = %q{2009-12-02}
|
13
|
+
s.description = %q{FFI bindings for chipmunk physics lib.}
|
14
|
+
s.email = %q{shawn42@gmail.com}
|
15
|
+
s.files = [
|
16
|
+
"Rakefile",
|
17
|
+
"VERSION",
|
18
|
+
"chipmunk-ffi.gemspec",
|
19
|
+
"lib/chipmunk-ffi.rb"
|
20
|
+
]
|
21
|
+
s.homepage = %q{http://shawn42.github.com/chipmunk-ffi}
|
22
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
s.rubyforge_project = %q{chipmunk-ffi}
|
25
|
+
s.rubygems_version = %q{1.3.5}
|
26
|
+
s.summary = %q{FFI bindings for chipmunk physics lib.}
|
27
|
+
|
28
|
+
if s.respond_to? :specification_version then
|
29
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
30
|
+
s.specification_version = 3
|
31
|
+
|
32
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
33
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
34
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
35
|
+
else
|
36
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
37
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
38
|
+
end
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
41
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
42
|
+
end
|
43
|
+
end
|
data/lib/chipmunk-ffi.rb
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nice-ffi'
|
3
|
+
|
4
|
+
module CP
|
5
|
+
extend NiceFFI::Library
|
6
|
+
|
7
|
+
|
8
|
+
unless defined? CP::LOAD_PATHS
|
9
|
+
# Check if the application has defined CP_PATHS with some
|
10
|
+
# paths to check first for chipmunk library.
|
11
|
+
CP::LOAD_PATHS = if defined? ::CP_PATHS
|
12
|
+
NiceFFI::PathSet::DEFAULT.prepend( ::CP_PATHS )
|
13
|
+
else
|
14
|
+
NiceFFI::PathSet::DEFAULT
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
load_library "chipmunk", CP::LOAD_PATHS
|
19
|
+
def self.cp_static_inline(func_sym, ret, args)
|
20
|
+
func_name = "_#{func_sym}"
|
21
|
+
attach_variable func_name, :pointer
|
22
|
+
const_func_name = func_sym.to_s.upcase
|
23
|
+
|
24
|
+
func = FFI::Function.new(Vect.by_value, args, FFI::Pointer.new(self.send(func_name)), :convention => :default )
|
25
|
+
const_set const_func_name, func
|
26
|
+
|
27
|
+
instance_eval <<-METHOD
|
28
|
+
def #{func_sym}(*args)
|
29
|
+
const_get('#{const_func_name}').call *args
|
30
|
+
end
|
31
|
+
METHOD
|
32
|
+
end
|
33
|
+
|
34
|
+
CP_FLOAT = :double
|
35
|
+
|
36
|
+
class Vect < NiceFFI::Struct
|
37
|
+
layout( :x, CP_FLOAT,
|
38
|
+
:y, CP_FLOAT )
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
cp_static_inline :cpv, Vect.by_value, [CP_FLOAT,CP_FLOAT]
|
43
|
+
cp_static_inline :cpvneg, Vect.by_value, [Vect.by_value]
|
44
|
+
cp_static_inline :cpvadd, Vect.by_value, [Vect.by_value,Vect.by_value]
|
45
|
+
cp_static_inline :cpvsub, Vect.by_value, [Vect.by_value,Vect.by_value]
|
46
|
+
cp_static_inline :cpvmult, Vect.by_value, [Vect.by_value,Vect.by_value]
|
47
|
+
cp_static_inline :cpvdot, Vect.by_value, [Vect.by_value,Vect.by_value]
|
48
|
+
cp_static_inline :cpvcross, Vect.by_value, [Vect.by_value,Vect.by_value]
|
49
|
+
|
50
|
+
cp_static_inline :cpvperp, Vect.by_value, [Vect.by_value]
|
51
|
+
cp_static_inline :cpvrperp, Vect.by_value, [Vect.by_value]
|
52
|
+
cp_static_inline :cpvproject, Vect.by_value, [Vect.by_value,Vect.by_value]
|
53
|
+
cp_static_inline :cpvrotate, Vect.by_value, [Vect.by_value,Vect.by_value]
|
54
|
+
cp_static_inline :cpvunrotate, Vect.by_value, [Vect.by_value,Vect.by_value]
|
55
|
+
|
56
|
+
cp_static_inline :cpvlengthsq, CP_FLOAT, [Vect.by_value]
|
57
|
+
|
58
|
+
cp_static_inline :cpvlerp, Vect.by_value, [Vect.by_value,Vect.by_value]
|
59
|
+
|
60
|
+
cp_static_inline :cpvnormalize, Vect.by_value, [Vect.by_value]
|
61
|
+
cp_static_inline :cpvnormalize_safe, Vect.by_value, [Vect.by_value]
|
62
|
+
|
63
|
+
cp_static_inline :cpvclamp, Vect.by_value, [Vect.by_value,Vect.by_value]
|
64
|
+
cp_static_inline :cpvlerpconst, Vect.by_value, [Vect.by_value,Vect.by_value]
|
65
|
+
cp_static_inline :cpvdist, CP_FLOAT, [Vect.by_value,Vect.by_value]
|
66
|
+
cp_static_inline :cpvdistsq, CP_FLOAT, [Vect.by_value,Vect.by_value]
|
67
|
+
|
68
|
+
cp_static_inline :cpvnear, :int, [Vect.by_value,Vect.by_value, CP_FLOAT]
|
69
|
+
|
70
|
+
func :cpvlength, [Vect.by_value], CP_FLOAT
|
71
|
+
func :cpvforangle, [CP_FLOAT], Vect.by_value
|
72
|
+
func :cpvslerp, [Vect.by_value, Vect.by_value, CP_FLOAT], Vect.by_value
|
73
|
+
func :cpvslerpconst, [Vect.by_value, Vect.by_value, CP_FLOAT], Vect.by_value
|
74
|
+
func :cpvtoangle, [Vect.by_value], CP_FLOAT
|
75
|
+
func :cpvstr, [Vect.by_value], :string
|
76
|
+
|
77
|
+
class Vec2
|
78
|
+
attr_accessor :struct
|
79
|
+
def initialize(x,y)
|
80
|
+
@struct = CP.cpv(x,y)
|
81
|
+
end
|
82
|
+
|
83
|
+
def x
|
84
|
+
@struct.x
|
85
|
+
end
|
86
|
+
def x=(new_x)
|
87
|
+
@struct.x = new_x
|
88
|
+
end
|
89
|
+
def y
|
90
|
+
@struct.y
|
91
|
+
end
|
92
|
+
def y=(new_y)
|
93
|
+
@struct.y = new_y
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.for_angle(angle)
|
97
|
+
create_from_struct CP.cpvforangle(angle)
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_s
|
101
|
+
CP.cpvstr @struct
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_angle
|
105
|
+
CP.cpvtoangle @struct
|
106
|
+
end
|
107
|
+
|
108
|
+
def to_a
|
109
|
+
[@struct.x,@struct.y]
|
110
|
+
end
|
111
|
+
|
112
|
+
def -@
|
113
|
+
create_from_struct CP.cpvneg(@struct)
|
114
|
+
end
|
115
|
+
|
116
|
+
def +(other_vec)
|
117
|
+
create_from_struct CP.cpvadd(@struct, other_vec.struct)
|
118
|
+
end
|
119
|
+
|
120
|
+
def -(other_vec)
|
121
|
+
create_from_struct CP.cpvsub(@struct, other_vec.struct)
|
122
|
+
end
|
123
|
+
|
124
|
+
def *(s)
|
125
|
+
create_from_struct CP.cpvmult(@struct, s)
|
126
|
+
end
|
127
|
+
|
128
|
+
def /(s)
|
129
|
+
factor = 1.0/s
|
130
|
+
create_from_struct CP.cpvmult(@struct, s)
|
131
|
+
end
|
132
|
+
|
133
|
+
def dot(other_vec)
|
134
|
+
CP.cpvdot(@struct, other_vec.struct)
|
135
|
+
end
|
136
|
+
|
137
|
+
def cross(other_vec)
|
138
|
+
CP.cpvcross(@struct, other_vec.struct)
|
139
|
+
end
|
140
|
+
|
141
|
+
def perp
|
142
|
+
create_from_struct CP.cpvperp(@struct)
|
143
|
+
end
|
144
|
+
|
145
|
+
def rperp
|
146
|
+
create_from_struct CP.cpvperp(@struct)
|
147
|
+
end
|
148
|
+
|
149
|
+
def project(other_vec)
|
150
|
+
create_from_struct CP.cpvproject(@struct, other_vec.struct)
|
151
|
+
end
|
152
|
+
|
153
|
+
def rotate(other_vec)
|
154
|
+
create_from_struct CP.cpvrotate(@struct, other_vec.struct)
|
155
|
+
end
|
156
|
+
|
157
|
+
def unrotate(other_vec)
|
158
|
+
create_from_struct CP.cpvunrotate(@struct, other_vec.struct)
|
159
|
+
end
|
160
|
+
|
161
|
+
def lengthsq
|
162
|
+
CP.cpvlengthsq(@struct)
|
163
|
+
end
|
164
|
+
|
165
|
+
def lerp(other_vec)
|
166
|
+
end
|
167
|
+
|
168
|
+
def normalize
|
169
|
+
create_from_struct CP.cpvnormalize(@struct)
|
170
|
+
end
|
171
|
+
|
172
|
+
def normalize!
|
173
|
+
@struct = CP.cpvnormalize(@struct)
|
174
|
+
end
|
175
|
+
|
176
|
+
def normalize_safe
|
177
|
+
create_from_struct CP.cpvnormalize_safe(@struct)
|
178
|
+
end
|
179
|
+
|
180
|
+
def clamp(other_vec)
|
181
|
+
create_from_struct CP.cpvclamp(@struct)
|
182
|
+
end
|
183
|
+
|
184
|
+
def lerpconst(other_vec)
|
185
|
+
create_from_struct CP.cpvlerpconst(@struct)
|
186
|
+
end
|
187
|
+
|
188
|
+
def dist(other_vec)
|
189
|
+
CP.cpvdist(@struct)
|
190
|
+
end
|
191
|
+
|
192
|
+
def distsq(other_vec)
|
193
|
+
CP.cpvdistsq(@struct)
|
194
|
+
end
|
195
|
+
|
196
|
+
def near?(other_vec, dist)
|
197
|
+
delta_v = CP.cpvsub(@struct, other_vec.struct)
|
198
|
+
CP.cpvdot(delta_v, delta_v) < dist*dist
|
199
|
+
end
|
200
|
+
|
201
|
+
def length
|
202
|
+
CP::cpvlength @struct
|
203
|
+
end
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
def create_from_struct(struct)
|
208
|
+
new_v = dup
|
209
|
+
new_v.struct = struct
|
210
|
+
new_v
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
ZERO_VEC_2 = Vec2.new(0,0).freeze
|
215
|
+
|
216
|
+
end
|
217
|
+
def vec2(x,y)
|
218
|
+
CP::Vec2.new x, y
|
219
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chipmunk-ffi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shawn Anderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-02 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: jeweler
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: FFI bindings for chipmunk physics lib.
|
36
|
+
email: shawn42@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- Rakefile
|
45
|
+
- VERSION
|
46
|
+
- chipmunk-ffi.gemspec
|
47
|
+
- lib/chipmunk-ffi.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://shawn42.github.com/chipmunk-ffi
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project: chipmunk-ffi
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: FFI bindings for chipmunk physics lib.
|
76
|
+
test_files: []
|
77
|
+
|