[Add] limit_speed in physics

This commit is contained in:
Allanis 2013-02-27 03:26:58 +00:00
parent 0de847b5a4
commit f6de9e8186
3 changed files with 9 additions and 4 deletions

View File

@ -14,6 +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));
}
// ================
// VEC2
// ================

View File

@ -22,6 +22,8 @@ typedef struct Vec2_ {
double mod, angle; // Polar values.
} Vec2;
void limit_speed(Vec2* vel, const double speed);
// Vector manupulation.
void vect_cset(Vec2* v, const double x, const double y);
// Doesn't set mod nor angle.

View File

@ -277,11 +277,9 @@ static void pilot_update(Pilot* pilot, const double dt) {
// Update the solid.
(*pilot->solid->update)(pilot->solid, dt);
if(!pilot_isFlag(pilot, PILOT_HYPERSPACE) && VMOD(pilot->solid->vel) >
pilot->ship->speed)
if(!pilot_isFlag(pilot, PILOT_HYPERSPACE))
// Should not go faster.
vect_pset(&pilot->solid->vel, pilot->ship->speed,
VANGLE(pilot->solid->vel));
limit_speed(&pilot->solid->vel, pilot->ship->speed);
}
// Pilot is getting ready or is in, hyperspace.