Add smoothing for steering percent

This commit is contained in:
Benau 2018-07-04 16:22:09 +08:00
parent ad773089a5
commit 7caad2905e
6 changed files with 46 additions and 51 deletions

View File

@ -112,7 +112,7 @@ public:
// Functions related to controlling the kart
// ------------------------------------------------------------------------
/** Returns the current steering value for this kart. */
float getSteerPercent() const { return m_controls.getSteer(); }
virtual float getSteerPercent() const { return m_controls.getSteer(); }
// ------------------------------------------------------------------------
/** Returns all controls of this kart. */
KartControl& getControls() { return m_controls; }
@ -279,10 +279,6 @@ public:
* like Ghost. */
virtual float getSpeed() const = 0;
// ------------------------------------------------------------------------
/** Returns the exponentially smoothened speed of the kart in
* which is removes shaking from camera. */
virtual float getSmoothedSpeed() const = 0;
// ------------------------------------------------------------------------
/** Returns the current maximum speed for this kart, this includes all
* bonus and maluses that are currently applied. */
virtual float getCurrentMaxSpeed() const = 0;

View File

@ -165,7 +165,6 @@ Kart::Kart (const std::string& ident, unsigned int world_kart_id,
// Set position and heading:
m_reset_transform = init_transform;
m_speed = 0.0f;
m_smoothed_speed = 0.0f;
m_last_factor_engine_sound = 0.0f;
m_kart_model->setKart(this);
@ -372,7 +371,6 @@ void Kart::reset()
m_brake_ticks = 0;
m_ticks_last_crash = 0;
m_speed = 0.0f;
m_smoothed_speed = 0.0f;
m_current_lean = 0.0f;
m_falling_time = 0.0f;
m_view_blocked_by_plunger = 0;
@ -1706,9 +1704,6 @@ void Kart::updateSpeed()
m_speed = -m_speed;
}
float f = 0.3f;
m_smoothed_speed = f*m_speed + (1.0f - f)*m_smoothed_speed;
// At low velocity, forces on kart push it back and forth so we ignore this
// - quick'n'dirty workaround for bug 1776883
if (fabsf(m_speed) < 0.2f ||
@ -1716,7 +1711,6 @@ void Kart::updateSpeed()
dynamic_cast<ExplosionAnimation*>( getKartAnimation() ) )
{
m_speed = 0;
m_smoothed_speed = 0;
}
} // updateSpeed

View File

@ -420,7 +420,7 @@ public:
* skidding related values) - non-const. */
virtual Skidding *getSkidding() OVERRIDE { return m_skidding; }
// ------------------------------------------------------------------------
virtual RaceManager::KartType getType() const { return m_type; }
virtual RaceManager::KartType getType() const OVERRIDE { return m_type; }
// ------------------------------------------------------------------------
/** Returns the bullet vehicle which represents this kart. */
virtual btKart *getVehicle() const OVERRIDE { return m_vehicle; }
@ -428,12 +428,9 @@ public:
/** Returns the speed of the kart in meters/second. */
virtual float getSpeed() const OVERRIDE { return m_speed; }
// ------------------------------------------------------------------------
/** Returns the speed of the kart in meters/second. */
virtual float getSmoothedSpeed() const OVERRIDE { return m_smoothed_speed; }
// ------------------------------------------------------------------------
/** This is used on the client side only to set the speed of the kart
* from the server information. */
virtual void setSpeed(float s) OVERRIDE { m_speed = s; }
* from the server information. */
virtual void setSpeed(float s) OVERRIDE { m_speed = s; }
// ------------------------------------------------------------------------
virtual btQuaternion getVisualRotation() const OVERRIDE;
// ------------------------------------------------------------------------
@ -453,7 +450,7 @@ public:
virtual Controller* getController() OVERRIDE { return m_controller; }
// ------------------------------------------------------------------------
/** Returns the controller of this kart (const version). */
const Controller* getController() const { return m_controller; }
const Controller* getController() const OVERRIDE { return m_controller; }
// ------------------------------------------------------------------------
/** True if the wheels are touching the ground. */
virtual bool isOnGround() const OVERRIDE;
@ -525,7 +522,7 @@ public:
virtual const Vec3& getRecentPreviousXYZ() const OVERRIDE;
// ------------------------------------------------------------------------
/** Returns the time at which the recent previous position occured */
virtual const float getRecentPreviousXYZTime() const;
virtual const float getRecentPreviousXYZTime() const OVERRIDE;
// ------------------------------------------------------------------------
/** For debugging only: check if a kart is flying. */
bool isFlying() const { return m_flying; }

View File

@ -61,6 +61,7 @@ void KartRewinder::saveTransform()
{
if (!getKartAnimation())
Moveable::prepareSmoothing();
m_prev_steering = getSteerPercent();
} // saveTransform
// ----------------------------------------------------------------------------
@ -70,6 +71,20 @@ void KartRewinder::computeError()
Moveable::checkSmoothing();
} // computeError
// ----------------------------------------------------------------------------
float KartRewinder::getSteerPercent() const
{
if (m_smoothing == SS_TO_ADJUST)
{
float ratio = m_adjust_time_dt / m_adjust_time;
if (ratio > 1.0f)
ratio = 1.0f;
return ratio * AbstractKart::getSteerPercent() +
(1.0f - ratio) * m_prev_steering;
}
return AbstractKart::getSteerPercent();
} // getSteerPercent
// ----------------------------------------------------------------------------
/** Saves all state information for a kart in a memory buffer. The memory
* is allocated here and the address returned. It will then be managed

View File

@ -34,34 +34,26 @@ private:
enum { EVENT_CONTROL = 0x01,
EVENT_ATTACH = 0x02 };
float m_prev_steering;
public:
KartRewinder(const std::string& ident,
unsigned int world_kart_id,
int position, const btTransform& init_transform,
PerPlayerDifficulty difficulty,
std::shared_ptr<RenderInfo> ri);
virtual ~KartRewinder() {};
virtual void saveTransform() OVERRIDE;
virtual void computeError() OVERRIDE;
virtual BareNetworkString* saveState();
void reset();
virtual void restoreState(BareNetworkString *p, int count) OVERRIDE;
virtual void rewindToEvent(BareNetworkString *p) OVERRIDE;
virtual void update(int ticks) OVERRIDE;
// -------------------------------------------------------------------------
virtual void undoState(BareNetworkString *p) OVERRIDE
{
}; // undoState
// -------------------------------------------------------------------------
virtual void undoEvent(BareNetworkString *p) OVERRIDE
{
}; // undoEvent
// -------------------------------------------------------------------------
KartRewinder(const std::string& ident, unsigned int world_kart_id,
int position, const btTransform& init_transform,
PerPlayerDifficulty difficulty,
std::shared_ptr<RenderInfo> ri);
~KartRewinder() {}
virtual void saveTransform() OVERRIDE;
virtual void computeError() OVERRIDE;
virtual BareNetworkString* saveState() OVERRIDE;
void reset() OVERRIDE;
virtual void restoreState(BareNetworkString *p, int count) OVERRIDE;
virtual void rewindToEvent(BareNetworkString *p) OVERRIDE;
virtual void update(int ticks) OVERRIDE;
virtual float getSteerPercent() const OVERRIDE;
// -------------------------------------------------------------------------
virtual void undoState(BareNetworkString *p) OVERRIDE {}
// -------------------------------------------------------------------------
virtual void undoEvent(BareNetworkString *p) OVERRIDE {}
}; // Rewinder
#endif

View File

@ -41,7 +41,7 @@ class Material;
*/
class Moveable: public NoCopy
{
private:
protected:
enum SmoothingState
{
SS_NONE = 0,
@ -49,6 +49,11 @@ private:
SS_TO_REAL
};
float m_adjust_time, m_adjust_time_dt;
SmoothingState m_smoothing;
private:
Vec3 m_velocityLC; /**<Velocity in kart coordinates. */
/** The bullet transform of this rigid body. */
btTransform m_transform;
@ -69,10 +74,6 @@ private:
std::pair<btTransform, Vec3> m_prev_position_data;
float m_adjust_time, m_adjust_time_dt;
SmoothingState m_smoothing;
btTransform m_smoothed_transform;
protected: