Allow smoothing for skidmarks
This commit is contained in:
@@ -378,7 +378,8 @@ void Flyable::setAnimation(AbstractKartAnimation *animation)
|
||||
*/
|
||||
void Flyable::updateGraphics(float dt)
|
||||
{
|
||||
Moveable::updateGraphics(dt, Vec3(0, 0, 0), btQuaternion(0, 0, 0, 1));
|
||||
updateSmoothedGraphics(dt);
|
||||
Moveable::updateGraphics();
|
||||
} // updateGraphics
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -89,7 +89,8 @@ void GhostKart::updateGraphics(float dt)
|
||||
|
||||
// Don't call Kart's updateGraphics, since it assumes physics. Instead
|
||||
// immediately call Moveable's updateGraphics.
|
||||
Moveable::updateGraphics(dt, center_shift, btQuaternion(0, 0, 0, 1));
|
||||
Moveable::updateSmoothedGraphics(dt);
|
||||
Moveable::updateGraphics(center_shift, btQuaternion(0, 0, 0, 1));
|
||||
} // updateGraphics
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -3020,16 +3020,17 @@ void Kart::updateGraphics(float dt)
|
||||
// To avoid this, raise the kart enough to offset the leaning.
|
||||
float lean_height = tan(m_current_lean) * getKartWidth()*0.5f;
|
||||
|
||||
Vec3 center_shift(0, 0, 0);
|
||||
Moveable::updateSmoothedGraphics(dt);
|
||||
|
||||
// Update the skidding jump height:
|
||||
Vec3 center_shift(0, 0, 0);
|
||||
float jump_height = m_skidding->updateGraphics(dt);
|
||||
center_shift.setY(jump_height + fabsf(lean_height) + m_graphical_y_offset);
|
||||
center_shift = getTrans().getBasis() * center_shift;
|
||||
center_shift = getSmoothedTrans().getBasis() * center_shift;
|
||||
|
||||
float heading = m_skidding->getVisualSkidRotation();
|
||||
Moveable::updateGraphics(dt, center_shift,
|
||||
btQuaternion(heading, 0, -m_current_lean));
|
||||
Moveable::updateGraphics(center_shift,
|
||||
btQuaternion(heading, 0, -m_current_lean));
|
||||
|
||||
static video::SColor pink(255, 255, 133, 253);
|
||||
static video::SColor green(255, 61, 87, 23);
|
||||
|
||||
@@ -62,7 +62,10 @@ void KartRewinder::reset()
|
||||
void KartRewinder::saveTransform()
|
||||
{
|
||||
if (!getKartAnimation())
|
||||
{
|
||||
Moveable::prepareSmoothing();
|
||||
m_skidding->prepareSmoothing();
|
||||
}
|
||||
|
||||
m_prev_steering = getSteerPercent();
|
||||
} // saveTransform
|
||||
@@ -71,7 +74,10 @@ void KartRewinder::saveTransform()
|
||||
void KartRewinder::computeError()
|
||||
{
|
||||
if (!getKartAnimation())
|
||||
{
|
||||
Moveable::checkSmoothing();
|
||||
m_skidding->checkSmoothing();
|
||||
}
|
||||
|
||||
float diff = fabsf(m_prev_steering - AbstractKart::getSteerPercent());
|
||||
if (diff > 0.05f)
|
||||
|
||||
@@ -74,6 +74,8 @@ public:
|
||||
virtual void undoState(BareNetworkString *p) OVERRIDE {}
|
||||
// -------------------------------------------------------------------------
|
||||
virtual void undoEvent(BareNetworkString *p) OVERRIDE {}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool enableSmoothing() const OVERRIDE { return true; }
|
||||
|
||||
}; // Rewinder
|
||||
#endif
|
||||
|
||||
@@ -125,19 +125,19 @@ void Moveable::checkSmoothing()
|
||||
} // checkSmoothing
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Updates the graphics model. Mainly set the graphical position to be the
|
||||
* same as the physics position, but uses offsets to position and rotation
|
||||
* for special gfx effects (e.g. skidding will turn the karts more).
|
||||
* \param offset_xyz Offset to be added to the position.
|
||||
* \param rotation Additional rotation.
|
||||
*/
|
||||
void Moveable::updateGraphics(float dt, const Vec3& offset_xyz,
|
||||
const btQuaternion& rotation)
|
||||
void Moveable::updateSmoothedGraphics(float dt)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
Vec3 cur_xyz = getXYZ();
|
||||
btQuaternion cur_rot = getRotation();
|
||||
|
||||
if (!enableSmoothing())
|
||||
{
|
||||
m_smoothed_transform.setOrigin(cur_xyz);
|
||||
m_smoothed_transform.setRotation(cur_rot);
|
||||
return;
|
||||
}
|
||||
|
||||
float ratio = 0.0f;
|
||||
if (m_smoothing != SS_NONE)
|
||||
{
|
||||
@@ -216,9 +216,23 @@ void Moveable::updateGraphics(float dt, const Vec3& offset_xyz,
|
||||
getXYZ().getX(), getXYZ().getY(), getXYZ().getZ());
|
||||
#endif
|
||||
|
||||
Vec3 xyz = cur_xyz + offset_xyz;
|
||||
#endif
|
||||
} // updateSmoothedGraphics
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Updates the graphics model. Mainly set the graphical position to be the
|
||||
* same as the physics position, but uses offsets to position and rotation
|
||||
* for special gfx effects (e.g. skidding will turn the karts more).
|
||||
* \param offset_xyz Offset to be added to the position.
|
||||
* \param rotation Additional rotation.
|
||||
*/
|
||||
void Moveable::updateGraphics(const Vec3& offset_xyz,
|
||||
const btQuaternion& rotation)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
Vec3 xyz = m_smoothed_transform.getOrigin() + offset_xyz;
|
||||
m_node->setPosition(xyz.toIrrVector());
|
||||
btQuaternion r_all = cur_rot * rotation;
|
||||
btQuaternion r_all = m_smoothed_transform.getRotation() * rotation;
|
||||
if(btFuzzyZero(r_all.getX()) && btFuzzyZero(r_all.getY()-0.70710677f) &&
|
||||
btFuzzyZero(r_all.getZ()) && btFuzzyZero(r_all.getW()-0.70710677f) )
|
||||
r_all.setX(0.000001f);
|
||||
|
||||
@@ -81,9 +81,9 @@ protected:
|
||||
scene::ISceneNode *m_node;
|
||||
btRigidBody *m_body;
|
||||
KartMotionState *m_motion_state;
|
||||
|
||||
virtual void updateGraphics(float dt, const Vec3& off_xyz,
|
||||
const btQuaternion& off_rotation);
|
||||
virtual void updateSmoothedGraphics(float dt);
|
||||
virtual void updateGraphics(const Vec3& off_xyz = Vec3(0.0f, 0.0f, 0.0f),
|
||||
const btQuaternion& off_rotation = btQuaternion(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
||||
public:
|
||||
Moveable();
|
||||
@@ -163,6 +163,8 @@ public:
|
||||
const Vec3& getSmoothedXYZ() const
|
||||
{ return (Vec3&)m_smoothed_transform.getOrigin(); }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool enableSmoothing() const { return false; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool smoothRotation() const { return true; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual const std::string& getIdent() const
|
||||
@@ -170,7 +172,6 @@ public:
|
||||
static std::string unused("unused");
|
||||
return unused;
|
||||
}
|
||||
|
||||
}; // class Moveable
|
||||
|
||||
#endif
|
||||
|
||||
@@ -77,7 +77,10 @@ void Skidding::reset()
|
||||
m_kart->getKartGFX()->setCreationRateAbsolute(KartGFX::KGFX_SKIDR, 0);
|
||||
m_kart->getKartGFX()->updateSkidLight(0);
|
||||
m_kart->getControls().setSkidControl(KartControl::SC_NONE);
|
||||
|
||||
m_prev_visual_rotation = 0.0f;
|
||||
m_smoothing_time = 0.0f;
|
||||
m_smoothing_dt = -1.0f;
|
||||
|
||||
btVector3 rot(0, 0, 0);
|
||||
// Only access the vehicle if the kart is not a ghost
|
||||
if (!m_kart->isGhostKart())
|
||||
@@ -88,9 +91,9 @@ void Skidding::reset()
|
||||
/** Save the skidding state of a kart. It only saves the important physics
|
||||
* values including m_remaining_jump_time (while this is mostly a graphical
|
||||
* effect, you can't skid while still doing a jump, so it does affect the
|
||||
* state), but not visual only values like m_visual_rotation. Similarly
|
||||
* m_real_steering is output of updateRewind() and will be recomputed every
|
||||
* frame when update() is called, and similar for m_skid_bonus_ready
|
||||
* state). Similarly m_real_steering is output of updateRewind() and will be
|
||||
* recomputed every frame when update() is called, and similar for
|
||||
* m_skid_bonus_ready
|
||||
* \param buffer Buffer for the state information.
|
||||
*/
|
||||
void Skidding::saveState(BareNetworkString *buffer)
|
||||
@@ -115,6 +118,25 @@ void Skidding::rewindTo(BareNetworkString *buffer)
|
||||
m_visual_rotation = buffer->getFloat();
|
||||
} // rewindTo
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Skidding::prepareSmoothing()
|
||||
{
|
||||
m_prev_visual_rotation = getVisualSkidRotation();
|
||||
} // prepareSmoothing
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Skidding::checkSmoothing()
|
||||
{
|
||||
float diff = fabsf(m_prev_visual_rotation - m_visual_rotation);
|
||||
if (diff > 0.1f)
|
||||
{
|
||||
m_smoothing_time = m_kart->getTimeFullSteer(diff);
|
||||
m_smoothing_dt = 0.0f;
|
||||
}
|
||||
else
|
||||
m_smoothing_dt = -1.0f;
|
||||
} // checkSmoothing
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Computes the actual steering fraction to be used in the physics, and
|
||||
* stores it in m_real_skidding. This is later used by kart to set the
|
||||
@@ -230,6 +252,13 @@ float Skidding::getSteeringWhenSkidding(float steering) const
|
||||
*/
|
||||
float Skidding::updateGraphics(float dt)
|
||||
{
|
||||
if (m_smoothing_dt >= 0.0f)
|
||||
{
|
||||
m_smoothing_dt += dt / m_smoothing_time;
|
||||
if (m_smoothing_dt > 1.0f)
|
||||
m_smoothing_dt = -1.0f;
|
||||
}
|
||||
|
||||
if (m_remaining_jump_time <= 0) return 0;
|
||||
|
||||
if (m_remaining_jump_time < 0)
|
||||
@@ -250,7 +279,7 @@ float Skidding::updateGraphics(float dt)
|
||||
float jump_time = kp->getSkidGraphicalJumpTime()
|
||||
- m_remaining_jump_time;
|
||||
return v0 * jump_time - 0.5f * gravity * jump_time * jump_time;
|
||||
|
||||
|
||||
} // updateGraphics
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -450,8 +479,7 @@ void Skidding::update(int ticks, bool is_on_ground,
|
||||
float t = std::min(m_skid_time, kp->getSkidVisualTime());
|
||||
t = std::min(t, kp->getSkidRevertVisualTime());
|
||||
|
||||
float vso = getVisualSkidRotation();
|
||||
btVector3 rot(0, vso * kp->getSkidPostSkidRotateFactor(), 0);
|
||||
btVector3 rot(0, m_visual_rotation * kp->getSkidPostSkidRotateFactor(), 0);
|
||||
m_kart->getVehicle()->setTimedRotation(t, rot);
|
||||
// skid_time is used to count backwards for the GFX
|
||||
m_skid_time = t;
|
||||
@@ -467,7 +495,7 @@ void Skidding::update(int ticks, bool is_on_ground,
|
||||
bonus_force,
|
||||
stk_config->time2Ticks(bonus_time),
|
||||
/*fade-out-time*/ stk_config->time2Ticks(1.0f));
|
||||
|
||||
|
||||
if (m_kart->getController()->canGetAchievements())
|
||||
{
|
||||
PlayerManager::increaseAchievement(
|
||||
@@ -528,4 +556,3 @@ unsigned int Skidding::getSkidBonus(float *bonus_time,
|
||||
}
|
||||
return (unsigned int) kp->getSkidBonusSpeed().size();
|
||||
} // getSkidBonusForce
|
||||
|
||||
|
||||
@@ -65,6 +65,12 @@ private:
|
||||
/** Set to >0 when a graphical jump is to be done. */
|
||||
float m_remaining_jump_time;
|
||||
|
||||
float m_prev_visual_rotation;
|
||||
|
||||
float m_smoothing_time;
|
||||
|
||||
float m_smoothing_dt;
|
||||
|
||||
public:
|
||||
/** SKID_NONE: Kart is currently not skidding.
|
||||
* SKID_ACCUMULATE_LEFT: Kart is skidding to the left and accumulating
|
||||
@@ -105,7 +111,15 @@ public:
|
||||
/** Determines how much the graphics model of the kart should be rotated
|
||||
* additionally (for skidding), depending on how long the kart has been
|
||||
* skidding etc. */
|
||||
float getVisualSkidRotation() const { return m_visual_rotation; };
|
||||
float getVisualSkidRotation() const
|
||||
{
|
||||
if (m_smoothing_dt >= 0.0f)
|
||||
{
|
||||
return m_smoothing_dt * m_visual_rotation +
|
||||
(1.0f - m_smoothing_dt) * m_prev_visual_rotation;
|
||||
}
|
||||
return m_visual_rotation;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the current skid factor in [1, skid_max_for_this_kart]. */
|
||||
float getSkidFactor() const { return m_skid_factor; }
|
||||
@@ -128,6 +142,11 @@ public:
|
||||
bool getSkidBonusReady() const { return m_skid_bonus_ready; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isJumping() const { return m_remaining_jump_time > 0; }
|
||||
// ------------------------------------------------------------------------
|
||||
void prepareSmoothing();
|
||||
// ------------------------------------------------------------------------
|
||||
void checkSmoothing();
|
||||
|
||||
}; // Skidding
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user