aboutsummaryrefslogtreecommitdiff
path: root/Client/Source/Phy2DLite/Body.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-30 23:50:01 +0800
committerchai <chaifix@163.com>2021-11-30 23:50:01 +0800
commit84d961f754c905b37420f4d1b3fee8f4e523e58a (patch)
treeaa3669ac285f7186ecd6a26f874da9bba765178b /Client/Source/Phy2DLite/Body.cpp
parent9e0e01b7f4375063f06e494113187d48614628e0 (diff)
+phy2d lite
Diffstat (limited to 'Client/Source/Phy2DLite/Body.cpp')
-rw-r--r--Client/Source/Phy2DLite/Body.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/Client/Source/Phy2DLite/Body.cpp b/Client/Source/Phy2DLite/Body.cpp
new file mode 100644
index 0000000..73bafe2
--- /dev/null
+++ b/Client/Source/Phy2DLite/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;
+ }
+}