Added speed-weighted texture animations, as requested by samuncle.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14358 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
1074bf720e
commit
734fef45a9
@ -487,7 +487,7 @@
|
||||
<!-- Parameters for the speed-weighted objects:
|
||||
a bigger value for strength-factor leads to the speed of the kart more quickly affecting
|
||||
the strength of the animation (up to a maximum value that corresponds to the original animation) -->
|
||||
<speed-weighted strength-factor="0.05" speed-factor="1.0"/>
|
||||
<speed-weighted strength-factor="0.05" speed-factor="1.0" texture-speed-x="0.0" texture-speed-y="0.0"/>
|
||||
|
||||
<!-- friction: slip used for bullet skidding. A high value
|
||||
(like 10000000) disables bullet skidding. -->
|
||||
|
@ -2395,7 +2395,7 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
|
||||
wheel_up_axis[i] = m_default_suspension_length[i]
|
||||
- m_vehicle->getWheelInfo(i).m_raycastInfo.m_suspensionLength;
|
||||
}
|
||||
m_kart_model->update(m_wheel_rotation_dt, getSteerPercent(), wheel_up_axis, m_speed);
|
||||
m_kart_model->update(dt, m_wheel_rotation_dt, getSteerPercent(), wheel_up_axis, m_speed);
|
||||
|
||||
Vec3 center_shift = m_kart_properties->getGravityCenterShift();
|
||||
float y = m_vehicle->getWheelInfo(0).m_chassisConnectionPointCS.getY()
|
||||
|
@ -592,7 +592,7 @@ void KartModel::reset()
|
||||
{
|
||||
// Reset the wheels
|
||||
const float suspension[4]={0,0,0,0};
|
||||
update(0, 0.0f, suspension, 0.0f);
|
||||
update(0.0f, 0.0f, 0.0f, suspension, 0.0f);
|
||||
|
||||
// Stop any animations currently being played.
|
||||
setAnimation(KartModel::AF_DEFAULT);
|
||||
@ -700,12 +700,13 @@ void KartModel::OnAnimationEnd(scene::IAnimatedMeshSceneNode *node)
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Rotates and turns the wheels appropriately, and adjust for suspension
|
||||
+ updates the speed-weighted objects' animations.
|
||||
* \param dt time since last frame
|
||||
* \param rotation_dt How far the wheels have rotated since last time.
|
||||
* \param steer The actual steer settings.
|
||||
* \param suspension Suspension height for all four wheels.
|
||||
* \param speed The speed of the kart in meters/sec, used for the speed-weighted objects' animations
|
||||
*/
|
||||
void KartModel::update(float rotation_dt, float steer, const float suspension[4], float speed)
|
||||
void KartModel::update(float dt, float rotation_dt, float steer, const float suspension[4], float speed)
|
||||
{
|
||||
float clamped_suspension[4];
|
||||
// Clamp suspension to minimum and maximum suspension length, so that
|
||||
@ -783,6 +784,27 @@ void KartModel::update(float rotation_dt, float steer, const float suspension[4]
|
||||
float anim_speed = speed * speed_factor;
|
||||
obj.m_node->setAnimationSpeed(anim_speed);
|
||||
}
|
||||
|
||||
// Texture animation
|
||||
const core::vector2df& tex_speed = m_kart->getKartProperties()->getSpeedWeightedTextureSpeed();
|
||||
if(tex_speed != core::vector2df(0.0f, 0.0f))
|
||||
{
|
||||
obj.m_texture_cur_offset += speed * tex_speed * dt;
|
||||
if(obj.m_texture_cur_offset.X > 1.0f) obj.m_texture_cur_offset.X = fmod(obj.m_texture_cur_offset.X, 1.0f);
|
||||
if(obj.m_texture_cur_offset.Y > 1.0f) obj.m_texture_cur_offset.Y = fmod(obj.m_texture_cur_offset.Y, 1.0f);
|
||||
|
||||
for(unsigned int i=0; i<obj.m_node->getMaterialCount(); i++)
|
||||
{
|
||||
video::SMaterial &irrMaterial=obj.m_node->getMaterial(i);
|
||||
for(unsigned int j=0; j<video::MATERIAL_MAX_TEXTURES; j++)
|
||||
{
|
||||
video::ITexture* t=irrMaterial.getTexture(j);
|
||||
if(!t) continue;
|
||||
core::matrix4 *m = &irrMaterial.getTextureMatrix(j);
|
||||
m->setTextureTranslate(obj.m_texture_cur_offset.X, obj.m_texture_cur_offset.Y);
|
||||
} // for j<MATERIAL_MAX_TEXTURES
|
||||
} // for i<getMaterialCount
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the end animation is being played, if so, don't
|
||||
|
@ -51,6 +51,9 @@ struct SpeedWeightedObject
|
||||
|
||||
/** Filename of the "speed weighted" object */
|
||||
std::string m_name;
|
||||
|
||||
/** Current uv translation in the texture matrix for speed-weighted texture animations */
|
||||
core::vector2df m_texture_cur_offset;
|
||||
};
|
||||
typedef std::vector<SpeedWeightedObject> SpeedWeightedObjectList;
|
||||
|
||||
@ -192,7 +195,7 @@ public:
|
||||
void reset();
|
||||
void loadInfo(const XMLNode &node);
|
||||
bool loadModels(const KartProperties &kart_properties);
|
||||
void update(float rotation_dt, float steer,
|
||||
void update(float dt, float rotation_dt, float steer,
|
||||
const float suspension[4], float speed);
|
||||
void setDefaultPhysicsPosition(const Vec3 ¢er_shift,
|
||||
float wheel_radius);
|
||||
|
@ -69,6 +69,7 @@ KartProperties::KartProperties(const std::string &filename)
|
||||
m_suspension_stiffness = m_wheel_damping_relaxation = m_wheel_base =
|
||||
m_wheel_damping_compression = m_friction_slip = m_roll_influence =
|
||||
m_wheel_radius = m_speed_weighted_strength_factor = m_speed_weighted_speed_factor =
|
||||
m_speed_weighted_texture_speed.X = m_speed_weighted_texture_speed.Y =
|
||||
m_chassis_linear_damping = m_max_suspension_force =
|
||||
m_chassis_angular_damping = m_suspension_rest =
|
||||
m_max_speed_reverse_ratio = m_rescue_vert_offset =
|
||||
@ -431,6 +432,8 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
{
|
||||
speed_weighted_node->get("strength-factor", &m_speed_weighted_strength_factor);
|
||||
speed_weighted_node->get("speed-factor", &m_speed_weighted_speed_factor);
|
||||
speed_weighted_node->get("texture-speed-x", &m_speed_weighted_texture_speed.X);
|
||||
speed_weighted_node->get("texture-speed-y", &m_speed_weighted_texture_speed.Y);
|
||||
}
|
||||
|
||||
if(const XMLNode *friction_node = root->getNode("friction"))
|
||||
|
@ -267,6 +267,7 @@ private:
|
||||
// Parameters for speed-weighted objects
|
||||
float m_speed_weighted_strength_factor;
|
||||
float m_speed_weighted_speed_factor;
|
||||
core::vector2df m_speed_weighted_texture_speed;
|
||||
|
||||
/** An impulse pushing the kart down which is proportional to speed. So
|
||||
* the actual impulse is speed * m_downward_impulse_factor. Set it to
|
||||
@ -540,6 +541,8 @@ public:
|
||||
/** Returns animation speed factor for speed-weighted objects */
|
||||
float getSpeedWeightedSpeedFactor() const {return m_speed_weighted_speed_factor;}
|
||||
|
||||
const core::vector2df& getSpeedWeightedTextureSpeed() const {return m_speed_weighted_texture_speed;}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the wheel base (distance front to rear axis). */
|
||||
float getWheelBase () const {return m_wheel_base; }
|
||||
|
@ -330,7 +330,7 @@ void FeatureUnlockedCutScene::init()
|
||||
m_unlocked_stuff[n].m_root_gift_node = kart_model->attachModel(true);
|
||||
kart_model->setAnimation(KartModel::AF_DEFAULT);
|
||||
float susp[4]={0,0,0,0};
|
||||
kart_model->update(0.0f, 0.0f, susp, 0.0f);
|
||||
kart_model->update(0.0f, 0.0f, 0.0f, susp, 0.0f);
|
||||
|
||||
#ifdef DEBUG
|
||||
m_unlocked_stuff[n].m_root_gift_node->setName("unlocked kart");
|
||||
|
@ -340,7 +340,7 @@ void GrandPrixLose::setKarts(std::vector<std::string> ident_arg)
|
||||
kart_main_node->updateAbsolutePosition();
|
||||
kart_main_node->setRotation(vector3df(0, 90, 0));
|
||||
float susp[4]={0,0,0,0};
|
||||
kart_model->update(0.0f, 0.0f, susp, 0.0f);
|
||||
kart_model->update(0.0f, 0.0f, 0.0f, susp, 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -451,7 +451,7 @@ void GrandPrixWin::setKarts(const std::string idents_arg[3])
|
||||
m_kart_z[n]) );
|
||||
kart_main_node->setScale( core::vector3df(0.4f, 0.4f, 0.4f) );
|
||||
float susp[4]={0,0,0,0};
|
||||
kart_model->update(0.0f, 0.0f, susp, 0.0f);
|
||||
kart_model->update(0.0f, 0.0f, 0.0f, susp, 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user