The turn angles at a certain (minimum and maximum) speeds

have been replaced with the radius of the turn (since the
turn angle depends on the wheelbase of the kart). This way
the turning behaviour can be defined independent of the
kart physics.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2484 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2008-11-20 04:54:31 +00:00
parent b4e87f549f
commit 49d9aeb365
5 changed files with 41 additions and 25 deletions

View File

@ -66,12 +66,16 @@
;; Bullet physics attributes
(brake-factor 2.75 )
;; 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
;; Defines the smallest turn radius at lowest speed (4.64 m at
;; speed 0) and at high speed (13.5 m 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)
;; allows for tighter turns at lower speeds. The actual steering
;; angle is dependent on the wheel base of the kart:
;; radius = wheel_base/sin(steering_angle)
;; By specifying the radius the steering behaviour can be defined
;; independent of the kart size.
(min-speed-radius 0 19 )
(max-speed-radius 12 6.4)
(engine-power 400 )
(mass 225 )
(suspension-stiffness 48.0 )

View File

@ -784,7 +784,7 @@ void Kart::updatePhysics (float dt)
}
if(m_wheelie_angle<=0.0f)
{
const float steering = DEGREE_TO_RAD(getMaxSteerAngle()) * m_controls.lr;
const float steering = getMaxSteerAngle() * m_controls.lr;
m_vehicle->setSteeringValue(steering, 0);
m_vehicle->setSteeringValue(steering, 1);
}

View File

@ -147,6 +147,17 @@ void KartProperties::load(const std::string &filename, const std::string &node,
}
m_kart_model.setDefaultPhysicsPosition(m_gravity_center_shift,
m_wheel_radius);
float wheel_base = fabsf( m_kart_model.getWheelPhysicsPosition(0).getY()
-m_kart_model.getWheelPhysicsPosition(2).getY());
m_angle_at_min = asinf(wheel_base/m_min_radius);
m_angle_at_max = asinf(wheel_base/m_max_radius);
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);
// Useful when tweaking kart parameters
if(user_config->m_print_kart_sizes)
printf("%s:\twidth: %f\tlength: %f\theight: %f\n",getIdent().c_str(),
@ -175,7 +186,7 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
lisp->get("mass", m_mass);
std::vector<float> v;
if(lisp->getVector("max-speed-angle", v))
if(lisp->getVector("max-speed-radius", v))
{
if(v.size()!=2)
printf("Incorrect max-speed-angle specifications for kart '%s'\n",
@ -183,11 +194,11 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
else
{
m_max_speed_turn = v[0];
m_angle_at_max = v[1];
m_max_radius = v[1];
}
}
v.clear();
if(lisp->getVector("min-speed-angle", v))
if(lisp->getVector("min-speed-radius", v))
{
if(v.size()!=2)
printf("Incorrect min-speed-angle specifications for kart '%s'\n",
@ -195,14 +206,9 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
else
{
m_min_speed_turn = v[0];
m_angle_at_min = v[1];
m_min_radius = 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 );
@ -279,9 +285,9 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_mass, "mass" );
CHECK_NEG(m_engine_power, "engine-power" );
CHECK_NEG(m_min_speed_turn, "min-speed-angle" );
CHECK_NEG(m_angle_at_min, "min-speed-angle" );
CHECK_NEG(m_min_radius, "min-speed-angle" );
CHECK_NEG(m_max_speed_turn, "max-speed-angle" );
CHECK_NEG(m_angle_at_max, "max-speed-angle" );
CHECK_NEG(m_max_radius, "max-speed-angle" );
CHECK_NEG(m_brake_factor, "brake-factor" );
CHECK_NEG(m_time_full_steer, "time-full-steer" );

View File

@ -46,6 +46,7 @@ private:
std::vector<std::string> m_groups; /**< List of all groups the kart
belongs to. */
static float UNDEFINED;
float m_speed_angle_increase; /**< Increase of turn angle with speed. */
protected:
// Display and gui
@ -78,11 +79,16 @@ 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:
* maximum speed to use. */
float m_max_speed_turn, m_angle_at_max; /**< Turn angle at lowest speed
* etc. */
float m_speed_angle_increase;
float m_min_speed_turn, /**< Speed for smallest turn radius. */
m_angle_at_min, /**< Steering angle for minimal turn
radius. Computed from radius and
kart length. */
m_min_radius; /**< Smallest turn radius. */
float m_max_speed_turn, /**< Speed for largest turn radius. */
m_angle_at_max, /**< Steering angle for maximum turn
radius. Computed from radius and
kart length. */
m_max_radius; /**< Largest turn radius. */
ssgEntity *m_wheel_model[4]; /**< The four wheel models. */
std::string m_wheel_filename[4]; /**< Filename of the wheel models. */

View File

@ -192,7 +192,7 @@ void DefaultRobot::handle_braking()
//even if we are in the inside, because the kart would be 'thrown'
//out of the curve.
if(!(lworld->getDistanceToCenterForKart(getWorldKartId()) > RaceManager::getTrack()->getWidth()[kart_info.m_track_sector] *
-CURVE_INSIDE_PERC || m_curve_angle > getMaxSteerAngle()))
-CURVE_INSIDE_PERC || m_curve_angle > RAD_TO_DEGREE(getMaxSteerAngle())))
{
m_controls.brake = false;
return;
@ -201,7 +201,7 @@ void DefaultRobot::handle_braking()
else if( m_curve_angle < -MIN_TRACK_ANGLE ) //Next curve is right
{
if(!(lworld->getDistanceToCenterForKart( getWorldKartId() ) < RaceManager::getTrack()->getWidth()[kart_info.m_track_sector] *
CURVE_INSIDE_PERC || m_curve_angle < -getMaxSteerAngle()))
CURVE_INSIDE_PERC || m_curve_angle < -RAD_TO_DEGREE(getMaxSteerAngle())))
{
m_controls.brake = false;
return;
@ -859,7 +859,7 @@ int DefaultRobot::calc_steps()
*/
float DefaultRobot::angle_to_control( float angle ) const
{
angle *= 180.0f / ( getMaxSteerAngle() * M_PI ) ;
angle = angle / getMaxSteerAngle();
if(angle > 1.0f) return 1.0f;
else if(angle < -1.0f) return -1.0f;