From 84d961f754c905b37420f4d1b3fee8f4e523e58a Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 30 Nov 2021 23:50:01 +0800 Subject: +phy2d lite --- Client/Source/Phy2DLite/Body.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Client/Source/Phy2DLite/Body.cpp (limited to 'Client/Source/Phy2DLite/Body.cpp') 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; + } +} -- cgit v1.1-26-g67d0