diff --git a/game_definitions.cpp b/game_definitions.cpp index d30e1e5..88043ec 100644 --- a/game_definitions.cpp +++ b/game_definitions.cpp @@ -1,5 +1,7 @@ #include "game_definitions.h" +#include + namespace GameDefinitions { MenuItemEnum & operator++ (MenuItemEnum & m) { @@ -26,5 +28,17 @@ MenuItemEnum & operator-- (MenuItemEnum & m) { } } +double LorentzFactor(double v) { + double lf; + double r = v / kSpeedOfLight; + if (r > 1.0) { + lf = kEpsilon; + } + else { + lf = sqrt(1.0 - r*r); + } + return lf; +} + } // namespace GameDefinitions diff --git a/game_definitions.h b/game_definitions.h index 7e3a0ac..c62bfcd 100644 --- a/game_definitions.h +++ b/game_definitions.h @@ -3,7 +3,9 @@ namespace GameDefinitions { +const double kEpsilon = 0.001; const double kGravityConstant = 0.7; +const double kSpeedOfLight = 180.0; enum OrbitDirEnum { od_Clockwise, @@ -27,6 +29,8 @@ enum MenuItemEnum { MenuItemEnum & operator++ (MenuItemEnum & m); MenuItemEnum & operator-- (MenuItemEnum & m); +double LorentzFactor(double v); + } // namespace GameDefinitions #endif // GAME_DEFINITIONS_H_ diff --git a/space_ship.h b/space_ship.h index 8a94535..fbd7466 100644 --- a/space_ship.h +++ b/space_ship.h @@ -36,7 +36,7 @@ class SpaceShip { double density_; double thrust_force_; double moment_; - + b2Vec2 position_; b2Vec2 velocity_; b2Vec2 gravity_; @@ -46,7 +46,7 @@ class SpaceShip { float color_[3]; public: - SpaceShip() + SpaceShip() : engine_(0) , radar_(0) , kMaxHullStrength(10.0) @@ -152,10 +152,6 @@ class SpaceShip { // Begin -- Handlers for Engine system. void hndThrustOut(double value) { thrust_force_ = value; - - BD_Scalar thrust; - thrust.value = thrust_force_; - DATABUS.Publish(db_PlayerThrust, &thrust); } void hndMomentOut(double value) { moment_ = value; @@ -172,7 +168,9 @@ class SpaceShip { physics_body_->ApplyTorque(moment_, true); // Get velocity for devices. velocity_ = physics_body_->GetLinearVelocity(); - + double speed = velocity_.Length(); + double lf = GameDefinitions::LorentzFactor(speed); + physics_body_->GetFixtureList()->SetDensity( density_ / lf ); // Get position. position_ = physics_body_->GetPosition(); angle_ = physics_body_->GetAngle() * 180.0 / M_PI; @@ -192,6 +190,10 @@ class SpaceShip { s.value = angle_; DATABUS.Publish(db_PlayerAngle, &s); + BD_Scalar thrust; + thrust.value = thrust_force_ * lf; + DATABUS.Publish(db_PlayerThrust, &thrust); + engine_->Update(delta_time); radar_->Update(delta_time); }