aboutsummaryrefslogtreecommitdiff
path: root/Client/Source/Phy2DLite/Body.cpp
blob: 993c3f847141596dcad37bf0625f2ff32a68034f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Body.h"
#include "Constants.h"

using namespace Phy2D;

Body::Body()
{
    position.Set(_0, _0);
    rotation = _0;
    velocity.Set(_0, _0);
    angularVelocity = _0;
    force.Set(_0, _0);
    torque = _0;
    friction = _0_2;

    width.Set(_1, _1);
    mass = NUMBER_MAX;
    invMass = _0;
    I = NUMBER_MAX;
    invI = _0;
}

void Body::Set(const Vec2& w, number m)
{
    position.Set(_0, _0);
    rotation = _0;
    velocity.Set(_0, _0);
    angularVelocity = _0;
    force.Set(_0, _0);
    torque = _0;
    friction = _0_2;

    width = w;
    mass = m;

    if (mass < NUMBER_MAX)
    {
        invMass = (number)_1 / mass;
        I = mass * (width.x * width.x + width.y * width.y) / _12;
        invI = (number)_1 / I;
    }
    else
    {
        invMass = _0;
        I = NUMBER_MAX;
        invI = _0;
    }
}