26 lines
688 B
C
26 lines
688 B
C
#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)));
|
|
}
|