aboutsummaryrefslogtreecommitdiff
path: root/Client/Source/Phy2D/Dynamic/Body.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-30 22:25:37 +0800
committerchai <chaifix@163.com>2021-11-30 22:25:37 +0800
commit9e0e01b7f4375063f06e494113187d48614628e0 (patch)
tree21a4901612ad92c121f4c887a33b1bbbe87c6b00 /Client/Source/Phy2D/Dynamic/Body.cpp
+init
Diffstat (limited to 'Client/Source/Phy2D/Dynamic/Body.cpp')
-rw-r--r--Client/Source/Phy2D/Dynamic/Body.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/Client/Source/Phy2D/Dynamic/Body.cpp b/Client/Source/Phy2D/Dynamic/Body.cpp
new file mode 100644
index 0000000..73bafe2
--- /dev/null
+++ b/Client/Source/Phy2D/Dynamic/Body.cpp
@@ -0,0 +1,47 @@
+#include "Body.h"
+
+using namespace Phy2D;
+
+Body::Body()
+{
+ position.Set(0.0f, 0.0f);
+ rotation = 0.0f;
+ velocity.Set(0.0f, 0.0f);
+ angularVelocity = 0.0f;
+ force.Set(0.0f, 0.0f);
+ torque = 0.0f;
+ friction = 0.2f;
+
+ width.Set(1.0f, 1.0f);
+ mass = NUMBER_MAX;
+ invMass = 0.0f;
+ I = NUMBER_MAX;
+ invI = 0.0f;
+}
+
+void Body::Set(const Vec2& w, number m)
+{
+ position.Set(0.0f, 0.0f);
+ rotation = 0.0f;
+ velocity.Set(0.0f, 0.0f);
+ angularVelocity = 0.0f;
+ force.Set(0.0f, 0.0f);
+ torque = 0.0f;
+ friction = 0.2f;
+
+ width = w;
+ mass = m;
+
+ if (mass < NUMBER_MAX)
+ {
+ invMass = (number)1.0f / mass;
+ I = mass * (width.x * width.x + width.y * width.y) / 12.0f;
+ invI = (number)1.0f / I;
+ }
+ else
+ {
+ invMass = 0.0f;
+ I = NUMBER_MAX;
+ invI = 0.0f;
+ }
+}