Added some (experimental) leaning for karts driving fast in

a curve. Feedback welcome (note many karts have some leaning
in their animation, best use a kart like suzanne which doesn't
do that).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12984 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2013-06-26 11:00:53 +00:00
parent 524c0c6a59
commit f147d8e662
5 changed files with 101 additions and 12 deletions

View File

@ -389,6 +389,12 @@
restricted to. -->
<swatter duration="10" distance="3" squash-duration="5"
squash-slowdown="0.5"/>
<!-- Leaning related parameters, i.e. slightly leaning the karts when
driving a fast curve.
max: maximum leaning (i.e. when steering as much as possible at highest
speed), in degrees.
sped: Speed with which the leaning changes (in degree/second). -->
<lean max="8.6" speed="5.0" />
<!-- turn-radius defines the turn radius of the kart at
a given speed. The actual steering angle is dependent on the

View File

@ -337,6 +337,7 @@ void Kart::reset()
m_bounce_back_time = 0.0f;
m_time_last_crash = 0.0f;
m_speed = 0.0f;
m_current_lean = 0.0f;
m_view_blocked_by_plunger = 0.0f;
m_has_caught_nolok_bubblegum = false;
@ -2261,13 +2262,67 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
m_kart_gfx->resizeBox(KartGFX::KGFX_ZIPPER, getSpeed(), dt);
Moveable::updateGraphics(dt, center_shift,
btQuaternion(m_skidding->getVisualSkidRotation(),
0, 0));
// Note that we compare with maximum speed of the kart, not
// maximum speed including terrain effects. This avoids that
// leaning might get less if a kart gets a special that increases
// its maximum speed, but not the current speed (by much). On the
// other hand, that ratio can often be greater than 1.
float speed_frac = m_speed / m_kart_properties->getMaxSpeed();
if(speed_frac>1.0f)
speed_frac = 1.0f;
else if (speed_frac < 0.0f) // no leaning when backwards driving
speed_frac = 0.0f;
/*
const float steer_frac = m_skidding->getSteeringFraction();
const float roll_speed = m_kart_properties->getLeanSpeed();
if(speed_frac > 0.8f && fabsf(steer_frac)>0.5f)
{
// Use steering ^ 7, which means less effect at lower
// steering
const float f = m_skidding->getSteeringFraction();
const float f2 = f*f;
const float max_lean = -m_kart_properties->getMaxLean()
* f2*f2*f2*f
* speed_frac;
if(max_lean>0)
{
m_current_lean += dt* roll_speed;
if(m_current_lean > max_lean)
m_current_lean = max_lean;
}
else if(max_lean<0)
{
m_current_lean -= dt*roll_speed;
if(m_current_lean < max_lean)
m_current_lean = max_lean;
}
}
else if(m_current_lean!=0.0f)
{
// Disable any potential roll factor that is still applied
// --------------------------------------------------------
if(m_current_lean>0)
{
m_current_lean -= dt * roll_speed;
if(m_current_lean < 0.0f)
m_current_lean = 0.0f;
}
else
{
m_current_lean += dt * roll_speed;
if(m_current_lean>0.0f)
m_current_lean = 0.0f;
}
}
float heading = m_skidding->getVisualSkidRotation();
Moveable::updateGraphics(dt, center_shift,
btQuaternion(heading, 0, m_current_lean));
#ifdef XX
// cheap wheelie effect
if (m_zipper_fire && m_zipper_fire->getCreationRate() > 0.0f)
if (m_controls.m_nitro)
{
m_node->updateAbsolutePosition();
m_kart_model->getWheelNodes()[0]->updateAbsolutePosition();
@ -2275,8 +2330,8 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
core::vector3df rot = m_node->getRotation();
float ratio = float(m_zipper_fire->getCreationRate())
/float(m_zipper_fire->getParticlesInfo()->getMaxRate());
float ratio = 0.8f; //float(m_zipper_fire->getCreationRate())
// /float(m_zipper_fire->getParticlesInfo()->getMaxRate());
const float a = (13.4f - ratio*13.0f);
float dst = -45.0f*sin((a*a)/180.f*M_PI);
@ -2290,7 +2345,8 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
m_node->setPosition(m_node->getPosition() + core::vector3df(0,wheel_y_after - wheel_y,0));
}
*/
#endif
} // updateGraphics
// ----------------------------------------------------------------------------

View File

@ -108,7 +108,6 @@ private:
/** For stars rotating around head effect */
Stars *m_stars_effect;
private:
/** True if the kart hasn't moved since 'ready-set-go' - used to
* determine startup boost. */
bool m_has_started;
@ -127,6 +126,9 @@ private:
* the kart is squashed. */
float m_squash_time;
/** Current leaning of the kart. */
float m_current_lean;
/** If > 0 then bubble gum effect is on */
float m_bubblegum_time;

View File

@ -87,7 +87,7 @@ KartProperties::KartProperties(const std::string &filename)
m_camera_distance = m_camera_forward_up_angle =
m_camera_backward_up_angle = m_explosion_invulnerability_time =
m_rescue_time = m_rescue_height = m_explosion_time =
m_explosion_radius =
m_explosion_radius = m_max_lean = m_lean_speed =
m_swatter_distance2 = m_swatter_duration = m_squash_slowdown =
m_squash_duration = m_downward_impulse_factor = UNDEFINED;
@ -500,6 +500,14 @@ void KartProperties::getAllData(const XMLNode * root)
}
}
if(const XMLNode *lean_node= root->getNode("lean"))
{
lean_node->get("max", &m_max_lean );
lean_node->get("speed", &m_lean_speed);
m_max_lean *= DEGREE_TO_RAD;
m_lean_speed *= DEGREE_TO_RAD;
}
if(const XMLNode *camera_node= root->getNode("camera"))
{
camera_node->get("distance", &m_camera_distance);
@ -654,8 +662,10 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_nitro_max, "nitro max" );
CHECK_NEG(m_swatter_distance2, "swatter distance" );
CHECK_NEG(m_swatter_duration, "swatter duration" );
CHECK_NEG(m_squash_duration, "squash-duration" );
CHECK_NEG(m_squash_slowdown, "squash-slowdown" );
CHECK_NEG(m_squash_duration, "swatter squash-duration" );
CHECK_NEG(m_squash_slowdown, "swatter squash-slowdown" );
CHECK_NEG(m_max_lean, "lean max" );
CHECK_NEG(m_lean_speed, "lean speed" );
CHECK_NEG(m_rescue_height, "rescue height" );
CHECK_NEG(m_rescue_time, "rescue time" );

View File

@ -225,6 +225,14 @@ private:
* is max_speed*m_squash_slowdown. */
float m_squash_slowdown;
/** The maximum roll a kart graphics should show when driving in a fast
* curve. This is read in as degrees, but stored in radians. */
float m_max_lean;
/** The speed with which the roll (when leaning in a curve) changes
* (in radians/second). */
float m_lean_speed;
/** Engine sound effect. */
std::string m_engine_sfx_type;
@ -806,6 +814,13 @@ public:
/** Returns the slowdown of a kart that is squashed. */
float getSquashSlowdown() const {return m_squash_slowdown; }
// ------------------------------------------------------------------------
/** The maximum leaning a kart should show (In radians). */
float getMaxLean() const { return m_max_lean; }
// ------------------------------------------------------------------------
/** The speed with which a kart should lean (in radians/s). */
float getLeanSpeed() const { return m_lean_speed; }
// ------------------------------------------------------------------------
/** Returns true if wheels should have random rotation at start. */
bool hasRandomWheels() const { return m_has_rand_wheels; }