chipmunk 4.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +60 -0
- data/Rakefile +47 -40
- data/ext/chipmunk/chipmunk.c +39 -3
- data/ext/chipmunk/cpArbiter.c +91 -80
- data/ext/chipmunk/cpArray.c +24 -10
- data/ext/chipmunk/cpBB.c +5 -4
- data/ext/chipmunk/cpBody.c +30 -22
- data/ext/chipmunk/cpCollision.c +54 -53
- data/ext/chipmunk/cpConstraint.c +54 -0
- data/ext/chipmunk/cpDampedRotarySpring.c +106 -0
- data/ext/chipmunk/cpDampedSpring.c +117 -0
- data/ext/chipmunk/cpGearJoint.c +114 -0
- data/ext/chipmunk/cpGrooveJoint.c +138 -0
- data/ext/chipmunk/cpHashSet.c +74 -40
- data/ext/chipmunk/cpPinJoint.c +117 -0
- data/ext/chipmunk/cpPivotJoint.c +114 -0
- data/ext/chipmunk/cpPolyShape.c +117 -15
- data/ext/chipmunk/cpRatchetJoint.c +128 -0
- data/ext/chipmunk/cpRotaryLimitJoint.c +122 -0
- data/ext/chipmunk/cpShape.c +174 -18
- data/ext/chipmunk/cpSimpleMotor.c +99 -0
- data/ext/chipmunk/cpSlideJoint.c +131 -0
- data/ext/chipmunk/cpSpace.c +584 -215
- data/ext/chipmunk/cpSpaceHash.c +191 -105
- data/ext/chipmunk/cpVect.c +18 -10
- data/ext/chipmunk/extconf.rb +34 -4
- data/ext/chipmunk/{chipmunk.h → include/chipmunk/chipmunk.h} +63 -6
- data/ext/chipmunk/include/chipmunk/chipmunk_ffi.h +42 -0
- data/ext/chipmunk/include/chipmunk/chipmunk_types.h +80 -0
- data/ext/chipmunk/include/chipmunk/chipmunk_unsafe.h +54 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpConstraint.h +92 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpDampedRotarySpring.h +46 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpDampedSpring.h +53 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpGearJoint.h +41 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpGrooveJoint.h +44 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpPinJoint.h +43 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpPivotJoint.h +42 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpRatchetJoint.h +40 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpRotaryLimitJoint.h +39 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpSimpleMotor.h +37 -0
- data/ext/chipmunk/include/chipmunk/constraints/cpSlideJoint.h +44 -0
- data/ext/chipmunk/include/chipmunk/constraints/util.h +116 -0
- data/ext/chipmunk/{cpArbiter.h → include/chipmunk/cpArbiter.h} +66 -15
- data/ext/chipmunk/{cpArray.h → include/chipmunk/cpArray.h} +2 -1
- data/ext/chipmunk/{cpBB.h → include/chipmunk/cpBB.h} +21 -0
- data/ext/chipmunk/{cpBody.h → include/chipmunk/cpBody.h} +37 -9
- data/ext/chipmunk/{cpCollision.h → include/chipmunk/cpCollision.h} +1 -1
- data/ext/chipmunk/{cpHashSet.h → include/chipmunk/cpHashSet.h} +12 -9
- data/ext/chipmunk/{cpPolyShape.h → include/chipmunk/cpPolyShape.h} +13 -2
- data/ext/chipmunk/{cpShape.h → include/chipmunk/cpShape.h} +51 -18
- data/ext/chipmunk/include/chipmunk/cpSpace.h +180 -0
- data/ext/chipmunk/{cpSpaceHash.h → include/chipmunk/cpSpaceHash.h} +18 -9
- data/ext/chipmunk/{cpVect.h → include/chipmunk/cpVect.h} +61 -10
- data/ext/chipmunk/prime.h +32 -32
- data/ext/chipmunk/rb_chipmunk.c +125 -109
- data/ext/chipmunk/rb_chipmunk.h +96 -77
- data/ext/chipmunk/rb_cpArbiter.c +225 -0
- data/ext/chipmunk/rb_cpBB.c +174 -154
- data/ext/chipmunk/rb_cpBody.c +347 -239
- data/ext/chipmunk/rb_cpConstraint.c +346 -0
- data/ext/chipmunk/rb_cpShape.c +455 -292
- data/ext/chipmunk/rb_cpSpace.c +544 -330
- data/ext/chipmunk/rb_cpVect.c +321 -250
- data/lib/chipmunk.rb +28 -15
- data/lib/chipmunk/version.rb +3 -0
- metadata +74 -34
- data/ext/chipmunk/cpJoint.c +0 -553
- data/ext/chipmunk/cpJoint.h +0 -122
- data/ext/chipmunk/cpSpace.h +0 -120
- data/ext/chipmunk/rb_cpJoint.c +0 -136
data/ext/chipmunk/cpVect.c
CHANGED
@@ -19,39 +19,47 @@
|
|
19
19
|
* SOFTWARE.
|
20
20
|
*/
|
21
21
|
|
22
|
-
#include
|
23
|
-
#include
|
22
|
+
#include <stdio.h>
|
23
|
+
#include <math.h>
|
24
24
|
|
25
25
|
#include "chipmunk.h"
|
26
26
|
|
27
27
|
cpFloat
|
28
28
|
cpvlength(const cpVect v)
|
29
29
|
{
|
30
|
-
return
|
30
|
+
return cpfsqrt( cpvdot(v, v) );
|
31
31
|
}
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
inline cpVect
|
34
|
+
cpvslerp(const cpVect v1, const cpVect v2, const cpFloat t)
|
35
35
|
{
|
36
|
-
|
36
|
+
cpFloat omega = cpfacos(cpvdot(v1, v2));
|
37
|
+
|
38
|
+
if(omega){
|
39
|
+
cpFloat denom = 1.0f/cpfsin(omega);
|
40
|
+
return cpvadd(cpvmult(v1, cpfsin((1.0f - t)*omega)*denom), cpvmult(v2, cpfsin(t*omega)*denom));
|
41
|
+
} else {
|
42
|
+
return v1;
|
43
|
+
}
|
37
44
|
}
|
38
45
|
|
39
46
|
cpVect
|
40
|
-
|
47
|
+
cpvslerpconst(const cpVect v1, const cpVect v2, const cpFloat a)
|
41
48
|
{
|
42
|
-
|
49
|
+
cpFloat angle = cpfacos(cpvdot(v1, v2));
|
50
|
+
return cpvslerp(v1, v2, cpfmin(a, angle)/angle);
|
43
51
|
}
|
44
52
|
|
45
53
|
cpVect
|
46
54
|
cpvforangle(const cpFloat a)
|
47
55
|
{
|
48
|
-
return cpv(
|
56
|
+
return cpv(cpfcos(a), cpfsin(a));
|
49
57
|
}
|
50
58
|
|
51
59
|
cpFloat
|
52
60
|
cpvtoangle(const cpVect v)
|
53
61
|
{
|
54
|
-
return
|
62
|
+
return cpfatan2(v.y, v.x);
|
55
63
|
}
|
56
64
|
|
57
65
|
char*
|
data/ext/chipmunk/extconf.rb
CHANGED
@@ -1,4 +1,34 @@
|
|
1
|
-
require 'mkmf'
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
+
create_makefile('chipmunk')
|
34
|
+
|
@@ -25,8 +25,21 @@
|
|
25
25
|
#ifdef __cplusplus
|
26
26
|
extern "C" {
|
27
27
|
#endif
|
28
|
-
|
29
|
-
|
28
|
+
|
29
|
+
void cpMessage(char *message, char *condition, char *file, int line, int isError);
|
30
|
+
#ifdef NDEBUG
|
31
|
+
#define cpAssertWarn(condition, message)
|
32
|
+
#else
|
33
|
+
#define cpAssertWarn(condition, message) if(!(condition)) cpMessage(message, #condition, __FILE__, __LINE__, 0)
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#ifdef NDEBUG
|
37
|
+
#define cpAssert(condition, message)
|
38
|
+
#else
|
39
|
+
#define cpAssert(condition, message) if(!(condition)) cpMessage(message, #condition, __FILE__, __LINE__, 1)
|
40
|
+
#endif
|
41
|
+
|
42
|
+
#include "chipmunk_types.h"
|
30
43
|
|
31
44
|
static inline cpFloat
|
32
45
|
cpfmax(cpFloat a, cpFloat b)
|
@@ -41,10 +54,29 @@ cpfmin(cpFloat a, cpFloat b)
|
|
41
54
|
}
|
42
55
|
|
43
56
|
static inline cpFloat
|
44
|
-
|
57
|
+
cpfabs(cpFloat n)
|
58
|
+
{
|
59
|
+
return (n < 0) ? -n : n;
|
60
|
+
}
|
61
|
+
|
62
|
+
static inline cpFloat
|
63
|
+
cpfclamp(cpFloat f, cpFloat min, cpFloat max)
|
64
|
+
{
|
45
65
|
return cpfmin(cpfmax(f, min), max);
|
46
66
|
}
|
47
67
|
|
68
|
+
static inline cpFloat
|
69
|
+
cpflerp(cpFloat f1, cpFloat f2, cpFloat t)
|
70
|
+
{
|
71
|
+
return f1*(1.0f - t) + f2*t;
|
72
|
+
}
|
73
|
+
|
74
|
+
static inline cpFloat
|
75
|
+
cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d)
|
76
|
+
{
|
77
|
+
return f1 + cpfclamp(f2 - f1, -d, d);
|
78
|
+
}
|
79
|
+
|
48
80
|
#ifndef INFINITY
|
49
81
|
#ifdef _MSC_VER
|
50
82
|
union MSVC_EVIL_FLOAT_HACK
|
@@ -54,11 +86,25 @@ cpfclamp(cpFloat f, cpFloat min, cpFloat max){
|
|
54
86
|
};
|
55
87
|
static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
|
56
88
|
#define INFINITY (INFINITY_HACK.Value)
|
57
|
-
#
|
89
|
+
#endif
|
90
|
+
|
91
|
+
#ifdef __GNUC__
|
92
|
+
#define INFINITY (__builtin_inf())
|
93
|
+
#endif
|
94
|
+
|
95
|
+
#ifndef INFINITY
|
58
96
|
#define INFINITY (1e1000)
|
59
97
|
#endif
|
60
98
|
#endif
|
61
99
|
|
100
|
+
// Maximum allocated size for various Chipmunk buffer sizes
|
101
|
+
#define CP_BUFFER_BYTES (32*1024)
|
102
|
+
|
103
|
+
#define cpmalloc malloc
|
104
|
+
#define cpcalloc calloc
|
105
|
+
#define cprealloc realloc
|
106
|
+
#define cpfree free
|
107
|
+
|
62
108
|
#include "cpVect.h"
|
63
109
|
#include "cpBB.h"
|
64
110
|
#include "cpBody.h"
|
@@ -72,18 +118,29 @@ cpfclamp(cpFloat f, cpFloat min, cpFloat max){
|
|
72
118
|
#include "cpArbiter.h"
|
73
119
|
#include "cpCollision.h"
|
74
120
|
|
75
|
-
#include "
|
121
|
+
#include "constraints/cpConstraint.h"
|
76
122
|
|
77
123
|
#include "cpSpace.h"
|
78
124
|
|
79
125
|
#define CP_HASH_COEF (3344921057ul)
|
80
|
-
#define CP_HASH_PAIR(A, B) ((
|
126
|
+
#define CP_HASH_PAIR(A, B) ((cpHashValue)(A)*CP_HASH_COEF ^ (cpHashValue)(B)*CP_HASH_COEF)
|
81
127
|
|
128
|
+
extern char *cpVersionString;
|
82
129
|
void cpInitChipmunk(void);
|
83
130
|
|
131
|
+
// Calculate the moment of inertia for a circle, r1 and r2 are the inner and outer diameters.
|
132
|
+
// (A solid circle has an inner diameter of 0)
|
84
133
|
cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset);
|
134
|
+
|
135
|
+
// Calculate the moment of inertia for a line segment. (beveling radius not supported)
|
136
|
+
cpFloat cpMomentForSegment(cpFloat m, cpVect a, cpVect b);
|
137
|
+
|
138
|
+
// Calculate the moment of inertia for a solid polygon shape.
|
85
139
|
cpFloat cpMomentForPoly(cpFloat m, int numVerts, cpVect *verts, cpVect offset);
|
86
140
|
|
141
|
+
// Calculate the moment of inertia for a solid box.
|
142
|
+
cpFloat cpMomentForBox(cpFloat m, cpFloat width, cpFloat height);
|
143
|
+
|
87
144
|
#ifdef __cplusplus
|
88
145
|
}
|
89
146
|
#endif
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// Create non static inlined copies of Chipmunk functions, useful for working with dynamic FFIs
|
2
|
+
// This file should only be included in chipmunk.c
|
3
|
+
|
4
|
+
#define MAKE_REF(name) __typeof__(name) *_##name = name
|
5
|
+
|
6
|
+
MAKE_REF(cpv); // makes a variable named _cpv that contains the function pointer for cpv()
|
7
|
+
MAKE_REF(cpvadd);
|
8
|
+
MAKE_REF(cpvneg);
|
9
|
+
MAKE_REF(cpvsub);
|
10
|
+
MAKE_REF(cpvmult);
|
11
|
+
MAKE_REF(cpvdot);
|
12
|
+
MAKE_REF(cpvcross);
|
13
|
+
MAKE_REF(cpvperp);
|
14
|
+
MAKE_REF(cpvrperp);
|
15
|
+
MAKE_REF(cpvproject);
|
16
|
+
MAKE_REF(cpvrotate);
|
17
|
+
MAKE_REF(cpvunrotate);
|
18
|
+
MAKE_REF(cpvlengthsq);
|
19
|
+
MAKE_REF(cpvlerp);
|
20
|
+
MAKE_REF(cpvnormalize);
|
21
|
+
MAKE_REF(cpvnormalize_safe);
|
22
|
+
MAKE_REF(cpvclamp);
|
23
|
+
MAKE_REF(cpvlerpconst);
|
24
|
+
MAKE_REF(cpvdist);
|
25
|
+
MAKE_REF(cpvnear);
|
26
|
+
MAKE_REF(cpvdistsq);
|
27
|
+
|
28
|
+
MAKE_REF(cpBBNew);
|
29
|
+
MAKE_REF(cpBBintersects);
|
30
|
+
MAKE_REF(cpBBcontainsBB);
|
31
|
+
MAKE_REF(cpBBcontainsVect);
|
32
|
+
MAKE_REF(cpBBmerge);
|
33
|
+
MAKE_REF(cpBBexpand);
|
34
|
+
|
35
|
+
MAKE_REF(cpBodyWorld2Local);
|
36
|
+
MAKE_REF(cpBodyLocal2World);
|
37
|
+
MAKE_REF(cpBodyApplyImpulse);
|
38
|
+
|
39
|
+
MAKE_REF(cpArbiterIsFirstContact);
|
40
|
+
MAKE_REF(cpArbiterGetShapes);
|
41
|
+
MAKE_REF(cpArbiterGetNormal);
|
42
|
+
MAKE_REF(cpArbiterGetPoint);
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#ifdef __APPLE__
|
2
|
+
#import "TargetConditionals.h"
|
3
|
+
#endif
|
4
|
+
|
5
|
+
// Use single precision floats on the iPhone.
|
6
|
+
#if TARGET_OS_IPHONE==1
|
7
|
+
#define CP_USE_DOUBLES 0
|
8
|
+
#else
|
9
|
+
// use doubles by default for higher precision
|
10
|
+
#define CP_USE_DOUBLES 1
|
11
|
+
#endif
|
12
|
+
|
13
|
+
#if CP_USE_DOUBLES
|
14
|
+
typedef double cpFloat;
|
15
|
+
#define cpfsqrt sqrt
|
16
|
+
#define cpfsin sin
|
17
|
+
#define cpfcos cos
|
18
|
+
#define cpfacos acos
|
19
|
+
#define cpfatan2 atan2
|
20
|
+
#define cpfmod fmod
|
21
|
+
#define cpfexp exp
|
22
|
+
#define cpfpow pow
|
23
|
+
#define cpffloor floor
|
24
|
+
#define cpfceil ceil
|
25
|
+
#else
|
26
|
+
typedef float cpFloat;
|
27
|
+
#define cpfsqrt sqrtf
|
28
|
+
#define cpfsin sinf
|
29
|
+
#define cpfcos cosf
|
30
|
+
#define cpfacos acosf
|
31
|
+
#define cpfatan2 atan2f
|
32
|
+
#define cpfmod fmodf
|
33
|
+
#define cpfexp expf
|
34
|
+
#define cpfpow powf
|
35
|
+
#define cpffloor floorf
|
36
|
+
#define cpfceil ceilf
|
37
|
+
#endif
|
38
|
+
|
39
|
+
#if TARGET_OS_IPHONE
|
40
|
+
// CGPoints are structurally the same, and allow
|
41
|
+
// easy interoperability with other iPhone libraries
|
42
|
+
#import <CoreGraphics/CGGeometry.h>
|
43
|
+
typedef CGPoint cpVect;
|
44
|
+
#else
|
45
|
+
typedef struct cpVect{cpFloat x,y;} cpVect;
|
46
|
+
#endif
|
47
|
+
|
48
|
+
typedef unsigned int cpHashValue;
|
49
|
+
|
50
|
+
#ifdef CP_DATA_POINTER_TYPE
|
51
|
+
typedef CP_DATA_POINTER_TYPE cpDataPointer;
|
52
|
+
#else
|
53
|
+
typedef void * cpDataPointer;
|
54
|
+
#endif
|
55
|
+
|
56
|
+
#ifdef CP_COLLISION_TYPE_TYPE
|
57
|
+
typedef CP_COLLISION_TYPE_TYPE cpCollisionType;
|
58
|
+
#else
|
59
|
+
typedef unsigned int cpCollisionType;
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#ifdef CP_GROUP_TYPE
|
63
|
+
typedef CP_GROUP_TYPE cpGroup;
|
64
|
+
#else
|
65
|
+
typedef unsigned int cpGroup;
|
66
|
+
#endif
|
67
|
+
|
68
|
+
#ifdef CP_LAYERS_TYPE
|
69
|
+
typedef CP_GROUP_TYPE cpLayers;
|
70
|
+
#else
|
71
|
+
typedef unsigned int cpLayers;
|
72
|
+
#endif
|
73
|
+
|
74
|
+
#ifndef CP_NO_GROUP
|
75
|
+
#define CP_NO_GROUP ((cpGroup)0)
|
76
|
+
#endif
|
77
|
+
|
78
|
+
#ifndef CP_ALL_LAYERS
|
79
|
+
#define CP_ALL_LAYERS (~(cpLayers)0)
|
80
|
+
#endif
|
@@ -0,0 +1,54 @@
|
|
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
|
+
|
23
|
+
|
24
|
+
/* This header defines a number of "unsafe" operations on Chipmunk objects.
|
25
|
+
* In this case "unsafe" is referring to operations which may reduce the
|
26
|
+
* physical accuracy or numerical stability of the simulation, but will not
|
27
|
+
* cause crashes.
|
28
|
+
*
|
29
|
+
* The prime example is mutating collision shapes. Chipmunk does not support
|
30
|
+
* this directly. Mutating shapes using this API will caused objects in contact
|
31
|
+
* to be pushed apart using Chipmunk's overlap solver, but not using real
|
32
|
+
* persistent velocities. Probably not what you meant, but perhaps close enough.
|
33
|
+
*/
|
34
|
+
|
35
|
+
#ifndef CHIPMUNK_UNSAFE_HEADER
|
36
|
+
#define CHIPMUNK_UNSAFE_HEADER
|
37
|
+
|
38
|
+
#ifdef __cplusplus
|
39
|
+
extern "C" {
|
40
|
+
#endif
|
41
|
+
|
42
|
+
void cpCircleShapeSetRadius(cpShape *shape, cpFloat radius);
|
43
|
+
void cpCircleShapeSetOffset(cpShape *shape, cpVect offset);
|
44
|
+
|
45
|
+
void cpSegmentShapeSetEndpoints(cpShape *shape, cpVect a, cpVect b);
|
46
|
+
void cpSegmentShapeSetRadius(cpShape *shape, cpFloat radius);
|
47
|
+
|
48
|
+
void cpPolyShapeSetVerts(cpShape *shape, int numVerts, cpVect *verts, cpVect offset);
|
49
|
+
|
50
|
+
#ifdef __cplusplus
|
51
|
+
}
|
52
|
+
#endif
|
53
|
+
|
54
|
+
#endif
|
@@ -0,0 +1,92 @@
|
|
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
|
+
// TODO: Comment me!
|
23
|
+
|
24
|
+
extern cpFloat cp_constraint_bias_coef;
|
25
|
+
|
26
|
+
struct cpConstraintClass;
|
27
|
+
struct cpConstraint;
|
28
|
+
|
29
|
+
typedef void (*cpConstraintPreStepFunction)(struct cpConstraint *constraint, cpFloat dt, cpFloat dt_inv);
|
30
|
+
typedef void (*cpConstraintApplyImpulseFunction)(struct cpConstraint *constraint);
|
31
|
+
typedef cpFloat (*cpConstraintGetImpulseFunction)(struct cpConstraint *constraint);
|
32
|
+
|
33
|
+
typedef struct cpConstraintClass {
|
34
|
+
cpConstraintPreStepFunction preStep;
|
35
|
+
cpConstraintApplyImpulseFunction applyImpulse;
|
36
|
+
cpConstraintGetImpulseFunction getImpulse;
|
37
|
+
} cpConstraintClass;
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
typedef struct cpConstraint {
|
42
|
+
const cpConstraintClass *klass;
|
43
|
+
|
44
|
+
cpBody *a, *b;
|
45
|
+
cpFloat maxForce;
|
46
|
+
cpFloat biasCoef;
|
47
|
+
cpFloat maxBias;
|
48
|
+
|
49
|
+
cpDataPointer data;
|
50
|
+
} cpConstraint;
|
51
|
+
|
52
|
+
#ifdef CP_USE_DEPRECATED_API_4
|
53
|
+
typedef cpConstraint cpJoint;
|
54
|
+
#endif
|
55
|
+
|
56
|
+
void cpConstraintDestroy(cpConstraint *constraint);
|
57
|
+
void cpConstraintFree(cpConstraint *constraint);
|
58
|
+
|
59
|
+
|
60
|
+
#define cpConstraintCheckCast(constraint, struct) \
|
61
|
+
cpAssert(constraint->klass == struct##GetClass(), "Constraint is not a "#struct);
|
62
|
+
|
63
|
+
|
64
|
+
#define CP_DefineConstraintGetter(struct, type, member, name) \
|
65
|
+
static inline type \
|
66
|
+
struct##Get##name(cpConstraint *constraint){ \
|
67
|
+
cpConstraintCheckCast(constraint, struct); \
|
68
|
+
return ((struct *)constraint)->member; \
|
69
|
+
} \
|
70
|
+
|
71
|
+
#define CP_DefineConstraintSetter(struct, type, member, name) \
|
72
|
+
static inline void \
|
73
|
+
struct##Set##name(cpConstraint *constraint, type value){ \
|
74
|
+
cpConstraintCheckCast(constraint, struct); \
|
75
|
+
((struct *)constraint)->member = value; \
|
76
|
+
} \
|
77
|
+
|
78
|
+
#define CP_DefineConstraintProperty(struct, type, member, name) \
|
79
|
+
CP_DefineConstraintGetter(struct, type, member, name) \
|
80
|
+
CP_DefineConstraintSetter(struct, type, member, name)
|
81
|
+
|
82
|
+
// Built in Joint types
|
83
|
+
#include "cpPinJoint.h"
|
84
|
+
#include "cpSlideJoint.h"
|
85
|
+
#include "cpPivotJoint.h"
|
86
|
+
#include "cpGrooveJoint.h"
|
87
|
+
#include "cpDampedSpring.h"
|
88
|
+
#include "cpDampedRotarySpring.h"
|
89
|
+
#include "cpRotaryLimitJoint.h"
|
90
|
+
#include "cpRatchetJoint.h"
|
91
|
+
#include "cpGearJoint.h"
|
92
|
+
#include "cpSimpleMotor.h"
|