From 1021d32f7ccb9f3f10253934fd4e5202b7382b2d Mon Sep 17 00:00:00 2001 From: neoraider Date: Fri, 20 Oct 2006 12:57:05 +0000 Subject: Physik-Engine angefangen. Lightmaps implementiert. --- physics.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 physics.c (limited to 'physics.c') diff --git a/physics.c b/physics.c new file mode 100644 index 0000000..cea066d --- /dev/null +++ b/physics.c @@ -0,0 +1,26 @@ +#include +#include +#include + +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))); +} -- cgit v1.2.3