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
|
#include <neofx/physics.h>
#include <neofx/math.h>
#include <math.h>
static VECTOR gravitation = {0, -9.8, 0};
void SetGravitation(VECTOR v) {
gravitation = v;
}
void ApplyPhysics(OBJECT o, float delta) {
VERTEX old_pos = o.pos;
VECTOR old_move = o.move;
float e;
e = expf(-o.air_resistance*delta);
o.move = VectorAdd(VectorMul(gravitation, 1/o.air_resistance),
VectorMul(VectorSub(old_move, VectorMul(gravitation, 1/o.air_resistance)),
e));
o.pos = VectorAdd(old_pos, VectorAdd(VectorMul(gravitation, delta/o.air_resistance),
VectorMul(VectorSub(old_move, VectorMul(gravitation, 1/o.air_resistance)),
(1-e)/o.air_resistance)));
}
|