forked from JayTwoLab/qbox2dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBody.cpp
56 lines (50 loc) · 1.16 KB
/
Body.cpp
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
49
50
51
52
53
54
55
56
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies.
* Erin Catto makes no representations about the suitability
* of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*/
#include "Body.h"
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 = FLT_MAX;
invMass = 0.0f;
I = FLT_MAX;
invI = 0.0f;
}
void Body::Set(const Vec2& w, float 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 < FLT_MAX)
{
invMass = 1.0f / mass;
I = mass * (width.x * width.x + width.y * width.y) / 12.0f;
invI = 1.0f / I;
}
else
{
invMass = 0.0f;
I = FLT_MAX;
invI = 0.0f;
}
}