This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
neofx-libneofx/physics.c
2007-10-31 23:15:01 +00:00

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)));
}