blob: 12882090dc12a09fd13235153b539efc70207114 (
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
|
struct Rigidbody {
Vector2 force = { 0, 0 };
Vector2 velocity = { 0, 0 };
Vector2 position = { 0, 0 };
float32 mass = 1.f;
void update(float32 deltaTimeSeconds) {
applyGravity(deltaTimeSeconds);
Vector2 acceleration = force / mass;
velocity += (acceleration * deltaTimeSeconds);
position += (velocity * deltaTimeSeconds);
force = Vector2 { 0.f, 0.f };
}
void applyGravity(float32 deltaTimeSeconds) {
velocity += (Vector2 { 0.f, -9.8.f } * deltaTimeSeconds);
}
void applyForce(Vector2 f) {
force += f;
}
};
|