From a6c758aa66e4d692250896ce4fb3abb2440dde31 Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 27 Feb 2013 03:45:25 +0000 Subject: [PATCH] [Fix?] Hyperspace bug. Messed up velocity issues. Ok. What we are doing here is messy. What we are doing is modulating the velocity. There is also a dt in there to try to make it not frame dependant.. The way things are done right now, we are cascading the limit_speed with the physics model, We can simplify it to a euler integration (It's actuallyu runge-kutta).. What we are doung is: v1 = v0 + adt Basically this means that the current velocity is the last vel plus the acceleration, times the time passed from the last instance. This is then chained to the limit speed which does: v = (v1 - vmax)(1-3dt) So we can right the composite form as: v = (v0 + adt - vmax) 1-3dt) = v0 + adt - vmax - 3dtv0 - 3adt2 + 3dtvmax -- Yes. This is hacky. I will try to play with some equasions later. --- src/physics.c | 8 +++++--- src/physics.h | 2 +- src/pilot.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/physics.c b/src/physics.c index fd53772..78fe403 100644 --- a/src/physics.c +++ b/src/physics.c @@ -14,9 +14,11 @@ double angle_diff(const double ref, double a) { return (d <= M_PI) ? d : d - 2*M_PI; } -void limit_speed(Vec2* vel, const double speed) { - if(VMOD(*vel) > speed) // Should not go faster. - vect_pset(vel, speed, VANGLE(*vel)); +void limit_speed(Vec2* vel, const double speed, const double dt) { + double vmod; + vmod = VMOD(*vel); + if(vmod > speed) // Should not go faster. + vect_pset(vel, (vmod-speed)*(1.-dt*3.) + speed, VANGLE(*vel)); } // ================ diff --git a/src/physics.h b/src/physics.h index 8e5058b..b4f6ebf 100644 --- a/src/physics.h +++ b/src/physics.h @@ -22,7 +22,7 @@ typedef struct Vec2_ { double mod, angle; // Polar values. } Vec2; -void limit_speed(Vec2* vel, const double speed); +void limit_speed(Vec2* vel, const double speed, const double dt); // Vector manupulation. void vect_cset(Vec2* v, const double x, const double y); diff --git a/src/pilot.c b/src/pilot.c index 0591028..5f7ce0d 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -279,7 +279,7 @@ static void pilot_update(Pilot* pilot, const double dt) { if(!pilot_isFlag(pilot, PILOT_HYPERSPACE)) // Should not go faster. - limit_speed(&pilot->solid->vel, pilot->ship->speed); + limit_speed(&pilot->solid->vel, pilot->ship->speed, dt); } // Pilot is getting ready or is in, hyperspace.