diff --git a/data/stk_config.data b/data/stk_config.data index f9420583d..c599e0d03 100644 --- a/data/stk_config.data +++ b/data/stk_config.data @@ -52,7 +52,12 @@ ;; Bullet physics attributes (brake-factor 2.75 ) - (max-steer-angle 6.4 ) + ;; Defines the (maximum) steering angle at a lowest speed (19 degrees at + ;; speed 0) and at high speed (6.4 degrees at speed 12 m/s). Maximum + ;; steering angles for speeds in between will be interpolated. This + ;; allows for tighter turns at lower speeds + (min-speed-angle 0 19) + (max-speed-angle 12 6.4) (engine-power 400 ) (mass 225 ) (suspension-stiffness 8.0 ) diff --git a/src/kart.hpp b/src/kart.hpp index 6f7839e09..046732376 100644 --- a/src/kart.hpp +++ b/src/kart.hpp @@ -168,7 +168,8 @@ public: float getWheelBase () const {return m_kart_properties->getWheelBase();} float getHeightCOG () const {return m_kart_properties->getHeightCOG();} float getFrictionSlip () const {return m_kart_properties->getFrictionSlip();} - float getMaxSteerAngle () const {return m_kart_properties->getMaxSteerAngle();} + float getMaxSteerAngle () const + {return m_kart_properties->getMaxSteerAngle(getSpeed());} float getGravityCenterShift () const {return m_kart_properties->getGravityCenterShift(); } float getWheelieMaxSpeedRatio () const @@ -181,8 +182,6 @@ public: {return m_kart_properties->getWheelieRestoreRate(); } float getWheelieSpeedBoost() const {return m_kart_properties->getWheelieSpeedBoost(); } - float getSteerAngle () const - {return m_controls.lr*m_kart_properties->getMaxSteerAngle(); } float getSteerPercent () const {return m_controls.lr; } float getMaxSpeed () const {return m_max_speed; } void setTimeAtLap (float t){m_time_at_last_lap=t; } diff --git a/src/kart_properties.cpp b/src/kart_properties.cpp index 6fae19b65..e35e8ab7c 100644 --- a/src/kart_properties.cpp +++ b/src/kart_properties.cpp @@ -151,7 +151,37 @@ void KartProperties::getAllData(const lisp::Lisp* lisp) lisp->get("time-full-steer", m_time_full_steer); lisp->get("brake-factor", m_brake_factor); lisp->get("mass", m_mass); - lisp->get("max-steer-angle", m_max_steer_angle); + + std::vector v; + if(lisp->getVector("max-speed-angle", v)) + { + if(v.size()!=2) + printf("Incorrect max-speed-angle specifications for kart %'s'\n", + getIdent()); + else + { + m_max_speed_turn = v[0]; + m_angle_at_max = v[1]; + } + } + v.clear(); + if(lisp->getVector("min-speed-angle", v)) + { + if(v.size()!=2) + printf("Incorrect min-speed-angle specifications for kart %'s'\n", + getIdent()); + else + { + m_min_speed_turn = v[0]; + m_angle_at_min = v[1]; + } + } + if(m_max_speed_turn == m_min_speed_turn) + m_speed_angle_increase = 0.0; + else + m_speed_angle_increase = (m_angle_at_min - m_angle_at_max) + / (m_max_speed_turn - m_min_speed_turn); + lisp->get("wheelie-max-speed-ratio", m_wheelie_max_speed_ratio ); lisp->get("wheelie-max-pitch", m_wheelie_max_pitch ); lisp->get("wheelie-pitch-rate", m_wheelie_pitch_rate ); @@ -217,7 +247,6 @@ void KartProperties::init_defaults() m_time_full_steer = stk_config->m_time_full_steer; m_brake_factor = stk_config->m_brake_factor; m_mass = stk_config->m_mass; - m_max_steer_angle = stk_config->m_max_steer_angle; m_wheelie_max_speed_ratio = stk_config->m_wheelie_max_speed_ratio; m_wheelie_max_pitch = stk_config->m_wheelie_max_pitch; m_wheelie_pitch_rate = stk_config->m_wheelie_pitch_rate; @@ -248,6 +277,19 @@ void KartProperties::init_defaults() m_camera_max_accel = stk_config->getCameraMaxAccel(); m_camera_max_brake = stk_config->getCameraMaxBrake(); m_camera_distance = stk_config->getCameraDistance(); + m_min_speed_turn = stk_config->m_min_speed_turn; + m_angle_at_min = stk_config->m_angle_at_min; + m_max_speed_turn = stk_config->m_max_speed_turn; + m_angle_at_max = stk_config->m_angle_at_max; } // init_defaults +// ---------------------------------------------------------------------------- +float KartProperties::getMaxSteerAngle(float speed) const +{ + if(speed<=m_min_speed_turn) return m_angle_at_min; + if(speed>=m_max_speed_turn) return m_angle_at_max; + return m_angle_at_min - speed*m_speed_angle_increase; +} // getMaxSteerAngle + + /* EOF */ diff --git a/src/kart_properties.hpp b/src/kart_properties.hpp index 948763c04..3e96e80a9 100644 --- a/src/kart_properties.hpp +++ b/src/kart_properties.hpp @@ -60,7 +60,6 @@ protected: float m_height_cog; // height of center of gravity float m_engine_power; // maximum force from engine float m_brake_factor; // braking factor * engine_power = braking force - float m_max_steer_angle; // maximum steering angle float m_time_full_steer; // time for player karts to reach full steer angle float m_wheelie_max_speed_ratio; // percentage of maximum speed for wheelies float m_wheelie_max_pitch; // maximum pitch for wheelies @@ -69,6 +68,10 @@ protected: float m_wheelie_speed_boost; // speed boost while doing a wheelie float m_wheelie_power_boost; // increase in engine power + float m_min_speed_turn, m_angle_at_min; // speed dependent steering: max + float m_max_speed_turn, m_angle_at_max; // turn angle at lowest speed etc + float m_speed_angle_increase; + // bullet physics data // ------------------- float m_suspension_stiffness; @@ -106,14 +109,15 @@ protected: public: KartProperties (); - virtual ~KartProperties (); + virtual ~KartProperties (); - virtual void init_defaults (); - virtual void getAllData (const lisp::Lisp* lisp); - virtual void load (const std::string filename, - const std::string node="tuxkart-kart", - bool dont_load_models=false, - bool dont_load_materials=false); + virtual void init_defaults (); + virtual void getAllData (const lisp::Lisp* lisp); + virtual void load (const std::string filename, + const std::string node="tuxkart-kart", + bool dont_load_models=false, + bool dont_load_materials=false); + float getMaxSteerAngle (float speed) const; Material* getIconMaterial () const {return m_icon_material; } ssgEntity* getModel () const {return m_model; } @@ -133,7 +137,6 @@ public: float getBrakeFactor () const {return m_brake_factor; } float getWheelBase () const {return m_wheel_base; } float getHeightCOG () const {return m_height_cog; } - float getMaxSteerAngle () const {return m_max_steer_angle; } float getMaxSpeedReverseRatio () const {return m_max_speed_reverse_ratio; } float getWheelieMaxSpeedRatio () const {return m_wheelie_max_speed_ratio; } float getWheelieMaxPitch () const {return m_wheelie_max_pitch; } diff --git a/src/kart_properties_manager.cpp b/src/kart_properties_manager.cpp index 5c2d28bb3..edde6f953 100644 --- a/src/kart_properties_manager.cpp +++ b/src/kart_properties_manager.cpp @@ -85,9 +85,9 @@ void KartPropertiesManager::loadKartData(bool dont_load_models) KartProperties* kp = new KartProperties(); kp->load(kart_file, "tuxkart-kart", dont_load_models); m_karts_properties.push_back(kp); - if(kp->getMaxSteerAngle() > m_max_steer_angle) + if(kp->getMaxSteerAngle(0) > m_max_steer_angle) { - m_max_steer_angle = kp->getMaxSteerAngle(); + m_max_steer_angle = kp->getMaxSteerAngle(0); } const std::vector& groups=kp->getGroups(); for(unsigned int g=0; g