Support to mirror a texture around U or V axis if a track is driven

in reverse.
This commit is contained in:
hiker 2015-08-03 23:25:11 +10:00
parent 6f11156c04
commit 340dec329c
3 changed files with 33 additions and 14 deletions

View File

@ -84,21 +84,19 @@ Material::Material(const XMLNode *node, bool deprecated)
std::string s;
//node->get("adjust-image", &s );
//if(s=="premultiply")
// m_adjust_image = ADJ_PREMUL;
//else if (s=="divide")
// m_adjust_image = ADJ_DIV;
//else if (s=="" || s=="none")
// m_adjust_image = ADJ_NONE;
//else
// Log::warn("material",
// "Incorrect adjust-image specification: '%s' - ignored.",
// s.c_str());
node->get("high-adhesion", &m_high_tire_adhesion);
node->get("reset", &m_drive_reset );
node->get("high-adhesion", &m_high_tire_adhesion );
node->get("reset", &m_drive_reset );
s = "";
node->get("mirror-axis", &s);
if (s == "u")
s = "U";
else if (s == "v")
s = "V";
if (s != "U" && s != "V")
m_mirror_axis_when_reverse = ' ';
else
m_mirror_axis_when_reverse = s[0];
// backwards compatibility
bool crash_reset = false;
node->get("crash-reset", &crash_reset );
@ -433,6 +431,7 @@ void Material::init()
m_surface = false;
m_ignore = false;
m_drive_reset = false;
m_mirror_axis_when_reverse = ' ';
m_collision_reaction = NORMAL;
m_disable_z_write = false;
m_water_shader_speed_1 = 6.6667f;

View File

@ -156,6 +156,11 @@ private:
bool m_fog;
/** Either ' ' (no mirroring), 'U' or 'V' if a texture needs to be
* mirrored when driving in reverse. Typically used for arrows indicating
* the direction. */
char m_mirror_axis_when_reverse;
ParticleKind* m_particles_effects[EMIT_KINDS_COUNT];
/** For normal maps */
@ -373,6 +378,9 @@ public:
// ------------------------------------------------------------------------
ShaderType getShaderType() const { return m_shader_type; }
// ------------------------------------------------------------------------
/** True if this texture should have the U coordinates mirrored. */
char getMirrorAxisInReverse() const { return m_mirror_axis_when_reverse; }
// ------------------------------------------------------------------------
} ;

View File

@ -885,6 +885,18 @@ void Track::convertTrackToBullet(scene::ISceneNode *node)
if (mb->getVertexType() == video::EVT_STANDARD)
{
irr::video::S3DVertex* mbVertices=(video::S3DVertex*)mb->getVertices();
if (race_manager->getReverseTrack() &&
material->getMirrorAxisInReverse() != ' ')
{
for (unsigned int i = 0; i < mb->getVertexCount(); i++)
{
core::vector2df &tc = mb->getTCoords(i);
if (material->getMirrorAxisInReverse() == 'V')
tc.Y = 1 - tc.Y;
else
tc.X = 1 - tc.X;
}
} // reverse track and texture needs mirroring
for (unsigned int matrix_index = 0; matrix_index < matrices.size(); matrix_index++)
{
for (unsigned int j = 0; j < mb->getIndexCount(); j += 3)