Add animated by step texture matrix for kart model
This commit is contained in:
parent
3b043b7f47
commit
a47e69d74e
@ -71,20 +71,22 @@ MovingTexture::MovingTexture(core::matrix4 *matrix, float dx, float dy)
|
||||
m_x = v.X;
|
||||
m_y = v.Y;
|
||||
m_count = 0.0f;
|
||||
m_dt = 0.0f;
|
||||
m_sp_tm = NULL;
|
||||
} // MovingTexture
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
MovingTexture::MovingTexture(float dx, float dy)
|
||||
MovingTexture::MovingTexture(float dx, float dy, float dt,
|
||||
bool animated_by_step)
|
||||
{
|
||||
// by default the animation by step is disabled
|
||||
m_isAnimatedByStep = false;
|
||||
m_isAnimatedByStep = animated_by_step;
|
||||
|
||||
m_dx = dx;
|
||||
m_dy = dy;
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
m_count = 0.0f;
|
||||
m_dt = dt;
|
||||
m_matrix = NULL;
|
||||
m_sp_tm = NULL;
|
||||
} // MovingTexture
|
||||
@ -160,5 +162,3 @@ void MovingTexture::update(float dt)
|
||||
}
|
||||
}
|
||||
} // update
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ class XMLNode;
|
||||
* \brief Handles animated textures (textures that move)
|
||||
* \ingroup graphics
|
||||
*/
|
||||
class MovingTexture : public NoCopy
|
||||
class MovingTexture
|
||||
{
|
||||
private:
|
||||
/** Translation increment per second. */
|
||||
@ -52,7 +52,8 @@ private:
|
||||
public:
|
||||
MovingTexture(core::matrix4 *matrix, const XMLNode &node);
|
||||
MovingTexture(core::matrix4 *matrix, float dx, float dy);
|
||||
MovingTexture(float dx, float dy);
|
||||
MovingTexture(float dx, float dy, float dt = 0.0f,
|
||||
bool animated_by_step = false);
|
||||
virtual ~MovingTexture();
|
||||
|
||||
/** Sets the speed of the animation. */
|
||||
@ -62,6 +63,8 @@ public:
|
||||
void setSPTM(float* sp_tm) { m_sp_tm = sp_tm; }
|
||||
virtual void update (float dt);
|
||||
virtual void reset ();
|
||||
float getCurrentX() const { return m_x; }
|
||||
float getCurrentY() const { return m_y; }
|
||||
}
|
||||
; // MovingTexture
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/mesh_tools.hpp"
|
||||
#include "graphics/moving_texture.hpp"
|
||||
#include "graphics/sp/sp_mesh.hpp"
|
||||
#include "graphics/sp/sp_mesh_buffer.hpp"
|
||||
#include "graphics/sp/sp_mesh_node.hpp"
|
||||
@ -62,17 +63,32 @@ SpeedWeightedObject::Properties::Properties()
|
||||
{
|
||||
m_strength_factor = -1.0f;
|
||||
m_speed_factor = 0.0f;
|
||||
m_texture_speed.X = 0.0f;
|
||||
m_texture_speed.Y = 0.0f;
|
||||
m_moving_texture = NULL;
|
||||
} // SpeedWeightedObject::Properties::Properties
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
SpeedWeightedObject::Properties::~Properties()
|
||||
{
|
||||
delete m_moving_texture;
|
||||
} // SpeedWeightedObject::Properties::~Properties
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
SpeedWeightedObject::Properties& SpeedWeightedObject::Properties::
|
||||
operator=(const SpeedWeightedObject::Properties& other)
|
||||
{
|
||||
m_strength_factor = other.m_strength_factor;
|
||||
m_speed_factor = other.m_speed_factor;
|
||||
m_moving_texture = NULL;
|
||||
if (other.m_moving_texture)
|
||||
m_moving_texture = new MovingTexture(*other.m_moving_texture);
|
||||
return *this;
|
||||
} // SpeedWeightedObject::Properties::Properties& operator=
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void SpeedWeightedObject::Properties::loadFromXMLNode(const XMLNode* xml_node)
|
||||
{
|
||||
xml_node->get("strength-factor", &m_strength_factor);
|
||||
xml_node->get("speed-factor", &m_speed_factor);
|
||||
xml_node->get("texture-speed-x", &m_texture_speed.X);
|
||||
xml_node->get("texture-speed-y", &m_texture_speed.Y);
|
||||
} // SpeedWeightedObject::Properties::loadFromXMLNode
|
||||
|
||||
// ============================================================================
|
||||
@ -658,8 +674,7 @@ bool KartModel::loadModels(const KartProperties &kart_properties)
|
||||
(obj.m_model->getMeshBuffer(j));
|
||||
// Pre-upload gl meshes and textures for kart screen
|
||||
mb->uploadGLMesh();
|
||||
if (obj.m_properties.m_texture_speed !=
|
||||
core::vector2df(0.0f, 0.0f))
|
||||
if (obj.m_properties.m_moving_texture)
|
||||
{
|
||||
for (unsigned k = 0; k < mb->getAllSTKMaterials().size();
|
||||
k++)
|
||||
@ -810,8 +825,21 @@ void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node)
|
||||
if (!obj.m_name.empty())
|
||||
{
|
||||
m_speed_weighted_objects.push_back(obj);
|
||||
float dx = 0.0f;
|
||||
float dy = 0.0f;
|
||||
float dt = 0.0f;
|
||||
bool step = false;
|
||||
speed_weighted_node->get("texture-speed-x", &dx);
|
||||
speed_weighted_node->get("texture-speed-y", &dy);
|
||||
speed_weighted_node->get("texture-speed-dt", &dt);
|
||||
speed_weighted_node->get("animated-by-step", &step);
|
||||
if (dx != 0.0f || dy != 0.0f)
|
||||
{
|
||||
m_speed_weighted_objects.back().m_properties.m_moving_texture =
|
||||
new MovingTexture(dx, dy, dt, step);
|
||||
}
|
||||
}
|
||||
} // loadSpeedWeightedInfo
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Loads a single wheel node. Currently this is the name of the wheel model
|
||||
@ -1171,24 +1199,17 @@ void KartModel::update(float dt, float distance, float steer, float speed,
|
||||
obj.m_node->setAnimationSpeed(anim_speed);
|
||||
}
|
||||
|
||||
// Texture animation
|
||||
core::vector2df tex_speed;
|
||||
tex_speed.X = obj.m_properties.m_texture_speed.X;
|
||||
tex_speed.Y = obj.m_properties.m_texture_speed.Y;
|
||||
if (tex_speed != core::vector2df(0.0f, 0.0f))
|
||||
if (obj.m_properties.m_moving_texture)
|
||||
{
|
||||
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);
|
||||
|
||||
obj.m_properties.m_moving_texture->update(speed * dt);
|
||||
SP::SPMeshNode* spmn = dynamic_cast<SP::SPMeshNode*>(obj.m_node);
|
||||
if (spmn)
|
||||
{
|
||||
for (unsigned i = 0; i < spmn->getSPM()->getMeshBufferCount(); i++)
|
||||
{
|
||||
auto& ret = spmn->getTextureMatrix(i);
|
||||
ret[0] = obj.m_texture_cur_offset.X;
|
||||
ret[1] = obj.m_texture_cur_offset.Y;
|
||||
ret[0] = obj.m_properties.m_moving_texture->getCurrentX();
|
||||
ret[1] = obj.m_properties.m_moving_texture->getCurrentY();
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1205,11 +1226,13 @@ void KartModel::update(float dt, float distance, float steer, float speed,
|
||||
if (!t) continue;
|
||||
core::matrix4 *m =
|
||||
&irrMaterial.getTextureMatrix(j);
|
||||
m->setTextureTranslate(obj.m_texture_cur_offset.X,
|
||||
obj.m_texture_cur_offset.Y);
|
||||
m->setTextureTranslate(
|
||||
obj.m_properties.m_moving_texture->getCurrentX(),
|
||||
obj.m_properties.m_moving_texture->getCurrentY());
|
||||
} // for j<MATERIAL_MAX_TEXTURES
|
||||
} // for i<getMaterialCount
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,14 @@ namespace irr
|
||||
class ISceneNode; class IMeshSceneNode; }
|
||||
}
|
||||
using namespace irr;
|
||||
namespace GE { class GERenderInfo; }
|
||||
|
||||
#include "utils/no_copy.hpp"
|
||||
#include "utils/vec3.hpp"
|
||||
|
||||
class AbstractKart;
|
||||
class KartProperties;
|
||||
namespace GE { class GERenderInfo; }
|
||||
class MovingTexture;
|
||||
class XMLNode;
|
||||
|
||||
/** A speed-weighted object is an object whose characteristics are influenced by the kart's speed */
|
||||
@ -48,14 +49,17 @@ struct SpeedWeightedObject
|
||||
{
|
||||
Properties();
|
||||
|
||||
~Properties();
|
||||
|
||||
Properties& operator=(const Properties& other);
|
||||
|
||||
/** Strength factor: how much the kart speed affects the animation's distance from a static pose (-1 to disable) */
|
||||
float m_strength_factor;
|
||||
|
||||
/** Speed factor: how much the kart speed affects the animation's speed (-1 to disable) */
|
||||
float m_speed_factor;
|
||||
|
||||
/** Texture speed, in UV coordinates */
|
||||
core::vector2df m_texture_speed;
|
||||
MovingTexture* m_moving_texture;
|
||||
|
||||
void loadFromXMLNode(const XMLNode* xml_node);
|
||||
|
||||
@ -78,9 +82,6 @@ struct SpeedWeightedObject
|
||||
/** Attach to which bone in kart model if not empty. */
|
||||
std::string m_bone_name;
|
||||
|
||||
/** Current uv translation in the texture matrix for speed-weighted texture animations */
|
||||
core::vector2df m_texture_cur_offset;
|
||||
|
||||
/** Specific properties for this given speed-weighted object,
|
||||
* otherwise just a copy of the values from the kart's properties */
|
||||
Properties m_properties;
|
||||
|
Loading…
Reference in New Issue
Block a user