chipmunk 5.3.4.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README +70 -0
- data/Rakefile +86 -0
- data/ext/chipmunk/extconf.rb +42 -0
- data/ext/chipmunk/rb_chipmunk.c +250 -0
- data/ext/chipmunk/rb_chipmunk.h +105 -0
- data/ext/chipmunk/rb_cpArbiter.c +253 -0
- data/ext/chipmunk/rb_cpBB.c +210 -0
- data/ext/chipmunk/rb_cpBody.c +504 -0
- data/ext/chipmunk/rb_cpConstraint.c +336 -0
- data/ext/chipmunk/rb_cpShape.c +450 -0
- data/ext/chipmunk/rb_cpSpace.c +711 -0
- data/ext/chipmunk/rb_cpVect.c +346 -0
- data/lib/1.8/chipmunk.so +0 -0
- data/lib/1.9/chipmunk.so +0 -0
- data/lib/chipmunk.rb +183 -0
- metadata +83 -0
@@ -0,0 +1,105 @@
|
|
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
|
+
extern VALUE m_Chipmunk;
|
23
|
+
|
24
|
+
extern VALUE c_cpVect;
|
25
|
+
extern VALUE c_cpBB;
|
26
|
+
extern VALUE c_cpBody;
|
27
|
+
extern VALUE m_cpShape;
|
28
|
+
extern VALUE c_cpCircleShape;
|
29
|
+
extern VALUE c_cpSegmentShape;
|
30
|
+
extern VALUE c_cpPolyShape;
|
31
|
+
extern VALUE m_cpConstraint;
|
32
|
+
extern VALUE c_cpSpace;
|
33
|
+
extern VALUE c_cpArbiter;
|
34
|
+
extern VALUE c_cpStaticBody;
|
35
|
+
extern VALUE c_cpSegmentQueryInfo;
|
36
|
+
|
37
|
+
extern ID id_parent;
|
38
|
+
|
39
|
+
static inline VALUE
|
40
|
+
VNEW(cpVect v)
|
41
|
+
{
|
42
|
+
cpVect *ptr = malloc(sizeof(cpVect));
|
43
|
+
*ptr = v;
|
44
|
+
return Data_Wrap_Struct(c_cpVect, NULL, free, ptr);
|
45
|
+
}
|
46
|
+
|
47
|
+
static inline VALUE
|
48
|
+
VWRAP(VALUE parent, cpVect *v)
|
49
|
+
{
|
50
|
+
VALUE vec_obj = Data_Wrap_Struct(c_cpVect, NULL, NULL, v);
|
51
|
+
rb_ivar_set(vec_obj, id_parent, parent);
|
52
|
+
|
53
|
+
return vec_obj;
|
54
|
+
}
|
55
|
+
|
56
|
+
#define GETTER_TEMPLATE(func_name, klass, type)\
|
57
|
+
static inline type *\
|
58
|
+
func_name(VALUE self)\
|
59
|
+
{\
|
60
|
+
if(!rb_obj_is_kind_of(self, klass)){\
|
61
|
+
VALUE klass_name = rb_funcall(klass, rb_intern("to_s"), 0);\
|
62
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", rb_obj_classname(self), StringValuePtr(klass_name));\
|
63
|
+
}\
|
64
|
+
type *ptr;\
|
65
|
+
Data_Get_Struct(self, type, ptr);\
|
66
|
+
return ptr;\
|
67
|
+
}\
|
68
|
+
|
69
|
+
GETTER_TEMPLATE(VGET , c_cpVect , cpVect )
|
70
|
+
GETTER_TEMPLATE(BBGET, c_cpBB , cpBB )
|
71
|
+
GETTER_TEMPLATE(BODY , c_cpBody , cpBody )
|
72
|
+
GETTER_TEMPLATE(STATICBODY , c_cpStaticBody , cpBody)
|
73
|
+
GETTER_TEMPLATE(SHAPE, m_cpShape, cpShape)
|
74
|
+
GETTER_TEMPLATE(CONSTRAINT, m_cpConstraint, cpConstraint)
|
75
|
+
GETTER_TEMPLATE(SPACE, c_cpSpace, cpSpace)
|
76
|
+
GETTER_TEMPLATE(ARBITER, c_cpArbiter, cpArbiter)
|
77
|
+
/* GETTER_TEMPLATE(SPACEHASH, c_cpSpaceHash, cpSpaceHash) */
|
78
|
+
|
79
|
+
// Helper to wrap cpArbter objects.
|
80
|
+
VALUE ARBWRAP(cpArbiter *arb);
|
81
|
+
|
82
|
+
//Helper that allocates and initializes a SegmenQueryInfo struct
|
83
|
+
VALUE rb_cpSegmentQueryInfoNew(VALUE shape, VALUE t, VALUE n);
|
84
|
+
|
85
|
+
void Init_chipmunk(void);
|
86
|
+
void Init_cpVect();
|
87
|
+
void Init_cpBB();
|
88
|
+
void Init_cpBody();
|
89
|
+
void Init_cpShape();
|
90
|
+
void Init_cpConstraint();
|
91
|
+
void Init_cpSpace();
|
92
|
+
void Init_cpArbiter(void);
|
93
|
+
|
94
|
+
// transforms a boolean VALUE to an int
|
95
|
+
#define CP_BOOL_INT(VAL) (((VAL) == Qnil) || ((VAL) == Qfalse) ? 0 : 1)
|
96
|
+
|
97
|
+
// transforms a C value (pointer or int) to Qtrue of Qfalse
|
98
|
+
// For consistency with RBH_BOOL_INT.
|
99
|
+
#define CP_INT_BOOL(VAL) ((VAL) ? Qtrue : Qfalse)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
@@ -0,0 +1,253 @@
|
|
1
|
+
/* Copyright (c) 2010 Beoran (beoran@rubyforge.org)
|
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_cpArbiter;
|
29
|
+
|
30
|
+
/*
|
31
|
+
* I quote the C docs on cpArbiter:
|
32
|
+
* Memory Management
|
33
|
+
* You should never need to create an arbiter, nor will you ever need to free
|
34
|
+
* one as they are handled by the space. More importantly, because they are
|
35
|
+
* handled by the space you should never hold onto a reference to an arbiter as
|
36
|
+
* you don't know when they will be destroyed. Use them within the callback
|
37
|
+
* where they are given to you and then forget about them or copy out the
|
38
|
+
* information you need from them.
|
39
|
+
*
|
40
|
+
* This means that Arbiter doesn't need an initialize, and also
|
41
|
+
* does NOT need any garbage collection.
|
42
|
+
*/
|
43
|
+
|
44
|
+
VALUE ARBWRAP(cpArbiter *arb)
|
45
|
+
{
|
46
|
+
return Data_Wrap_Struct(c_cpArbiter, NULL, NULL, arb);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
/*
|
51
|
+
static VALUE
|
52
|
+
rb_cpArbiterAlloc(VALUE klass)
|
53
|
+
{
|
54
|
+
cpArbiter *arb = cpArbiterAlloc();
|
55
|
+
return Data_Wrap_Struct(klass, NULL, cpArbiterFree, arb);
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
static VALUE
|
60
|
+
rb_cpArbiterInitialize(VALUE self, VALUE a, VALUE b, VALUE r, VALUE t)
|
61
|
+
{
|
62
|
+
cpArbiter *arb = ARBITER(self);
|
63
|
+
cpShape *sa = SHAPE(a);
|
64
|
+
cpShape *sb = SHAPE(b);
|
65
|
+
cpArbiterInit(arb, sa, sb);
|
66
|
+
return self;
|
67
|
+
}
|
68
|
+
*/
|
69
|
+
|
70
|
+
static VALUE
|
71
|
+
rb_cpArbiterTotalImpulse(VALUE self) {
|
72
|
+
cpArbiter *arb = ARBITER(self);
|
73
|
+
return VNEW(cpArbiterTotalImpulse(arb));
|
74
|
+
}
|
75
|
+
|
76
|
+
static VALUE
|
77
|
+
rb_cpArbiterTotalImpulseWithFriction(VALUE self) {
|
78
|
+
cpArbiter *arb = ARBITER(self);
|
79
|
+
return VNEW(cpArbiterTotalImpulseWithFriction(arb));
|
80
|
+
}
|
81
|
+
|
82
|
+
static VALUE
|
83
|
+
rb_cpArbiterGetImpulse(int argc, VALUE *argv, VALUE self)
|
84
|
+
{
|
85
|
+
VALUE friction = Qnil;
|
86
|
+
rb_scan_args(argc, argv, "01", &friction);
|
87
|
+
if (NIL_P(friction) || friction == Qnil) {
|
88
|
+
return rb_cpArbiterTotalImpulse(self);
|
89
|
+
}
|
90
|
+
/* Here, it's with friction */
|
91
|
+
return rb_cpArbiterTotalImpulseWithFriction(self);
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
static VALUE
|
96
|
+
rb_cpArbiterIgnore(VALUE self) {
|
97
|
+
cpArbiter *arb = ARBITER(self);
|
98
|
+
cpArbiterIgnore(arb);
|
99
|
+
return Qnil;
|
100
|
+
}
|
101
|
+
|
102
|
+
static VALUE
|
103
|
+
rb_cpArbiterGetShapes(VALUE self) {
|
104
|
+
cpArbiter *arb = ARBITER(self);
|
105
|
+
CP_ARBITER_GET_SHAPES(arb, a, b)
|
106
|
+
return rb_ary_new3(2, (VALUE)a->data, (VALUE)b->data);
|
107
|
+
}
|
108
|
+
|
109
|
+
static VALUE
|
110
|
+
rb_cpArbiterGetA(VALUE self) {
|
111
|
+
cpArbiter *arb = ARBITER(self);
|
112
|
+
CP_ARBITER_GET_SHAPES(arb, a, b)
|
113
|
+
return (VALUE)a->data;
|
114
|
+
}
|
115
|
+
|
116
|
+
static VALUE
|
117
|
+
rb_cpArbiterGetB(VALUE self) {
|
118
|
+
cpArbiter *arb = ARBITER(self);
|
119
|
+
CP_ARBITER_GET_SHAPES(arb, a, b)
|
120
|
+
return (VALUE)b->data;
|
121
|
+
}
|
122
|
+
|
123
|
+
static VALUE
|
124
|
+
rb_cpArbiterGetE(VALUE self) {
|
125
|
+
return rb_float_new(ARBITER(self)->e);
|
126
|
+
}
|
127
|
+
|
128
|
+
static VALUE
|
129
|
+
rb_cpArbiterSetE(VALUE self, VALUE e) {
|
130
|
+
ARBITER(self)->e = NUM2DBL(e);
|
131
|
+
return e;
|
132
|
+
}
|
133
|
+
|
134
|
+
static VALUE
|
135
|
+
rb_cpArbiterGetCount(VALUE self) {
|
136
|
+
return INT2NUM(cpArbiterGetCount(ARBITER(self)));
|
137
|
+
}
|
138
|
+
|
139
|
+
static VALUE
|
140
|
+
rb_cpArbiterGetU(VALUE self) {
|
141
|
+
return rb_float_new(ARBITER(self)->u);
|
142
|
+
}
|
143
|
+
|
144
|
+
static VALUE
|
145
|
+
rb_cpArbiterSetU(VALUE self, VALUE u) {
|
146
|
+
ARBITER(self)->u = NUM2DBL(u);
|
147
|
+
return u;
|
148
|
+
}
|
149
|
+
|
150
|
+
static VALUE
|
151
|
+
rb_cpArbiterIsFirstContact(VALUE self) {
|
152
|
+
int bool = cpArbiterIsFirstContact(ARBITER(self));
|
153
|
+
return bool ? Qtrue : Qfalse;
|
154
|
+
}
|
155
|
+
|
156
|
+
static int arbiterBadIndex(cpArbiter *arb, int i) {
|
157
|
+
return ((i<0) || (i >= cpArbiterGetCount(arb)));
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
static VALUE
|
162
|
+
rb_cpArbiterGetNormal(VALUE self, VALUE index) {
|
163
|
+
cpArbiter *arb = ARBITER(self);
|
164
|
+
int i = NUM2LONG(index);
|
165
|
+
if (arbiterBadIndex(arb, i)) {
|
166
|
+
rb_raise(rb_eIndexError, "No such normal.");
|
167
|
+
}
|
168
|
+
return VNEW(cpArbiterGetNormal(arb, i));
|
169
|
+
}
|
170
|
+
|
171
|
+
static VALUE
|
172
|
+
rb_cpArbiterGetPoint(VALUE self, VALUE index) {
|
173
|
+
cpArbiter *arb = ARBITER(self);
|
174
|
+
int i = NUM2LONG(index);
|
175
|
+
if (arbiterBadIndex(arb, i)) {
|
176
|
+
rb_raise(rb_eIndexError, "No such contact point.");
|
177
|
+
}
|
178
|
+
return VNEW(cpArbiterGetPoint(arb, i));
|
179
|
+
}
|
180
|
+
|
181
|
+
static VALUE
|
182
|
+
rb_cpArbiterGetDepth(VALUE self, VALUE index) {
|
183
|
+
cpArbiter *arb = ARBITER(self);
|
184
|
+
int i = NUM2LONG(index);
|
185
|
+
if (arbiterBadIndex(arb, i)) {
|
186
|
+
rb_raise(rb_eIndexError, "No such depth.");
|
187
|
+
}
|
188
|
+
// there"s a typo in the cpArbiter.h class.
|
189
|
+
return rb_float_new(cpArbiteGetDepth(arb, i));
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
static VALUE
|
194
|
+
rb_cpArbiterToString(VALUE self)
|
195
|
+
{
|
196
|
+
char str[256];
|
197
|
+
cpArbiter *arb = ARBITER(self);
|
198
|
+
sprintf(str, "#<CP::Arbiter:%p>", arb);
|
199
|
+
return rb_str_new2(str);
|
200
|
+
}
|
201
|
+
|
202
|
+
static VALUE
|
203
|
+
rb_cpArbiterEachContact(VALUE self)
|
204
|
+
{
|
205
|
+
cpArbiter *arb = ARBITER(self);
|
206
|
+
int i = 0;
|
207
|
+
for( i = 0; i < cpArbiterGetCount(arb); i++) {
|
208
|
+
VALUE index = INT2NUM(i);
|
209
|
+
VALUE contact, normal;
|
210
|
+
normal = rb_cpArbiterGetNormal(self, index);
|
211
|
+
contact = rb_cpArbiterGetPoint(self, index);
|
212
|
+
/* Yield an array of contact and normal */
|
213
|
+
rb_yield(rb_ary_new3(2, contact, normal));
|
214
|
+
}
|
215
|
+
return self;
|
216
|
+
}
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
void
|
221
|
+
Init_cpArbiter(void)
|
222
|
+
{
|
223
|
+
c_cpArbiter = rb_define_class_under(m_Chipmunk, "Arbiter", rb_cObject);
|
224
|
+
/*
|
225
|
+
rb_define_alloc_func(c_cpArbiter, rb_cpArbiterAlloc);
|
226
|
+
rb_define_method(c_cpArbiter , "initialize", rb_cpArbiterInitialize, 2);
|
227
|
+
*/
|
228
|
+
rb_define_method(c_cpArbiter, "a", rb_cpArbiterGetA, 0);
|
229
|
+
rb_define_method(c_cpArbiter, "b", rb_cpArbiterGetB, 0);
|
230
|
+
rb_define_method(c_cpArbiter, "e" , rb_cpArbiterGetE, 0);
|
231
|
+
rb_define_method(c_cpArbiter, "u" , rb_cpArbiterGetU, 0);
|
232
|
+
rb_define_method(c_cpArbiter, "e=", rb_cpArbiterSetE, 1);
|
233
|
+
rb_define_method(c_cpArbiter, "u=", rb_cpArbiterSetU, 1);
|
234
|
+
|
235
|
+
rb_define_method(c_cpArbiter, "point" , rb_cpArbiterGetPoint , 1);
|
236
|
+
rb_define_method(c_cpArbiter, "normal" , rb_cpArbiterGetNormal , 1);
|
237
|
+
rb_define_method(c_cpArbiter, "normal" , rb_cpArbiterGetDepth , 1);
|
238
|
+
rb_define_method(c_cpArbiter, "impulse" , rb_cpArbiterGetImpulse , -1);
|
239
|
+
|
240
|
+
rb_define_method(c_cpArbiter, "to_s", rb_cpArbiterToString, 0);
|
241
|
+
|
242
|
+
rb_define_method(c_cpArbiter, "first_contact?", rb_cpArbiterIsFirstContact, 0);
|
243
|
+
rb_define_method(c_cpArbiter, "count" , rb_cpArbiterGetCount, 0);
|
244
|
+
rb_define_method(c_cpArbiter, "contacts" , rb_cpArbiterGetCount, 0);
|
245
|
+
rb_define_method(c_cpArbiter, "size" , rb_cpArbiterGetCount, 0);
|
246
|
+
rb_define_method(c_cpArbiter, "length" , rb_cpArbiterGetCount, 0);
|
247
|
+
rb_define_method(c_cpArbiter, "each_contact" , rb_cpArbiterEachContact , 0);
|
248
|
+
|
249
|
+
rb_define_method(c_cpArbiter, "shapes" , rb_cpArbiterGetShapes , 0);
|
250
|
+
/* Ignore is new in the 5.x API, I think. */
|
251
|
+
rb_define_method(c_cpArbiter, "ignore" , rb_cpArbiterIgnore , 0);
|
252
|
+
|
253
|
+
}
|
@@ -0,0 +1,210 @@
|
|
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_cpBB;
|
29
|
+
|
30
|
+
static VALUE BBNEW(cpBB bb) {
|
31
|
+
cpBB *ptr = malloc(sizeof(cpBB));
|
32
|
+
*ptr = bb;
|
33
|
+
return Data_Wrap_Struct(c_cpBB, NULL, free, ptr);
|
34
|
+
}
|
35
|
+
|
36
|
+
static VALUE
|
37
|
+
rb_cpBBAlloc(VALUE klass)
|
38
|
+
{
|
39
|
+
cpBB *bb = malloc(sizeof(cpBB));
|
40
|
+
return Data_Wrap_Struct(klass, NULL, free, bb);
|
41
|
+
}
|
42
|
+
|
43
|
+
static VALUE
|
44
|
+
rb_cpBBInitialize(VALUE self, VALUE l, VALUE b, VALUE r, VALUE t)
|
45
|
+
{
|
46
|
+
cpBB *bb = BBGET(self);
|
47
|
+
bb->l = NUM2DBL(l);
|
48
|
+
bb->b = NUM2DBL(b);
|
49
|
+
bb->r = NUM2DBL(r);
|
50
|
+
bb->t = NUM2DBL(t);
|
51
|
+
|
52
|
+
return self;
|
53
|
+
}
|
54
|
+
|
55
|
+
static VALUE
|
56
|
+
rb_cpBBintersects(VALUE self, VALUE other)
|
57
|
+
{
|
58
|
+
int value = cpBBintersects(*BBGET(self), *BBGET(other));
|
59
|
+
return value ? Qtrue : Qfalse;
|
60
|
+
}
|
61
|
+
|
62
|
+
static VALUE
|
63
|
+
rb_cpBBcontainsBB(VALUE self, VALUE other)
|
64
|
+
{
|
65
|
+
int value = cpBBcontainsBB(*BBGET(self), *BBGET(other));
|
66
|
+
return value ? Qtrue : Qfalse;
|
67
|
+
}
|
68
|
+
|
69
|
+
static VALUE
|
70
|
+
rb_cpBBcontainsVect(VALUE self, VALUE other)
|
71
|
+
{
|
72
|
+
int value = cpBBcontainsVect(*BBGET(self), *VGET(other));
|
73
|
+
return value ? Qtrue : Qfalse;
|
74
|
+
}
|
75
|
+
|
76
|
+
static VALUE
|
77
|
+
rb_cpBBcontains(VALUE self, VALUE other)
|
78
|
+
{
|
79
|
+
if (rb_class_of(other) == c_cpBB) {
|
80
|
+
return rb_cpBBcontainsBB(self, other);
|
81
|
+
} else if (rb_class_of(other) == c_cpVect) {
|
82
|
+
return rb_cpBBcontainsVect(self, other);
|
83
|
+
}
|
84
|
+
rb_raise(rb_eArgError, "contains works only with a BB or A Vect2 argument");
|
85
|
+
return Qnil;
|
86
|
+
}
|
87
|
+
|
88
|
+
static VALUE
|
89
|
+
rb_cpBBClampVect(VALUE self, VALUE v)
|
90
|
+
{
|
91
|
+
return VNEW(cpBBClampVect(*BBGET(self), *VGET(v)));
|
92
|
+
}
|
93
|
+
|
94
|
+
static VALUE
|
95
|
+
rb_cpBBWrapVect(VALUE self, VALUE v)
|
96
|
+
{
|
97
|
+
return VNEW(cpBBWrapVect(*BBGET(self), *VGET(v)));
|
98
|
+
}
|
99
|
+
|
100
|
+
static VALUE
|
101
|
+
rb_cpBBGetL(VALUE self)
|
102
|
+
{
|
103
|
+
return rb_float_new(BBGET(self)->l);
|
104
|
+
}
|
105
|
+
|
106
|
+
static VALUE
|
107
|
+
rb_cpBBGetB(VALUE self)
|
108
|
+
{
|
109
|
+
return rb_float_new(BBGET(self)->b);
|
110
|
+
}
|
111
|
+
|
112
|
+
static VALUE
|
113
|
+
rb_cpBBGetR(VALUE self)
|
114
|
+
{
|
115
|
+
return rb_float_new(BBGET(self)->r);
|
116
|
+
}
|
117
|
+
|
118
|
+
static VALUE
|
119
|
+
rb_cpBBGetT(VALUE self)
|
120
|
+
{
|
121
|
+
return rb_float_new(BBGET(self)->t);
|
122
|
+
}
|
123
|
+
|
124
|
+
static VALUE
|
125
|
+
rb_cpBBSetL(VALUE self, VALUE val)
|
126
|
+
{
|
127
|
+
BBGET(self)->l = NUM2DBL(val);
|
128
|
+
return val;
|
129
|
+
}
|
130
|
+
|
131
|
+
static VALUE
|
132
|
+
rb_cpBBSetB(VALUE self, VALUE val)
|
133
|
+
{
|
134
|
+
BBGET(self)->b = NUM2DBL(val);
|
135
|
+
return val;
|
136
|
+
}
|
137
|
+
|
138
|
+
static VALUE
|
139
|
+
rb_cpBBSetR(VALUE self, VALUE val)
|
140
|
+
{
|
141
|
+
BBGET(self)->r = NUM2DBL(val);
|
142
|
+
return val;
|
143
|
+
}
|
144
|
+
|
145
|
+
static VALUE
|
146
|
+
rb_cpBBSetT(VALUE self, VALUE val)
|
147
|
+
{
|
148
|
+
BBGET(self)->t = NUM2DBL(val);
|
149
|
+
return val;
|
150
|
+
}
|
151
|
+
|
152
|
+
static VALUE
|
153
|
+
rb_cpBBToString(VALUE self)
|
154
|
+
{
|
155
|
+
char str[256];
|
156
|
+
cpBB *bb = BBGET(self);
|
157
|
+
|
158
|
+
sprintf(str, "#<CP::BB:(% .3f, % .3f) -> (% .3f, % .3f)>", bb->l, bb->b, bb->r, bb->t);
|
159
|
+
|
160
|
+
return rb_str_new2(str);
|
161
|
+
}
|
162
|
+
|
163
|
+
static VALUE
|
164
|
+
rb_cpBBmerge(VALUE self, VALUE other) {
|
165
|
+
return BBNEW(cpBBmerge(*BBGET(self), *BBGET(other)));
|
166
|
+
}
|
167
|
+
|
168
|
+
static VALUE
|
169
|
+
rb_cpBBexpand(VALUE self, VALUE other) {
|
170
|
+
return BBNEW(cpBBexpand(*BBGET(self), *VGET(other)));
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
void
|
175
|
+
Init_cpBB(void)
|
176
|
+
{
|
177
|
+
c_cpBB = rb_define_class_under(m_Chipmunk, "BB", rb_cObject);
|
178
|
+
rb_define_alloc_func(c_cpBB, rb_cpBBAlloc);
|
179
|
+
rb_define_method(c_cpBB, "initialize", rb_cpBBInitialize, 4);
|
180
|
+
|
181
|
+
rb_define_method(c_cpBB, "l", rb_cpBBGetL, 0);
|
182
|
+
rb_define_method(c_cpBB, "b", rb_cpBBGetB, 0);
|
183
|
+
rb_define_method(c_cpBB, "r", rb_cpBBGetR, 0);
|
184
|
+
rb_define_method(c_cpBB, "t", rb_cpBBGetT, 0);
|
185
|
+
|
186
|
+
rb_define_method(c_cpBB, "l=", rb_cpBBSetL, 1);
|
187
|
+
rb_define_method(c_cpBB, "b=", rb_cpBBSetB, 1);
|
188
|
+
rb_define_method(c_cpBB, "r=", rb_cpBBSetR, 1);
|
189
|
+
rb_define_method(c_cpBB, "t=", rb_cpBBSetT, 1);
|
190
|
+
|
191
|
+
rb_define_method(c_cpBB, "intersect?", rb_cpBBintersects, 1);
|
192
|
+
rb_define_method(c_cpBB, "intersects?", rb_cpBBintersects, 1);
|
193
|
+
//containsBB
|
194
|
+
//containsVect
|
195
|
+
rb_define_method(c_cpBB, "contains?", rb_cpBBcontains, 1);
|
196
|
+
rb_define_method(c_cpBB, "contain?", rb_cpBBcontains, 1);
|
197
|
+
|
198
|
+
rb_define_method(c_cpBB, "contains_bb?", rb_cpBBcontainsBB, 1);
|
199
|
+
rb_define_method(c_cpBB, "contain_bb?", rb_cpBBcontainsBB, 1);
|
200
|
+
rb_define_method(c_cpBB, "contains_vect?", rb_cpBBcontainsVect, 1);
|
201
|
+
rb_define_method(c_cpBB, "contain_vect?", rb_cpBBcontainsVect, 1);
|
202
|
+
|
203
|
+
rb_define_method(c_cpBB, "clamp_vect", rb_cpBBClampVect, 1);
|
204
|
+
rb_define_method(c_cpBB, "wrap_vect" , rb_cpBBWrapVect, 1);
|
205
|
+
rb_define_method(c_cpBB, "merge" , rb_cpBBmerge, 1);
|
206
|
+
rb_define_method(c_cpBB, "expand" , rb_cpBBexpand, 1);
|
207
|
+
|
208
|
+
|
209
|
+
rb_define_method(c_cpBB, "to_s", rb_cpBBToString, 0);
|
210
|
+
}
|