chipmunk 4.1.0-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +38 -0
- data/ext/chipmunk/chipmunk.c +69 -0
- data/ext/chipmunk/chipmunk.h +91 -0
- data/ext/chipmunk/cpArbiter.c +263 -0
- data/ext/chipmunk/cpArbiter.h +85 -0
- data/ext/chipmunk/cpArray.c +114 -0
- data/ext/chipmunk/cpArray.h +45 -0
- data/ext/chipmunk/cpBB.c +46 -0
- data/ext/chipmunk/cpBB.h +53 -0
- data/ext/chipmunk/cpBody.c +180 -0
- data/ext/chipmunk/cpBody.h +132 -0
- data/ext/chipmunk/cpCollision.c +390 -0
- data/ext/chipmunk/cpCollision.h +23 -0
- data/ext/chipmunk/cpHashSet.c +219 -0
- data/ext/chipmunk/cpHashSet.h +79 -0
- data/ext/chipmunk/cpJoint.c +553 -0
- data/ext/chipmunk/cpJoint.h +122 -0
- data/ext/chipmunk/cpPolyShape.c +139 -0
- data/ext/chipmunk/cpPolyShape.h +92 -0
- data/ext/chipmunk/cpShape.c +244 -0
- data/ext/chipmunk/cpShape.h +141 -0
- data/ext/chipmunk/cpSpace.c +530 -0
- data/ext/chipmunk/cpSpace.h +120 -0
- data/ext/chipmunk/cpSpaceHash.c +455 -0
- data/ext/chipmunk/cpSpaceHash.h +100 -0
- data/ext/chipmunk/cpVect.c +63 -0
- data/ext/chipmunk/cpVect.h +106 -0
- data/ext/chipmunk/extconf.rb +4 -0
- data/ext/chipmunk/prime.h +68 -0
- data/ext/chipmunk/rb_chipmunk.c +109 -0
- data/ext/chipmunk/rb_chipmunk.h +77 -0
- data/ext/chipmunk/rb_cpBB.c +154 -0
- data/ext/chipmunk/rb_cpBody.c +239 -0
- data/ext/chipmunk/rb_cpJoint.c +136 -0
- data/ext/chipmunk/rb_cpShape.c +292 -0
- data/ext/chipmunk/rb_cpSpace.c +330 -0
- data/ext/chipmunk/rb_cpVect.c +250 -0
- data/lib/1.8/chipmunk.so +0 -0
- data/lib/1.9/chipmunk.so +0 -0
- data/lib/chipmunk.rb +15 -0
- metadata +92 -0
@@ -0,0 +1,100 @@
|
|
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
|
+
// The spatial hash is Chipmunk's default (and currently only) spatial index type.
|
23
|
+
// Based on a chained hash table.
|
24
|
+
|
25
|
+
// Used internally to track objects added to the hash
|
26
|
+
typedef struct cpHandle{
|
27
|
+
// Pointer to the object
|
28
|
+
void *obj;
|
29
|
+
// Retain count
|
30
|
+
int retain;
|
31
|
+
// Query stamp. Used to make sure two objects
|
32
|
+
// aren't identified twice in the same query.
|
33
|
+
int stamp;
|
34
|
+
} cpHandle;
|
35
|
+
|
36
|
+
// Linked list element for in the chains.
|
37
|
+
typedef struct cpSpaceHashBin{
|
38
|
+
cpHandle *handle;
|
39
|
+
struct cpSpaceHashBin *next;
|
40
|
+
} cpSpaceHashBin;
|
41
|
+
|
42
|
+
// BBox callback. Called whenever the hash needs a bounding box from an object.
|
43
|
+
typedef cpBB (*cpSpaceHashBBFunc)(void *obj);
|
44
|
+
|
45
|
+
typedef struct cpSpaceHash{
|
46
|
+
// Number of cells in the table.
|
47
|
+
int numcells;
|
48
|
+
// Dimentions of the cells.
|
49
|
+
cpFloat celldim;
|
50
|
+
|
51
|
+
// BBox callback.
|
52
|
+
cpSpaceHashBBFunc bbfunc;
|
53
|
+
|
54
|
+
// Hashset of all the handles.
|
55
|
+
cpHashSet *handleSet;
|
56
|
+
|
57
|
+
cpSpaceHashBin **table;
|
58
|
+
// List of recycled bins.
|
59
|
+
cpSpaceHashBin *bins;
|
60
|
+
|
61
|
+
// Incremented on each query. See cpHandle.stamp.
|
62
|
+
int stamp;
|
63
|
+
} cpSpaceHash;
|
64
|
+
|
65
|
+
//Basic allocation/destruction functions.
|
66
|
+
cpSpaceHash *cpSpaceHashAlloc(void);
|
67
|
+
cpSpaceHash *cpSpaceHashInit(cpSpaceHash *hash, cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc);
|
68
|
+
cpSpaceHash *cpSpaceHashNew(cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc);
|
69
|
+
|
70
|
+
void cpSpaceHashDestroy(cpSpaceHash *hash);
|
71
|
+
void cpSpaceHashFree(cpSpaceHash *hash);
|
72
|
+
|
73
|
+
// Resize the hashtable. (Does not rehash! You must call cpSpaceHashRehash() if needed.)
|
74
|
+
void cpSpaceHashResize(cpSpaceHash *hash, cpFloat celldim, int numcells);
|
75
|
+
|
76
|
+
// Add an object to the hash.
|
77
|
+
void cpSpaceHashInsert(cpSpaceHash *hash, void *obj, unsigned int id, cpBB bb);
|
78
|
+
// Remove an object from the hash.
|
79
|
+
void cpSpaceHashRemove(cpSpaceHash *hash, void *obj, unsigned int id);
|
80
|
+
|
81
|
+
// Iterator function
|
82
|
+
typedef void (*cpSpaceHashIterator)(void *obj, void *data);
|
83
|
+
// Iterate over the objects in the hash.
|
84
|
+
void cpSpaceHashEach(cpSpaceHash *hash, cpSpaceHashIterator func, void *data);
|
85
|
+
|
86
|
+
// Rehash the contents of the hash.
|
87
|
+
void cpSpaceHashRehash(cpSpaceHash *hash);
|
88
|
+
// Rehash only a specific object.
|
89
|
+
void cpSpaceHashRehashObject(cpSpaceHash *hash, void *obj, unsigned int id);
|
90
|
+
|
91
|
+
// Query callback.
|
92
|
+
typedef int (*cpSpaceHashQueryFunc)(void *obj1, void *obj2, void *data);
|
93
|
+
// Point query the hash. A reference to the query point is passed as obj1 to the query callback.
|
94
|
+
void cpSpaceHashPointQuery(cpSpaceHash *hash, cpVect point, cpSpaceHashQueryFunc func, void *data);
|
95
|
+
// Query the hash for a given BBox.
|
96
|
+
void cpSpaceHashQuery(cpSpaceHash *hash, void *obj, cpBB bb, cpSpaceHashQueryFunc func, void *data);
|
97
|
+
// Run a query for the object, then insert it. (Optimized case)
|
98
|
+
void cpSpaceHashQueryInsert(cpSpaceHash *hash, void *obj, cpBB bb, cpSpaceHashQueryFunc func, void *data);
|
99
|
+
// Rehashes while querying for each object. (Optimized case)
|
100
|
+
void cpSpaceHashQueryRehash(cpSpaceHash *hash, cpSpaceHashQueryFunc func, void *data);
|
@@ -0,0 +1,63 @@
|
|
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 "stdio.h"
|
23
|
+
#include "math.h"
|
24
|
+
|
25
|
+
#include "chipmunk.h"
|
26
|
+
|
27
|
+
cpFloat
|
28
|
+
cpvlength(const cpVect v)
|
29
|
+
{
|
30
|
+
return sqrtf( cpvdot(v, v) );
|
31
|
+
}
|
32
|
+
|
33
|
+
cpFloat
|
34
|
+
cpvlengthsq(const cpVect v)
|
35
|
+
{
|
36
|
+
return cpvdot(v, v);
|
37
|
+
}
|
38
|
+
|
39
|
+
cpVect
|
40
|
+
cpvnormalize(const cpVect v)
|
41
|
+
{
|
42
|
+
return cpvmult( v, 1.0f/cpvlength(v) );
|
43
|
+
}
|
44
|
+
|
45
|
+
cpVect
|
46
|
+
cpvforangle(const cpFloat a)
|
47
|
+
{
|
48
|
+
return cpv(cos(a), sin(a));
|
49
|
+
}
|
50
|
+
|
51
|
+
cpFloat
|
52
|
+
cpvtoangle(const cpVect v)
|
53
|
+
{
|
54
|
+
return atan2(v.y, v.x);
|
55
|
+
}
|
56
|
+
|
57
|
+
char*
|
58
|
+
cpvstr(const cpVect v)
|
59
|
+
{
|
60
|
+
static char str[256];
|
61
|
+
sprintf(str, "(% .3f, % .3f)", v.x, v.y);
|
62
|
+
return str;
|
63
|
+
}
|
@@ -0,0 +1,106 @@
|
|
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
|
+
typedef struct cpVect{
|
23
|
+
cpFloat x,y;
|
24
|
+
} cpVect;
|
25
|
+
|
26
|
+
static const cpVect cpvzero={0.0f,0.0f};
|
27
|
+
|
28
|
+
static inline cpVect
|
29
|
+
cpv(const cpFloat x, const cpFloat y)
|
30
|
+
{
|
31
|
+
cpVect v = {x, y};
|
32
|
+
return v;
|
33
|
+
}
|
34
|
+
|
35
|
+
static inline cpVect
|
36
|
+
cpvadd(const cpVect v1, const cpVect v2)
|
37
|
+
{
|
38
|
+
return cpv(v1.x + v2.x, v1.y + v2.y);
|
39
|
+
}
|
40
|
+
|
41
|
+
static inline cpVect
|
42
|
+
cpvneg(const cpVect v)
|
43
|
+
{
|
44
|
+
return cpv(-v.x, -v.y);
|
45
|
+
}
|
46
|
+
|
47
|
+
static inline cpVect
|
48
|
+
cpvsub(const cpVect v1, const cpVect v2)
|
49
|
+
{
|
50
|
+
return cpv(v1.x - v2.x, v1.y - v2.y);
|
51
|
+
}
|
52
|
+
|
53
|
+
static inline cpVect
|
54
|
+
cpvmult(const cpVect v, const cpFloat s)
|
55
|
+
{
|
56
|
+
return cpv(v.x*s, v.y*s);
|
57
|
+
}
|
58
|
+
|
59
|
+
static inline cpFloat
|
60
|
+
cpvdot(const cpVect v1, const cpVect v2)
|
61
|
+
{
|
62
|
+
return v1.x*v2.x + v1.y*v2.y;
|
63
|
+
}
|
64
|
+
|
65
|
+
static inline cpFloat
|
66
|
+
cpvcross(const cpVect v1, const cpVect v2)
|
67
|
+
{
|
68
|
+
return v1.x*v2.y - v1.y*v2.x;
|
69
|
+
}
|
70
|
+
|
71
|
+
static inline cpVect
|
72
|
+
cpvperp(const cpVect v)
|
73
|
+
{
|
74
|
+
return cpv(-v.y, v.x);
|
75
|
+
}
|
76
|
+
|
77
|
+
static inline cpVect
|
78
|
+
cpvrperp(const cpVect v)
|
79
|
+
{
|
80
|
+
return cpv(v.y, -v.x);
|
81
|
+
}
|
82
|
+
|
83
|
+
static inline cpVect
|
84
|
+
cpvproject(const cpVect v1, const cpVect v2)
|
85
|
+
{
|
86
|
+
return cpvmult(v2, cpvdot(v1, v2)/cpvdot(v2, v2));
|
87
|
+
}
|
88
|
+
|
89
|
+
static inline cpVect
|
90
|
+
cpvrotate(const cpVect v1, const cpVect v2)
|
91
|
+
{
|
92
|
+
return cpv(v1.x*v2.x - v1.y*v2.y, v1.x*v2.y + v1.y*v2.x);
|
93
|
+
}
|
94
|
+
|
95
|
+
static inline cpVect
|
96
|
+
cpvunrotate(const cpVect v1, const cpVect v2)
|
97
|
+
{
|
98
|
+
return cpv(v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y);
|
99
|
+
}
|
100
|
+
|
101
|
+
cpFloat cpvlength(const cpVect v);
|
102
|
+
cpFloat cpvlengthsq(const cpVect v); // no sqrt() call
|
103
|
+
cpVect cpvnormalize(const cpVect v);
|
104
|
+
cpVect cpvforangle(const cpFloat a); // convert radians to a normalized vector
|
105
|
+
cpFloat cpvtoangle(const cpVect v); // convert a vector to radians
|
106
|
+
char *cpvstr(const cpVect v); // get a string representation of a vector
|
@@ -0,0 +1,68 @@
|
|
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
|
+
// Used for resizing hash tables.
|
23
|
+
// Values approximately double.
|
24
|
+
|
25
|
+
static int primes[] = {
|
26
|
+
5, //2^2 + 1
|
27
|
+
11, //2^3 + 3
|
28
|
+
17, //2^4 + 1
|
29
|
+
37, //2^5 + 5
|
30
|
+
67, //2^6 + 3
|
31
|
+
131, //2^7 + 3
|
32
|
+
257, //2^8 + 1
|
33
|
+
521, //2^9 + 9
|
34
|
+
1031, //2^10 + 7
|
35
|
+
2053, //2^11 + 5
|
36
|
+
4099, //2^12 + 3
|
37
|
+
8209, //2^13 + 17
|
38
|
+
16411, //2^14 + 27
|
39
|
+
32771, //2^15 + 3
|
40
|
+
65537, //2^16 + 1
|
41
|
+
131101, //2^17 + 29
|
42
|
+
262147, //2^18 + 3
|
43
|
+
524309, //2^19 + 21
|
44
|
+
1048583, //2^20 + 7
|
45
|
+
2097169, //2^21 + 17
|
46
|
+
4194319, //2^22 + 15
|
47
|
+
8388617, //2^23 + 9
|
48
|
+
16777259, //2^24 + 43
|
49
|
+
33554467, //2^25 + 35
|
50
|
+
67108879, //2^26 + 15
|
51
|
+
134217757, //2^27 + 29
|
52
|
+
268435459, //2^28 + 3
|
53
|
+
536870923, //2^29 + 11
|
54
|
+
1073741827, //2^30 + 3
|
55
|
+
0,
|
56
|
+
};
|
57
|
+
|
58
|
+
static int
|
59
|
+
next_prime(int n)
|
60
|
+
{
|
61
|
+
int i = 0;
|
62
|
+
while(n > primes[i]){
|
63
|
+
i++;
|
64
|
+
assert(primes[i]); // realistically this should never happen
|
65
|
+
}
|
66
|
+
|
67
|
+
return primes[i];
|
68
|
+
}
|
@@ -0,0 +1,109 @@
|
|
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 m_Chipmunk;
|
28
|
+
|
29
|
+
ID id_parent;
|
30
|
+
|
31
|
+
static VALUE
|
32
|
+
rb_get_cp_bias_coef(VALUE self)
|
33
|
+
{
|
34
|
+
return rb_float_new(cp_bias_coef);
|
35
|
+
}
|
36
|
+
|
37
|
+
static VALUE
|
38
|
+
rb_set_cp_bias_coef(VALUE self, VALUE num)
|
39
|
+
{
|
40
|
+
cp_bias_coef = NUM2DBL(num);
|
41
|
+
return num;
|
42
|
+
}
|
43
|
+
|
44
|
+
static VALUE
|
45
|
+
rb_get_cp_collision_slop(VALUE self)
|
46
|
+
{
|
47
|
+
return rb_float_new(cp_collision_slop);
|
48
|
+
}
|
49
|
+
|
50
|
+
static VALUE
|
51
|
+
rb_set_cp_collision_slop(VALUE self, VALUE num)
|
52
|
+
{
|
53
|
+
cp_collision_slop = NUM2DBL(num);
|
54
|
+
return num;
|
55
|
+
}
|
56
|
+
|
57
|
+
static VALUE
|
58
|
+
rb_momentForCircle(VALUE self, VALUE m, VALUE r1, VALUE r2, VALUE offset)
|
59
|
+
{
|
60
|
+
cpFloat i = cpMomentForCircle(NUM2DBL(m), NUM2DBL(r1), NUM2DBL(r2), *VGET(offset));
|
61
|
+
return rb_float_new(i);
|
62
|
+
}
|
63
|
+
|
64
|
+
static VALUE
|
65
|
+
rb_momentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset)
|
66
|
+
{
|
67
|
+
Check_Type(arr, T_ARRAY);
|
68
|
+
int numVerts = RARRAY_LEN(arr);
|
69
|
+
cpVect verts[numVerts];
|
70
|
+
|
71
|
+
for(int i=0; i<numVerts; i++)
|
72
|
+
verts[i] = *VGET(RARRAY_PTR(arr)[i]);
|
73
|
+
|
74
|
+
cpFloat inertia = cpMomentForPoly(NUM2DBL(m), numVerts, verts, *VGET(offset));
|
75
|
+
return rb_float_new(inertia);
|
76
|
+
}
|
77
|
+
|
78
|
+
static VALUE
|
79
|
+
rb_dampedSpring(VALUE self, VALUE a, VALUE b, VALUE r1, VALUE r2, VALUE len, VALUE k, VALUE dmp, VALUE dt)
|
80
|
+
{
|
81
|
+
cpDampedSpring(BODY(a), BODY(b), *VGET(r1), *VGET(r2), NUM2DBL(len), NUM2DBL(k), NUM2DBL(dmp), NUM2DBL(dt));
|
82
|
+
return Qnil;
|
83
|
+
}
|
84
|
+
|
85
|
+
void
|
86
|
+
Init_chipmunk(void)
|
87
|
+
{
|
88
|
+
id_parent = rb_intern("parent");
|
89
|
+
|
90
|
+
cpInitChipmunk();
|
91
|
+
|
92
|
+
m_Chipmunk = rb_define_module("CP");
|
93
|
+
rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0);
|
94
|
+
rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1);
|
95
|
+
rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0);
|
96
|
+
rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1);
|
97
|
+
|
98
|
+
rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_momentForCircle, 4);
|
99
|
+
rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_momentForPoly, 3);
|
100
|
+
|
101
|
+
rb_define_module_function(m_Chipmunk, "damped_spring", rb_dampedSpring, 8);
|
102
|
+
|
103
|
+
Init_cpVect();
|
104
|
+
Init_cpBB();
|
105
|
+
Init_cpBody();
|
106
|
+
Init_cpShape();
|
107
|
+
Init_cpJoint();
|
108
|
+
Init_cpSpace();
|
109
|
+
}
|