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
@@ -0,0 +1,46 @@
|
|
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 cpFloat (*cpDampedRotarySpringTorqueFunc)(struct cpConstraint *spring, cpFloat relativeAngle);
|
23
|
+
|
24
|
+
const cpConstraintClass *cpDampedRotarySpringGetClass();
|
25
|
+
|
26
|
+
typedef struct cpDampedRotarySpring {
|
27
|
+
cpConstraint constraint;
|
28
|
+
cpFloat restAngle;
|
29
|
+
cpFloat stiffness;
|
30
|
+
cpFloat damping;
|
31
|
+
cpDampedRotarySpringTorqueFunc springTorqueFunc;
|
32
|
+
|
33
|
+
cpFloat dt;
|
34
|
+
cpFloat target_wrn;
|
35
|
+
|
36
|
+
cpFloat iSum;
|
37
|
+
} cpDampedRotarySpring;
|
38
|
+
|
39
|
+
cpDampedRotarySpring *cpDampedRotarySpringAlloc(void);
|
40
|
+
cpDampedRotarySpring *cpDampedRotarySpringInit(cpDampedRotarySpring *joint, cpBody *a, cpBody *b, cpFloat restAngle, cpFloat stiffness, cpFloat damping);
|
41
|
+
cpConstraint *cpDampedRotarySpringNew(cpBody *a, cpBody *b, cpFloat restAngle, cpFloat stiffness, cpFloat damping);
|
42
|
+
|
43
|
+
CP_DefineConstraintProperty(cpDampedRotarySpring, cpFloat, restAngle, RestAngle);
|
44
|
+
CP_DefineConstraintProperty(cpDampedRotarySpring, cpFloat, stiffness, Stiffness);
|
45
|
+
CP_DefineConstraintProperty(cpDampedRotarySpring, cpFloat, damping, Damping);
|
46
|
+
CP_DefineConstraintProperty(cpDampedRotarySpring, cpDampedRotarySpringTorqueFunc, springTorqueFunc, SpringTorqueFunc);
|
@@ -0,0 +1,53 @@
|
|
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
|
+
struct cpDampedSpring;
|
23
|
+
|
24
|
+
typedef cpFloat (*cpDampedSpringForceFunc)(struct cpConstraint *spring, cpFloat dist);
|
25
|
+
|
26
|
+
const cpConstraintClass *cpDampedSpringGetClass();
|
27
|
+
|
28
|
+
typedef struct cpDampedSpring {
|
29
|
+
cpConstraint constraint;
|
30
|
+
cpVect anchr1, anchr2;
|
31
|
+
cpFloat restLength;
|
32
|
+
cpFloat stiffness;
|
33
|
+
cpFloat damping;
|
34
|
+
cpDampedSpringForceFunc springForceFunc;
|
35
|
+
|
36
|
+
cpFloat dt;
|
37
|
+
cpFloat target_vrn;
|
38
|
+
|
39
|
+
cpVect r1, r2;
|
40
|
+
cpFloat nMass;
|
41
|
+
cpVect n;
|
42
|
+
} cpDampedSpring;
|
43
|
+
|
44
|
+
cpDampedSpring *cpDampedSpringAlloc(void);
|
45
|
+
cpDampedSpring *cpDampedSpringInit(cpDampedSpring *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping);
|
46
|
+
cpConstraint *cpDampedSpringNew(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping);
|
47
|
+
|
48
|
+
CP_DefineConstraintProperty(cpDampedSpring, cpVect, anchr1, Anchr1);
|
49
|
+
CP_DefineConstraintProperty(cpDampedSpring, cpVect, anchr2, Anchr2);
|
50
|
+
CP_DefineConstraintProperty(cpDampedSpring, cpFloat, restLength, RestLength);
|
51
|
+
CP_DefineConstraintProperty(cpDampedSpring, cpFloat, stiffness, Stiffness);
|
52
|
+
CP_DefineConstraintProperty(cpDampedSpring, cpFloat, damping, Damping);
|
53
|
+
CP_DefineConstraintProperty(cpDampedSpring, cpDampedSpringForceFunc, springForceFunc, SpringForceFunc);
|
@@ -0,0 +1,41 @@
|
|
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
|
+
const cpConstraintClass *cpGearJointGetClass();
|
23
|
+
|
24
|
+
typedef struct cpGearJoint {
|
25
|
+
cpConstraint constraint;
|
26
|
+
cpFloat phase, ratio;
|
27
|
+
cpFloat ratio_inv;
|
28
|
+
|
29
|
+
cpFloat iSum;
|
30
|
+
|
31
|
+
cpFloat bias;
|
32
|
+
cpFloat jAcc, jMax;
|
33
|
+
} cpGearJoint;
|
34
|
+
|
35
|
+
cpGearJoint *cpGearJointAlloc(void);
|
36
|
+
cpGearJoint *cpGearJointInit(cpGearJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio);
|
37
|
+
cpConstraint *cpGearJointNew(cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio);
|
38
|
+
|
39
|
+
CP_DefineConstraintProperty(cpGearJoint, cpFloat, phase, Phase);
|
40
|
+
CP_DefineConstraintGetter(cpGearJoint, cpFloat, ratio, Ratio);
|
41
|
+
void cpGearJointSetRatio(cpConstraint *constraint, cpFloat value);
|
@@ -0,0 +1,44 @@
|
|
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
|
+
const cpConstraintClass *cpGrooveJointGetClass();
|
23
|
+
|
24
|
+
typedef struct cpGrooveJoint {
|
25
|
+
cpConstraint constraint;
|
26
|
+
cpVect grv_n, grv_a, grv_b;
|
27
|
+
cpVect anchr2;
|
28
|
+
|
29
|
+
cpVect grv_tn;
|
30
|
+
cpFloat clamp;
|
31
|
+
cpVect r1, r2;
|
32
|
+
cpVect k1, k2;
|
33
|
+
|
34
|
+
cpVect jAcc;
|
35
|
+
cpFloat jMaxLen;
|
36
|
+
cpVect bias;
|
37
|
+
} cpGrooveJoint;
|
38
|
+
|
39
|
+
cpGrooveJoint *cpGrooveJointAlloc(void);
|
40
|
+
cpGrooveJoint *cpGrooveJointInit(cpGrooveJoint *joint, cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchr2);
|
41
|
+
cpConstraint *cpGrooveJointNew(cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchr2);
|
42
|
+
|
43
|
+
// TODO setters for the groove.
|
44
|
+
CP_DefineConstraintProperty(cpGrooveJoint, cpVect, anchr2, Anchr2);
|
@@ -0,0 +1,43 @@
|
|
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
|
+
const cpConstraintClass *cpPinJointGetClass();
|
23
|
+
|
24
|
+
typedef struct cpPinJoint {
|
25
|
+
cpConstraint constraint;
|
26
|
+
cpVect anchr1, anchr2;
|
27
|
+
cpFloat dist;
|
28
|
+
|
29
|
+
cpVect r1, r2;
|
30
|
+
cpVect n;
|
31
|
+
cpFloat nMass;
|
32
|
+
|
33
|
+
cpFloat jnAcc, jnMax;
|
34
|
+
cpFloat bias;
|
35
|
+
} cpPinJoint;
|
36
|
+
|
37
|
+
cpPinJoint *cpPinJointAlloc(void);
|
38
|
+
cpPinJoint *cpPinJointInit(cpPinJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2);
|
39
|
+
cpConstraint *cpPinJointNew(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2);
|
40
|
+
|
41
|
+
CP_DefineConstraintProperty(cpPinJoint, cpVect, anchr1, Anchr1);
|
42
|
+
CP_DefineConstraintProperty(cpPinJoint, cpVect, anchr2, Anchr2);
|
43
|
+
CP_DefineConstraintProperty(cpPinJoint, cpFloat, dist, Dist);
|
@@ -0,0 +1,42 @@
|
|
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
|
+
const cpConstraintClass *cpPivotJointGetClass();
|
23
|
+
|
24
|
+
typedef struct cpPivotJoint {
|
25
|
+
cpConstraint constraint;
|
26
|
+
cpVect anchr1, anchr2;
|
27
|
+
|
28
|
+
cpVect r1, r2;
|
29
|
+
cpVect k1, k2;
|
30
|
+
|
31
|
+
cpVect jAcc;
|
32
|
+
cpFloat jMaxLen;
|
33
|
+
cpVect bias;
|
34
|
+
} cpPivotJoint;
|
35
|
+
|
36
|
+
cpPivotJoint *cpPivotJointAlloc(void);
|
37
|
+
cpPivotJoint *cpPivotJointInit(cpPivotJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2);
|
38
|
+
cpConstraint *cpPivotJointNew(cpBody *a, cpBody *b, cpVect pivot);
|
39
|
+
cpConstraint *cpPivotJointNew2(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2);
|
40
|
+
|
41
|
+
CP_DefineConstraintProperty(cpPivotJoint, cpVect, anchr1, Anchr1);
|
42
|
+
CP_DefineConstraintProperty(cpPivotJoint, cpVect, anchr2, Anchr2);
|
@@ -0,0 +1,40 @@
|
|
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
|
+
const cpConstraintClass *cpRatchetJointGetClass();
|
23
|
+
|
24
|
+
typedef struct cpRatchetJoint {
|
25
|
+
cpConstraint constraint;
|
26
|
+
cpFloat angle, phase, ratchet;
|
27
|
+
|
28
|
+
cpFloat iSum;
|
29
|
+
|
30
|
+
cpFloat bias;
|
31
|
+
cpFloat jAcc, jMax;
|
32
|
+
} cpRatchetJoint;
|
33
|
+
|
34
|
+
cpRatchetJoint *cpRatchetJointAlloc(void);
|
35
|
+
cpRatchetJoint *cpRatchetJointInit(cpRatchetJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet);
|
36
|
+
cpConstraint *cpRatchetJointNew(cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet);
|
37
|
+
|
38
|
+
CP_DefineConstraintProperty(cpRatchetJoint, cpFloat, angle, Angle);
|
39
|
+
CP_DefineConstraintProperty(cpRatchetJoint, cpFloat, phase, Phase);
|
40
|
+
CP_DefineConstraintProperty(cpRatchetJoint, cpFloat, ratchet, Ratchet);
|
@@ -0,0 +1,39 @@
|
|
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
|
+
const cpConstraintClass *cpRotaryLimitJointGetClass();
|
23
|
+
|
24
|
+
typedef struct cpRotaryLimitJoint {
|
25
|
+
cpConstraint constraint;
|
26
|
+
cpFloat min, max;
|
27
|
+
|
28
|
+
cpFloat iSum;
|
29
|
+
|
30
|
+
cpFloat bias;
|
31
|
+
cpFloat jAcc, jMax;
|
32
|
+
} cpRotaryLimitJoint;
|
33
|
+
|
34
|
+
cpRotaryLimitJoint *cpRotaryLimitJointAlloc(void);
|
35
|
+
cpRotaryLimitJoint *cpRotaryLimitJointInit(cpRotaryLimitJoint *joint, cpBody *a, cpBody *b, cpFloat min, cpFloat max);
|
36
|
+
cpConstraint *cpRotaryLimitJointNew(cpBody *a, cpBody *b, cpFloat min, cpFloat max);
|
37
|
+
|
38
|
+
CP_DefineConstraintProperty(cpRotaryLimitJoint, cpFloat, min, Min);
|
39
|
+
CP_DefineConstraintProperty(cpRotaryLimitJoint, cpFloat, max, Max);
|
@@ -0,0 +1,37 @@
|
|
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
|
+
const cpConstraintClass *cpSimpleMotorGetClass();
|
23
|
+
|
24
|
+
typedef struct cpSimpleMotor {
|
25
|
+
cpConstraint constraint;
|
26
|
+
cpFloat rate;
|
27
|
+
|
28
|
+
cpFloat iSum;
|
29
|
+
|
30
|
+
cpFloat jAcc, jMax;
|
31
|
+
} cpSimpleMotor;
|
32
|
+
|
33
|
+
cpSimpleMotor *cpSimpleMotorAlloc(void);
|
34
|
+
cpSimpleMotor *cpSimpleMotorInit(cpSimpleMotor *joint, cpBody *a, cpBody *b, cpFloat rate);
|
35
|
+
cpConstraint *cpSimpleMotorNew(cpBody *a, cpBody *b, cpFloat rate);
|
36
|
+
|
37
|
+
CP_DefineConstraintProperty(cpSimpleMotor, cpFloat, rate, Rate);
|
@@ -0,0 +1,44 @@
|
|
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
|
+
const cpConstraintClass *cpSlideJointGetClass();
|
23
|
+
|
24
|
+
typedef struct cpSlideJoint {
|
25
|
+
cpConstraint constraint;
|
26
|
+
cpVect anchr1, anchr2;
|
27
|
+
cpFloat min, max;
|
28
|
+
|
29
|
+
cpVect r1, r2;
|
30
|
+
cpVect n;
|
31
|
+
cpFloat nMass;
|
32
|
+
|
33
|
+
cpFloat jnAcc, jnMax;
|
34
|
+
cpFloat bias;
|
35
|
+
} cpSlideJoint;
|
36
|
+
|
37
|
+
cpSlideJoint *cpSlideJointAlloc(void);
|
38
|
+
cpSlideJoint *cpSlideJointInit(cpSlideJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max);
|
39
|
+
cpConstraint *cpSlideJointNew(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max);
|
40
|
+
|
41
|
+
CP_DefineConstraintProperty(cpSlideJoint, cpVect, anchr1, Anchr1);
|
42
|
+
CP_DefineConstraintProperty(cpSlideJoint, cpVect, anchr2, Anchr2);
|
43
|
+
CP_DefineConstraintProperty(cpSlideJoint, cpFloat, min, Min);
|
44
|
+
CP_DefineConstraintProperty(cpSlideJoint, cpFloat, max, Max);
|
@@ -0,0 +1,116 @@
|
|
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
|
+
#define CP_DefineClassGetter(t) const cpConstraintClass * t##GetClass(){return (cpConstraintClass *)&klass;}
|
23
|
+
|
24
|
+
void cpConstraintInit(cpConstraint *constraint, const cpConstraintClass *klass, cpBody *a, cpBody *b);
|
25
|
+
|
26
|
+
#define J_MAX(constraint, dt) (((cpConstraint *)constraint)->maxForce*(dt))
|
27
|
+
|
28
|
+
static inline cpVect
|
29
|
+
relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2){
|
30
|
+
cpVect v1_sum = cpvadd(a->v, cpvmult(cpvperp(r1), a->w));
|
31
|
+
cpVect v2_sum = cpvadd(b->v, cpvmult(cpvperp(r2), b->w));
|
32
|
+
|
33
|
+
return cpvsub(v2_sum, v1_sum);
|
34
|
+
}
|
35
|
+
|
36
|
+
static inline cpFloat
|
37
|
+
normal_relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n){
|
38
|
+
return cpvdot(relative_velocity(a, b, r1, r2), n);
|
39
|
+
}
|
40
|
+
|
41
|
+
static inline void
|
42
|
+
apply_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j)
|
43
|
+
{
|
44
|
+
cpBodyApplyImpulse(a, cpvneg(j), r1);
|
45
|
+
cpBodyApplyImpulse(b, j, r2);
|
46
|
+
}
|
47
|
+
|
48
|
+
static inline void
|
49
|
+
apply_bias_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j)
|
50
|
+
{
|
51
|
+
cpBodyApplyBiasImpulse(a, cpvneg(j), r1);
|
52
|
+
cpBodyApplyBiasImpulse(b, j, r2);
|
53
|
+
}
|
54
|
+
|
55
|
+
static inline cpVect
|
56
|
+
clamp_vect(cpVect v, cpFloat len)
|
57
|
+
{
|
58
|
+
return cpvclamp(v, len);
|
59
|
+
// return (cpvdot(v,v) > len*len) ? cpvmult(cpvnormalize(v), len) : v;
|
60
|
+
}
|
61
|
+
|
62
|
+
static inline cpFloat
|
63
|
+
k_scalar(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n)
|
64
|
+
{
|
65
|
+
cpFloat mass_sum = a->m_inv + b->m_inv;
|
66
|
+
cpFloat r1cn = cpvcross(r1, n);
|
67
|
+
cpFloat r2cn = cpvcross(r2, n);
|
68
|
+
|
69
|
+
cpFloat value = mass_sum + a->i_inv*r1cn*r1cn + b->i_inv*r2cn*r2cn;
|
70
|
+
cpAssert(value != 0.0, "Unsolvable collision or constraint.");
|
71
|
+
|
72
|
+
return value;
|
73
|
+
}
|
74
|
+
|
75
|
+
static inline void
|
76
|
+
k_tensor(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect *k1, cpVect *k2)
|
77
|
+
{
|
78
|
+
// calculate mass matrix
|
79
|
+
// If I wasn't lazy and wrote a proper matrix class, this wouldn't be so gross...
|
80
|
+
cpFloat k11, k12, k21, k22;
|
81
|
+
cpFloat m_sum = a->m_inv + b->m_inv;
|
82
|
+
|
83
|
+
// start with I*m_sum
|
84
|
+
k11 = m_sum; k12 = 0.0f;
|
85
|
+
k21 = 0.0f; k22 = m_sum;
|
86
|
+
|
87
|
+
// add the influence from r1
|
88
|
+
cpFloat a_i_inv = a->i_inv;
|
89
|
+
cpFloat r1xsq = r1.x * r1.x * a_i_inv;
|
90
|
+
cpFloat r1ysq = r1.y * r1.y * a_i_inv;
|
91
|
+
cpFloat r1nxy = -r1.x * r1.y * a_i_inv;
|
92
|
+
k11 += r1ysq; k12 += r1nxy;
|
93
|
+
k21 += r1nxy; k22 += r1xsq;
|
94
|
+
|
95
|
+
// add the influnce from r2
|
96
|
+
cpFloat b_i_inv = b->i_inv;
|
97
|
+
cpFloat r2xsq = r2.x * r2.x * b_i_inv;
|
98
|
+
cpFloat r2ysq = r2.y * r2.y * b_i_inv;
|
99
|
+
cpFloat r2nxy = -r2.x * r2.y * b_i_inv;
|
100
|
+
k11 += r2ysq; k12 += r2nxy;
|
101
|
+
k21 += r2nxy; k22 += r2xsq;
|
102
|
+
|
103
|
+
// invert
|
104
|
+
cpFloat determinant = k11*k22 - k12*k21;
|
105
|
+
cpAssert(determinant != 0.0, "Unsolvable constraint.");
|
106
|
+
|
107
|
+
cpFloat det_inv = 1.0f/determinant;
|
108
|
+
*k1 = cpv( k22*det_inv, -k12*det_inv);
|
109
|
+
*k2 = cpv(-k21*det_inv, k11*det_inv);
|
110
|
+
}
|
111
|
+
|
112
|
+
static inline cpVect
|
113
|
+
mult_k(cpVect vr, cpVect k1, cpVect k2)
|
114
|
+
{
|
115
|
+
return cpv(cpvdot(vr, k1), cpvdot(vr, k2));
|
116
|
+
}
|