blob: 1d896fda4f17f2d836acf29bf840915ec4287d60 (
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
|
#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;
}
}
|