chipmunk 4.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/LICENSE +20 -0
  2. data/README +60 -0
  3. data/Rakefile +47 -40
  4. data/ext/chipmunk/chipmunk.c +39 -3
  5. data/ext/chipmunk/cpArbiter.c +91 -80
  6. data/ext/chipmunk/cpArray.c +24 -10
  7. data/ext/chipmunk/cpBB.c +5 -4
  8. data/ext/chipmunk/cpBody.c +30 -22
  9. data/ext/chipmunk/cpCollision.c +54 -53
  10. data/ext/chipmunk/cpConstraint.c +54 -0
  11. data/ext/chipmunk/cpDampedRotarySpring.c +106 -0
  12. data/ext/chipmunk/cpDampedSpring.c +117 -0
  13. data/ext/chipmunk/cpGearJoint.c +114 -0
  14. data/ext/chipmunk/cpGrooveJoint.c +138 -0
  15. data/ext/chipmunk/cpHashSet.c +74 -40
  16. data/ext/chipmunk/cpPinJoint.c +117 -0
  17. data/ext/chipmunk/cpPivotJoint.c +114 -0
  18. data/ext/chipmunk/cpPolyShape.c +117 -15
  19. data/ext/chipmunk/cpRatchetJoint.c +128 -0
  20. data/ext/chipmunk/cpRotaryLimitJoint.c +122 -0
  21. data/ext/chipmunk/cpShape.c +174 -18
  22. data/ext/chipmunk/cpSimpleMotor.c +99 -0
  23. data/ext/chipmunk/cpSlideJoint.c +131 -0
  24. data/ext/chipmunk/cpSpace.c +584 -215
  25. data/ext/chipmunk/cpSpaceHash.c +191 -105
  26. data/ext/chipmunk/cpVect.c +18 -10
  27. data/ext/chipmunk/extconf.rb +34 -4
  28. data/ext/chipmunk/{chipmunk.h → include/chipmunk/chipmunk.h} +63 -6
  29. data/ext/chipmunk/include/chipmunk/chipmunk_ffi.h +42 -0
  30. data/ext/chipmunk/include/chipmunk/chipmunk_types.h +80 -0
  31. data/ext/chipmunk/include/chipmunk/chipmunk_unsafe.h +54 -0
  32. data/ext/chipmunk/include/chipmunk/constraints/cpConstraint.h +92 -0
  33. data/ext/chipmunk/include/chipmunk/constraints/cpDampedRotarySpring.h +46 -0
  34. data/ext/chipmunk/include/chipmunk/constraints/cpDampedSpring.h +53 -0
  35. data/ext/chipmunk/include/chipmunk/constraints/cpGearJoint.h +41 -0
  36. data/ext/chipmunk/include/chipmunk/constraints/cpGrooveJoint.h +44 -0
  37. data/ext/chipmunk/include/chipmunk/constraints/cpPinJoint.h +43 -0
  38. data/ext/chipmunk/include/chipmunk/constraints/cpPivotJoint.h +42 -0
  39. data/ext/chipmunk/include/chipmunk/constraints/cpRatchetJoint.h +40 -0
  40. data/ext/chipmunk/include/chipmunk/constraints/cpRotaryLimitJoint.h +39 -0
  41. data/ext/chipmunk/include/chipmunk/constraints/cpSimpleMotor.h +37 -0
  42. data/ext/chipmunk/include/chipmunk/constraints/cpSlideJoint.h +44 -0
  43. data/ext/chipmunk/include/chipmunk/constraints/util.h +116 -0
  44. data/ext/chipmunk/{cpArbiter.h → include/chipmunk/cpArbiter.h} +66 -15
  45. data/ext/chipmunk/{cpArray.h → include/chipmunk/cpArray.h} +2 -1
  46. data/ext/chipmunk/{cpBB.h → include/chipmunk/cpBB.h} +21 -0
  47. data/ext/chipmunk/{cpBody.h → include/chipmunk/cpBody.h} +37 -9
  48. data/ext/chipmunk/{cpCollision.h → include/chipmunk/cpCollision.h} +1 -1
  49. data/ext/chipmunk/{cpHashSet.h → include/chipmunk/cpHashSet.h} +12 -9
  50. data/ext/chipmunk/{cpPolyShape.h → include/chipmunk/cpPolyShape.h} +13 -2
  51. data/ext/chipmunk/{cpShape.h → include/chipmunk/cpShape.h} +51 -18
  52. data/ext/chipmunk/include/chipmunk/cpSpace.h +180 -0
  53. data/ext/chipmunk/{cpSpaceHash.h → include/chipmunk/cpSpaceHash.h} +18 -9
  54. data/ext/chipmunk/{cpVect.h → include/chipmunk/cpVect.h} +61 -10
  55. data/ext/chipmunk/prime.h +32 -32
  56. data/ext/chipmunk/rb_chipmunk.c +125 -109
  57. data/ext/chipmunk/rb_chipmunk.h +96 -77
  58. data/ext/chipmunk/rb_cpArbiter.c +225 -0
  59. data/ext/chipmunk/rb_cpBB.c +174 -154
  60. data/ext/chipmunk/rb_cpBody.c +347 -239
  61. data/ext/chipmunk/rb_cpConstraint.c +346 -0
  62. data/ext/chipmunk/rb_cpShape.c +455 -292
  63. data/ext/chipmunk/rb_cpSpace.c +544 -330
  64. data/ext/chipmunk/rb_cpVect.c +321 -250
  65. data/lib/chipmunk.rb +28 -15
  66. data/lib/chipmunk/version.rb +3 -0
  67. metadata +74 -34
  68. data/ext/chipmunk/cpJoint.c +0 -553
  69. data/ext/chipmunk/cpJoint.h +0 -122
  70. data/ext/chipmunk/cpSpace.h +0 -120
  71. data/ext/chipmunk/rb_cpJoint.c +0 -136
@@ -1,250 +1,321 @@
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.h"
23
-
24
- #include "ruby.h"
25
- #include "rb_chipmunk.h"
26
-
27
- VALUE c_cpVect;
28
-
29
- static VALUE
30
- rb_cpVectForAngle(VALUE self, VALUE angle)
31
- {
32
- return VNEW(cpvforangle(NUM2DBL(angle)));
33
- }
34
-
35
- static VALUE
36
- rb_cpVectAlloc(VALUE klass)
37
- {
38
- cpVect *v = malloc(sizeof(cpVect));
39
- return Data_Wrap_Struct(klass, NULL, free, v);
40
- }
41
-
42
- static VALUE
43
- rb_cpVectInitialize(VALUE self, VALUE x, VALUE y)
44
- {
45
- cpVect *v = VGET(self);
46
- v->x = NUM2DBL(x);
47
- v->y = NUM2DBL(y);
48
-
49
- return self;
50
- }
51
-
52
- static VALUE
53
- rb_cpVectGetX(VALUE self)
54
- {
55
- return rb_float_new(VGET(self)->x);
56
- }
57
-
58
- static VALUE
59
- rb_cpVectGetY(VALUE self)
60
- {
61
- return rb_float_new(VGET(self)->y);
62
- }
63
-
64
- static VALUE
65
- rb_cpVectSetX(VALUE self, VALUE x)
66
- {
67
- VGET(self)->x = NUM2DBL(x);
68
- return self;
69
- }
70
-
71
- static VALUE
72
- rb_cpVectSetY(VALUE self, VALUE y)
73
- {
74
- VGET(self)->y = NUM2DBL(y);
75
- return self;
76
- }
77
-
78
- static VALUE
79
- rb_cpVectToString(VALUE self)
80
- {
81
- char str[256];
82
- cpVect *v = VGET(self);
83
-
84
- sprintf(str, "(% .3f, % .3f)", v->x, v->y);
85
-
86
- return rb_str_new2(str);
87
- }
88
-
89
- static VALUE
90
- rb_cpVectToArray(VALUE self)
91
- {
92
- cpVect *v = VGET(self);
93
- return rb_ary_new3(2, rb_float_new(v->x), rb_float_new(v->y));
94
- }
95
-
96
- static VALUE
97
- rb_cpVectToAngle(VALUE self)
98
- {
99
- return rb_float_new(cpvtoangle(*VGET(self)));
100
- }
101
-
102
-
103
- static VALUE
104
- rb_cpVectNegate(VALUE self)
105
- {
106
- return VNEW(cpvneg(*VGET(self)));
107
- }
108
-
109
- static VALUE
110
- rb_cpVectAdd(VALUE self, VALUE v)
111
- {
112
- return VNEW(cpvadd(*VGET(self), *VGET(v)));
113
- }
114
-
115
- static VALUE
116
- rb_cpVectSub(VALUE self, VALUE v)
117
- {
118
- return VNEW(cpvsub(*VGET(self), *VGET(v)));
119
- }
120
-
121
- static VALUE
122
- rb_cpVectSMult(VALUE self, VALUE s)
123
- {
124
- return VNEW(cpvmult(*VGET(self), NUM2DBL(s)));
125
- }
126
-
127
- static VALUE
128
- rb_cpVectSDiv(VALUE self, VALUE s)
129
- {
130
- cpFloat factor = 1.0f/(float)NUM2DBL(s);
131
- return VNEW(cpvmult(*VGET(self), factor));
132
- }
133
-
134
- static VALUE
135
- rb_cpVectDot(VALUE self, VALUE v)
136
- {
137
- return rb_float_new(cpvdot(*VGET(self), *VGET(v)));
138
- }
139
-
140
- static VALUE
141
- rb_cpVectCross(VALUE self, VALUE v)
142
- {
143
- return rb_float_new(cpvcross(*VGET(self), *VGET(v)));
144
- }
145
-
146
- static VALUE
147
- rb_cpVectLength(VALUE self)
148
- {
149
- cpVect *v;
150
- Data_Get_Struct(self, cpVect, v);
151
- return rb_float_new(cpvlength(*v));
152
- }
153
-
154
- static VALUE
155
- rb_cpVectLengthsq(VALUE self)
156
- {
157
- cpVect *v;
158
- Data_Get_Struct(self, cpVect, v);
159
- return rb_float_new(cpvlengthsq(*v));
160
- }
161
-
162
- static VALUE
163
- rb_cpVectNorm(VALUE self)
164
- {
165
- return VNEW(cpvnormalize(*VGET(self)));
166
- }
167
-
168
- static VALUE
169
- rb_cpVectNormBang(VALUE self)
170
- {
171
- cpVect *v = VGET(self);
172
- *v = cpvnormalize(*v);
173
- return self;
174
- }
175
-
176
- static VALUE
177
- rb_cpVectPerp(VALUE self)
178
- {
179
- return VNEW(cpvperp(*VGET(self)));
180
- }
181
-
182
- static VALUE
183
- rb_cpVectProject(VALUE self, VALUE v)
184
- {
185
- return VNEW(cpvproject(*VGET(self), *VGET(v)));
186
- }
187
-
188
- static VALUE
189
- rb_cpVectRotate(VALUE self, VALUE v)
190
- {
191
- return VNEW(cpvrotate(*VGET(self), *VGET(v)));
192
- }
193
-
194
- static VALUE
195
- rb_cpVectUnRotate(VALUE self, VALUE v)
196
- {
197
- return VNEW(cpvunrotate(*VGET(self), *VGET(v)));
198
- }
199
-
200
- static VALUE
201
- rb_cpVectNear(VALUE self, VALUE v, VALUE d)
202
- {
203
- cpFloat dist = NUM2DBL(d);
204
- cpVect delta = cpvsub(*VGET(self), *VGET(v));
205
- return (cpvdot(delta, delta) <= dist*dist) ? Qtrue : Qfalse;
206
- }
207
-
208
- static VALUE
209
- rb_vec2(VALUE self, VALUE x, VALUE y)
210
- {
211
- return VNEW(cpv(NUM2DBL(x), NUM2DBL(y)));
212
- }
213
-
214
- void
215
- Init_cpVect(void)
216
- {
217
- c_cpVect = rb_define_class_under(m_Chipmunk, "Vec2", rb_cObject);
218
- rb_define_singleton_method(c_cpBB, "for_angle", rb_cpVectForAngle, 1);
219
-
220
- rb_define_alloc_func(c_cpVect, rb_cpVectAlloc);
221
- rb_define_method(c_cpVect, "initialize", rb_cpVectInitialize, 2);
222
-
223
- rb_define_method(c_cpVect, "x", rb_cpVectGetX, 0);
224
- rb_define_method(c_cpVect, "y", rb_cpVectGetY, 0);
225
- rb_define_method(c_cpVect, "x=", rb_cpVectSetX, 1);
226
- rb_define_method(c_cpVect, "y=", rb_cpVectSetY, 1);
227
-
228
- rb_define_method(c_cpVect, "to_s", rb_cpVectToString, 0);
229
- rb_define_method(c_cpVect, "to_a", rb_cpVectToArray, 0);
230
- rb_define_method(c_cpVect, "to_angle", rb_cpVectToAngle, 0);
231
-
232
- rb_define_method(c_cpVect, "-@", rb_cpVectNegate, 0);
233
- rb_define_method(c_cpVect, "+", rb_cpVectAdd, 1);
234
- rb_define_method(c_cpVect, "-", rb_cpVectSub, 1);
235
- rb_define_method(c_cpVect, "*", rb_cpVectSMult, 1);
236
- rb_define_method(c_cpVect, "/", rb_cpVectSDiv, 1);
237
- rb_define_method(c_cpVect, "dot", rb_cpVectDot, 1);
238
- rb_define_method(c_cpVect, "cross", rb_cpVectCross, 1);
239
- rb_define_method(c_cpVect, "length", rb_cpVectLength, 0);
240
- rb_define_method(c_cpVect, "lengthsq", rb_cpVectLengthsq, 0);
241
- rb_define_method(c_cpVect, "normalize", rb_cpVectNorm, 0);
242
- rb_define_method(c_cpVect, "normalize!", rb_cpVectNormBang, 0);
243
- rb_define_method(c_cpVect, "perp", rb_cpVectPerp, 0);
244
- rb_define_method(c_cpVect, "project", rb_cpVectProject, 1);
245
- rb_define_method(c_cpVect, "rotate", rb_cpVectRotate, 1);
246
- rb_define_method(c_cpVect, "unrotate", rb_cpVectUnRotate, 1);
247
- rb_define_method(c_cpVect, "near?", rb_cpVectNear, 2);
248
-
249
- rb_define_global_function("vec2", rb_vec2, 2);
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
+ #include "chipmunk.h"
24
+
25
+ #include "ruby.h"
26
+ #include "rb_chipmunk.h"
27
+
28
+ VALUE c_cpVect;
29
+
30
+ static VALUE
31
+ rb_cpVectForAngle(VALUE self, VALUE angle)
32
+ {
33
+ return VNEW(cpvforangle(NUM2DBL(angle)));
34
+ }
35
+
36
+ static VALUE
37
+ rb_cpVectAlloc(VALUE klass)
38
+ {
39
+ cpVect *v = malloc(sizeof(cpVect));
40
+ return Data_Wrap_Struct(klass, NULL, free, v);
41
+ }
42
+
43
+ static VALUE
44
+ rb_cpVectInitialize(VALUE self, VALUE x, VALUE y)
45
+ {
46
+ cpVect *v = VGET(self);
47
+ v->x = NUM2DBL(x);
48
+ v->y = NUM2DBL(y);
49
+
50
+ return self;
51
+ }
52
+
53
+ static VALUE
54
+ rb_cpVectGetX(VALUE self)
55
+ {
56
+ return rb_float_new(VGET(self)->x);
57
+ }
58
+
59
+ static VALUE
60
+ rb_cpVectGetY(VALUE self)
61
+ {
62
+ return rb_float_new(VGET(self)->y);
63
+ }
64
+
65
+ static VALUE
66
+ rb_cpVectSetX(VALUE self, VALUE x)
67
+ {
68
+ VGET(self)->x = NUM2DBL(x);
69
+ return self;
70
+ }
71
+
72
+ static VALUE
73
+ rb_cpVectSetY(VALUE self, VALUE y)
74
+ {
75
+ VGET(self)->y = NUM2DBL(y);
76
+ return self;
77
+ }
78
+
79
+ static VALUE
80
+ rb_cpVectToString(VALUE self)
81
+ {
82
+ char str[256];
83
+ cpVect *v = VGET(self);
84
+
85
+ sprintf(str, "(% .3f, % .3f)", v->x, v->y);
86
+
87
+ return rb_str_new2(str);
88
+ }
89
+
90
+ static VALUE
91
+ rb_cpVectToArray(VALUE self)
92
+ {
93
+ cpVect *v = VGET(self);
94
+ return rb_ary_new3(2, rb_float_new(v->x), rb_float_new(v->y));
95
+ }
96
+
97
+ static VALUE
98
+ rb_cpVectToAngle(VALUE self)
99
+ {
100
+ return rb_float_new(cpvtoangle(*VGET(self)));
101
+ }
102
+
103
+
104
+ static VALUE
105
+ rb_cpVectNegate(VALUE self)
106
+ {
107
+ return VNEW(cpvneg(*VGET(self)));
108
+ }
109
+
110
+ static VALUE
111
+ rb_cpVectAdd(VALUE self, VALUE v)
112
+ {
113
+ return VNEW(cpvadd(*VGET(self), *VGET(v)));
114
+ }
115
+
116
+ static VALUE
117
+ rb_cpVectSub(VALUE self, VALUE v)
118
+ {
119
+ return VNEW(cpvsub(*VGET(self), *VGET(v)));
120
+ }
121
+
122
+ static VALUE
123
+ rb_cpVectSMult(VALUE self, VALUE s)
124
+ {
125
+ return VNEW(cpvmult(*VGET(self), NUM2DBL(s)));
126
+ }
127
+
128
+ static VALUE
129
+ rb_cpVectSDiv(VALUE self, VALUE s)
130
+ {
131
+ cpFloat factor = 1.0f/(float)NUM2DBL(s);
132
+ return VNEW(cpvmult(*VGET(self), factor));
133
+ }
134
+
135
+ static VALUE
136
+ rb_cpVectDot(VALUE self, VALUE v)
137
+ {
138
+ return rb_float_new(cpvdot(*VGET(self), *VGET(v)));
139
+ }
140
+
141
+ static VALUE
142
+ rb_cpVectCross(VALUE self, VALUE v)
143
+ {
144
+ return rb_float_new(cpvcross(*VGET(self), *VGET(v)));
145
+ }
146
+
147
+ static VALUE
148
+ rb_cpVectLength(VALUE self)
149
+ {
150
+ cpVect *v;
151
+ Data_Get_Struct(self, cpVect, v);
152
+ return rb_float_new(cpvlength(*v));
153
+ }
154
+
155
+ static VALUE
156
+ rb_cpVectLengthsq(VALUE self)
157
+ {
158
+ cpVect *v;
159
+ Data_Get_Struct(self, cpVect, v);
160
+ return rb_float_new(cpvlengthsq(*v));
161
+ }
162
+
163
+ static VALUE
164
+ rb_cpVectNorm(VALUE self)
165
+ {
166
+ return VNEW(cpvnormalize(*VGET(self)));
167
+ }
168
+
169
+ static VALUE
170
+ rb_cpVectNormBang(VALUE self)
171
+ {
172
+ cpVect *v = VGET(self);
173
+ *v = cpvnormalize(*v);
174
+ return self;
175
+ }
176
+
177
+ static VALUE
178
+ rb_cpVectNormSafe(VALUE self)
179
+ {
180
+ return VNEW(cpvnormalize_safe(*VGET(self)));
181
+ }
182
+
183
+ static VALUE
184
+ rb_cpVectNormSafeBang(VALUE self)
185
+ {
186
+ cpVect *v = VGET(self);
187
+ *v = cpvnormalize_safe(*v);
188
+ return self;
189
+ }
190
+
191
+ static VALUE
192
+ rb_cpVectPerp(VALUE self)
193
+ {
194
+ return VNEW(cpvperp(*VGET(self)));
195
+ }
196
+
197
+ static VALUE
198
+ rb_cpVectProject(VALUE self, VALUE v)
199
+ {
200
+ return VNEW(cpvproject(*VGET(self), *VGET(v)));
201
+ }
202
+
203
+ static VALUE
204
+ rb_cpVectRotate(VALUE self, VALUE v)
205
+ {
206
+ return VNEW(cpvrotate(*VGET(self), *VGET(v)));
207
+ }
208
+
209
+ static VALUE
210
+ rb_cpVectUnRotate(VALUE self, VALUE v)
211
+ {
212
+ return VNEW(cpvunrotate(*VGET(self), *VGET(v)));
213
+ }
214
+
215
+ static VALUE
216
+ rb_cpVectNear(VALUE self, VALUE v, VALUE d)
217
+ {
218
+ cpFloat dist = NUM2DBL(d);
219
+ cpVect delta = cpvsub(*VGET(self), *VGET(v));
220
+ return (cpvdot(delta, delta) <= dist*dist) ? Qtrue : Qfalse;
221
+ }
222
+
223
+ static VALUE
224
+ rb_vec2(VALUE self, VALUE x, VALUE y)
225
+ {
226
+ return VNEW(cpv(NUM2DBL(x), NUM2DBL(y)));
227
+ }
228
+
229
+ static VALUE
230
+ rb_cpVectDist(VALUE self, VALUE v)
231
+ {
232
+ return rb_float_new(cpvdist(*VGET(self), *VGET(v)));
233
+ }
234
+
235
+ static VALUE
236
+ rb_cpVectDistsq(VALUE self, VALUE v)
237
+ {
238
+ return rb_float_new(cpvdistsq(*VGET(self), *VGET(v)));
239
+ }
240
+
241
+ static VALUE
242
+ rb_cpVectRperp(VALUE self)
243
+ {
244
+ return VNEW(cpvrperp(*VGET(self)));
245
+ }
246
+
247
+ static VALUE
248
+ rb_cpVectLerp(VALUE self, VALUE v, VALUE t)
249
+ {
250
+ return VNEW(cpvlerp(*VGET(self), *VGET(v), NUM2DBL(t)));
251
+ }
252
+
253
+ static VALUE
254
+ rb_cpVectLerpconst(VALUE self, VALUE v, VALUE d)
255
+ {
256
+ return VNEW(cpvlerpconst(*VGET(self), *VGET(v), NUM2DBL(d)));
257
+ }
258
+
259
+ static VALUE
260
+ rb_cpVectSlerp(VALUE self, VALUE v, VALUE t)
261
+ {
262
+ return VNEW(cpvslerp(*VGET(self), *VGET(v), NUM2DBL(t)));
263
+ }
264
+
265
+ static VALUE
266
+ rb_cpVectSlerpconst(VALUE self, VALUE v, VALUE d)
267
+ {
268
+ return VNEW(cpvslerpconst(*VGET(self), *VGET(v), NUM2DBL(d)));
269
+ }
270
+
271
+
272
+ void
273
+ Init_cpVect(void)
274
+ {
275
+ c_cpVect = rb_define_class_under(m_Chipmunk, "Vec2", rb_cObject);
276
+ rb_define_singleton_method(c_cpVect, "for_angle", rb_cpVectForAngle, 1);
277
+
278
+ rb_define_alloc_func(c_cpVect, rb_cpVectAlloc);
279
+ rb_define_method(c_cpVect, "initialize", rb_cpVectInitialize, 2);
280
+
281
+ rb_define_method(c_cpVect, "x", rb_cpVectGetX, 0);
282
+ rb_define_method(c_cpVect, "y", rb_cpVectGetY, 0);
283
+ rb_define_method(c_cpVect, "x=", rb_cpVectSetX, 1);
284
+ rb_define_method(c_cpVect, "y=", rb_cpVectSetY, 1);
285
+
286
+ rb_define_method(c_cpVect, "to_s", rb_cpVectToString, 0);
287
+ rb_define_method(c_cpVect, "to_a", rb_cpVectToArray, 0);
288
+ rb_define_method(c_cpVect, "to_angle", rb_cpVectToAngle, 0);
289
+
290
+ rb_define_method(c_cpVect, "-@", rb_cpVectNegate, 0);
291
+ rb_define_method(c_cpVect, "+", rb_cpVectAdd, 1);
292
+ rb_define_method(c_cpVect, "-", rb_cpVectSub, 1);
293
+ rb_define_method(c_cpVect, "*", rb_cpVectSMult, 1);
294
+ rb_define_method(c_cpVect, "/", rb_cpVectSDiv, 1);
295
+
296
+ rb_define_method(c_cpVect, "dot" , rb_cpVectDot, 1);
297
+ rb_define_method(c_cpVect, "cross" , rb_cpVectCross, 1);
298
+ rb_define_method(c_cpVect, "dist" , rb_cpVectDist, 1);
299
+ rb_define_method(c_cpVect, "distsq" , rb_cpVectDistsq, 1);
300
+ rb_define_method(c_cpVect, "length" , rb_cpVectLength, 0);
301
+ rb_define_method(c_cpVect, "lengthsq" , rb_cpVectLengthsq, 0);
302
+ rb_define_method(c_cpVect, "lerp" , rb_cpVectLerp, 2);
303
+ rb_define_method(c_cpVect, "lerpconst" , rb_cpVectLerpconst, 2);
304
+ rb_define_method(c_cpVect, "normalize" , rb_cpVectNorm, 0);
305
+ rb_define_method(c_cpVect, "normalize!" , rb_cpVectNormBang, 0);
306
+ rb_define_method(c_cpVect, "normalize_safe" , rb_cpVectNormSafe, 0);
307
+ rb_define_method(c_cpVect, "normalize_safe!" , rb_cpVectNormSafeBang, 0);
308
+
309
+ rb_define_method(c_cpVect, "perp" , rb_cpVectPerp, 0);
310
+ rb_define_method(c_cpVect, "project" , rb_cpVectProject, 1);
311
+ rb_define_method(c_cpVect, "rotate" , rb_cpVectRotate, 1);
312
+ rb_define_method(c_cpVect, "rperp" , rb_cpVectRperp, 0);
313
+ rb_define_method(c_cpVect, "slerp" , rb_cpVectSlerp, 2);
314
+ rb_define_method(c_cpVect, "slerpconst" , rb_cpVectSlerpconst, 2);
315
+
316
+
317
+ rb_define_method(c_cpVect, "unrotate" , rb_cpVectUnRotate, 1);
318
+ rb_define_method(c_cpVect, "near?" , rb_cpVectNear, 2);
319
+
320
+ rb_define_global_function("vec2", rb_vec2, 2);
321
+ }