2 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
4 * Permission to use, copy, modify, distribute and sell this software
5 * and its documentation for any purpose is hereby granted without fee,
6 * provided that the above copyright notice appear in all copies.
7 * Erin Catto makes no representations about the suitability
8 * of this software for any purpose.
9 * It is provided "as is" without express or implied warranty.
14 import b2dlite
.mathutils
;
23 VFloat angularVelocity
;
36 position
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
37 rotation
= VFloatNum
!(0.0);
38 velocity
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
39 angularVelocity
= VFloatNum
!(0.0);
40 force
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
41 torque
= VFloatNum
!(0.0);
42 friction
= VFloatNum
!(0.2);
44 width
.set(VFloatNum
!(1.0), VFloatNum
!(1.0));
46 invMass
= VFloatNum
!(0.0);
48 invI
= VFloatNum
!(0.0);
51 void set() (in auto ref Vec2 w
, VFloat m
) {
52 position
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
53 rotation
= VFloatNum
!(0.0);
54 velocity
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
55 angularVelocity
= VFloatNum
!(0.0);
56 force
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
57 torque
= VFloatNum
!(0.0);
58 friction
= VFloatNum
!(0.2);
61 if (mass
< VFloat
.max
) {
62 invMass
= VFloatNum
!(1.0)/mass
;
63 I
= mass
*(width
.x
*width
.x
+width
.y
*width
.y
)/VFloatNum
!(12.0);
64 invI
= VFloatNum
!(1.0)/I
;
66 invMass
= VFloatNum
!(0.0);
68 invI
= VFloatNum
!(0.0);
72 void AddForce() (in auto ref Vec2 f
) { pragma(inline
, true); force
+= f
; }
74 int opCmp() (Body b
) pure const nothrow @trusted @nogc {
75 if (b
is null) return 1;
76 if (b
is this) return 0;
77 if (cast(size_t
)cast(void*)this < cast(size_t
)cast(void*)b
) return -1;
78 if (cast(size_t
)cast(void*)this > cast(size_t
)cast(void*)b
) return 1;