stk-code_catmod/src/graphics/moving_texture.cpp

80 lines
2.5 KiB
C++
Raw Normal View History

// $Id: moving_texture.cpp 796 2006-09-27 07:06:34Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/moving_texture.hpp"
#include "io/xml_node.hpp"
/** Constructor for an animated texture.
* \param matrix The texture matrix to modify.
* \param node An XML node containing dx and dy attributes to set the
* speed of the animation.
*/
MovingTexture::MovingTexture(core::matrix4 *matrix, const XMLNode &node)
: m_matrix(matrix)
{
m_dx = 0.0f;
m_dy = 0.0f;
core::vector3df v = m_matrix->getTranslation();
m_x = v.X;
m_y = v.Y;
node.get("dx", &m_dx);
node.get("dy", &m_dy);
} // MovingTexture
//-----------------------------------------------------------------------------
/** Constructor for an animated texture, specifying the speed of the animation
* directly.
* \param matrix The texture matrix to modify.
* \param dx Speed of the animation in X direction.
* \param dy Speed of the animation in Y direction.
*/
MovingTexture::MovingTexture(core::matrix4 *matrix, float dx, float dy)
: m_matrix(matrix)
{
m_dx = dx;
m_dy = dy;
core::vector3df v = m_matrix->getTranslation();
m_x = v.X;
m_y = v.Y;
} // Moving Texture
//-----------------------------------------------------------------------------
/** Destructor for an animated texture.
*/
MovingTexture::~MovingTexture()
{
} // ~MovingTexture
//-----------------------------------------------------------------------------
/** Updates the transform of an animated texture.
* \param dt Time step size.
*/
void MovingTexture::update(float dt)
{
m_x = m_x + dt*m_dx;
m_y = m_y + dt*m_dy;
if(m_x>1.0f) m_x = fmod(m_x, 1.0f);
if(m_y>1.0f) m_y = fmod(m_y, 1.0f);
m_matrix->setTextureTranslate(m_x, m_y);
} // update