~ubuntu-branches/ubuntu/precise/supertuxkart/precise

« back to all changes in this revision

Viewing changes to src/animations/animation_base.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-24 22:36:25 UTC
  • mfrom: (1.1.9 upstream) (6.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110224223625-ygrjfpg92obovuch
Tags: 0.7+dfsg1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  $Id: animation_base.cpp 1681 2008-04-09 13:52:48Z hikerstk $
 
2
//
 
3
//  SuperTuxKart - a fun racing game with go-kart
 
4
//  Copyright (C) 2009  Joerg Henrichs
 
5
//
 
6
//  This program is free software; you can redistribute it and/or
 
7
//  modify it under the terms of the GNU General Public License
 
8
//  as published by the Free Software Foundation; either version 3
 
9
//  of the License, or (at your option) any later version.
 
10
//
 
11
//  This program is distributed in the hope that it will be useful,
 
12
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
//  GNU General Public License for more details.
 
15
//
 
16
//  You should have received a copy of the GNU General Public License
 
17
//  along with this program; if not, write to the Free Software
 
18
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
#include "animations/animation_base.hpp"
 
21
 
 
22
#include "animations/ipo.hpp"
 
23
#include "graphics/irr_driver.hpp"
 
24
#include "io/file_manager.hpp"
 
25
#include "io/xml_node.hpp"
 
26
 
 
27
AnimationBase::AnimationBase(const XMLNode &node)
 
28
             : TrackObject(node)
 
29
{
 
30
    float fps=25;
 
31
    node.get("fps", &fps);
 
32
    for(unsigned int i=0; i<node.getNumNodes(); i++)
 
33
    {
 
34
        Ipo *ipo = new Ipo(*node.getNode(i), fps);
 
35
        m_all_ipos.push_back(ipo);
 
36
    }   // for i<getNumNodes()
 
37
    m_playing = true;
 
38
 
 
39
}   // AnimationBase
 
40
// ----------------------------------------------------------------------------
 
41
/** Removes all IPOs.
 
42
 */
 
43
AnimationBase::~AnimationBase()
 
44
{
 
45
    std::vector<Ipo*>::iterator i;
 
46
    for(i=m_all_ipos.begin(); i<m_all_ipos.end(); i++)
 
47
        delete *i;
 
48
    m_all_ipos.clear();
 
49
}   // ~AnimationBase
 
50
 
 
51
// ----------------------------------------------------------------------------
 
52
/** Stores the initial transform (in the IPOs actually). This is necessary
 
53
 *  for relative IPOs.
 
54
 *  \param xyz Position of the object.
 
55
 *  \param hpr Rotation of the object.
 
56
 */
 
57
void AnimationBase::setInitialTransform(const core::vector3df &xyz, 
 
58
                                        const core::vector3df &hpr)
 
59
{
 
60
    std::vector<Ipo*>::iterator i;
 
61
    for(i=m_all_ipos.begin(); i<m_all_ipos.end(); i++)
 
62
    {
 
63
        (*i)->setInitialTransform(xyz, hpr);
 
64
    }   // for i in m_all_ipos
 
65
}   // setTransform
 
66
 
 
67
// ----------------------------------------------------------------------------
 
68
/** Resets all IPOs for this animation.
 
69
 */
 
70
void AnimationBase::reset()
 
71
{
 
72
    std::vector<Ipo*>::iterator i;
 
73
    for(i=m_all_ipos.begin(); i<m_all_ipos.end(); i++)
 
74
    {
 
75
        (*i)->reset();
 
76
    }   // for i in m_all_ipos
 
77
}   // reset
 
78
 
 
79
// ----------------------------------------------------------------------------
 
80
/** Updates the time, position and rotation. Called once per framce.
 
81
 *  \param dt Time since last call.
 
82
 *  \param xyz Position to be updated.
 
83
 *  \param hpr Rotation to be updated.
 
84
 */
 
85
void AnimationBase::update(float dt, core::vector3df *xyz, 
 
86
                           core::vector3df *hpr, core::vector3df *scale)
 
87
{
 
88
    std::vector<Ipo*>::iterator i;
 
89
    for(i=m_all_ipos.begin(); i<m_all_ipos.end(); i++)
 
90
    {
 
91
        (*i)->update(dt, xyz, hpr, scale);
 
92
    }   // for i in m_all_ipos
 
93
 
 
94
}   // float dt