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
;
17 // ////////////////////////////////////////////////////////////////////////// //
20 static shared uint lastidx
;
30 VFloat angularVelocity
;
43 import core
.atomic
: atomicOp
;
44 midx
= atomicOp
!"+="(lastidx
, 1);
45 position
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
46 rotation
= VFloatNum
!(0.0);
47 velocity
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
48 angularVelocity
= VFloatNum
!(0.0);
49 force
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
50 torque
= VFloatNum
!(0.0);
51 friction
= VFloatNum
!(0.2);
53 width
.set(VFloatNum
!(1.0), VFloatNum
!(1.0));
55 invMass
= VFloatNum
!(0.0);
57 invI
= VFloatNum
!(0.0);
60 @property uint id () const pure nothrow @safe @nogc { pragma(inline
, true); return midx
; }
62 void set() (in auto ref Vec2 w
, VFloat m
) {
63 position
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
64 rotation
= VFloatNum
!(0.0);
65 velocity
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
66 angularVelocity
= VFloatNum
!(0.0);
67 force
.set(VFloatNum
!(0.0), VFloatNum
!(0.0));
68 torque
= VFloatNum
!(0.0);
69 friction
= VFloatNum
!(0.2);
72 if (mass
< VFloat
.max
) {
73 invMass
= VFloatNum
!(1.0)/mass
;
74 I
= mass
*(width
.x
*width
.x
+width
.y
*width
.y
)/VFloatNum
!(12.0);
75 invI
= VFloatNum
!(1.0)/I
;
77 invMass
= VFloatNum
!(0.0);
79 invI
= VFloatNum
!(0.0);
83 void addForce() (in auto ref Vec2 f
) { pragma(inline
, true); force
+= f
; }
85 int opCmp() (Body b
) pure const nothrow @trusted @nogc {
87 return (b
!is null ? b
.midx
== midx
: 1);