~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to source/Irrlicht/CSceneNodeAnimatorFlyStraight.cpp

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
 
2
// This file is part of the "Irrlicht Engine".
 
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
 
4
 
 
5
#include "CSceneNodeAnimatorFlyStraight.h"
 
6
 
 
7
namespace irr
 
8
{
 
9
namespace scene
 
10
{
 
11
 
 
12
 
 
13
//! constructor
 
14
CSceneNodeAnimatorFlyStraight::CSceneNodeAnimatorFlyStraight(const core::vector3df& startPoint,
 
15
                                const core::vector3df& endPoint, u32 timeForWay,
 
16
                                bool loop, u32 now, bool pingpong)
 
17
: ISceneNodeAnimatorFinishing(now + timeForWay),
 
18
        Start(startPoint), End(endPoint), TimeFactor(0.0f), StartTime(now),
 
19
        TimeForWay(timeForWay), Loop(loop), PingPong(pingpong)
 
20
{
 
21
        #ifdef _DEBUG
 
22
        setDebugName("CSceneNodeAnimatorFlyStraight");
 
23
        #endif
 
24
 
 
25
        recalculateIntermediateValues();
 
26
}
 
27
 
 
28
 
 
29
void CSceneNodeAnimatorFlyStraight::recalculateIntermediateValues()
 
30
{
 
31
        Vector = End - Start;
 
32
        TimeFactor = (f32)Vector.getLength() / TimeForWay;
 
33
        Vector.normalize();
 
34
}
 
35
 
 
36
 
 
37
//! animates a scene node
 
38
void CSceneNodeAnimatorFlyStraight::animateNode(ISceneNode* node, u32 timeMs)
 
39
{
 
40
        if (!node)
 
41
                return;
 
42
 
 
43
        u32 t = (timeMs-StartTime);
 
44
 
 
45
        core::vector3df pos;
 
46
 
 
47
        if (!Loop && !PingPong && t >= TimeForWay)
 
48
        {
 
49
                pos = End;
 
50
                HasFinished = true;
 
51
        }
 
52
        else if (!Loop && PingPong && t >= TimeForWay * 2.f )
 
53
        {
 
54
                pos = Start;
 
55
                HasFinished = true;
 
56
        }
 
57
        else
 
58
        {
 
59
                f32 phase = fmodf( (f32) t, (f32) TimeForWay );
 
60
                core::vector3df rel = Vector * phase * TimeFactor;
 
61
                const bool pong = PingPong && fmodf( (f32) t, (f32) TimeForWay*2.f ) >= TimeForWay;
 
62
 
 
63
                if ( !pong )
 
64
                {
 
65
                        pos += Start + rel;
 
66
                }
 
67
                else
 
68
                {
 
69
                        pos = End - rel;
 
70
                }
 
71
        }
 
72
 
 
73
        node->setPosition(pos);
 
74
}
 
75
 
 
76
 
 
77
//! Writes attributes of the scene node animator.
 
78
void CSceneNodeAnimatorFlyStraight::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
 
79
{
 
80
        out->addVector3d("Start", Start);
 
81
        out->addVector3d("End", End);
 
82
        out->addInt("TimeForWay", TimeForWay);
 
83
        out->addBool("Loop", Loop);
 
84
        out->addBool("PingPong", PingPong);
 
85
}
 
86
 
 
87
 
 
88
//! Reads attributes of the scene node animator.
 
89
void CSceneNodeAnimatorFlyStraight::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
 
90
{
 
91
        Start = in->getAttributeAsVector3d("Start");
 
92
        End = in->getAttributeAsVector3d("End");
 
93
        TimeForWay = in->getAttributeAsInt("TimeForWay");
 
94
        Loop = in->getAttributeAsBool("Loop");
 
95
        PingPong = in->getAttributeAsBool("PingPong");
 
96
 
 
97
        recalculateIntermediateValues();
 
98
}
 
99
 
 
100
 
 
101
ISceneNodeAnimator* CSceneNodeAnimatorFlyStraight::createClone(ISceneNode* node, ISceneManager* newManager)
 
102
{
 
103
        CSceneNodeAnimatorFlyStraight * newAnimator =
 
104
                new CSceneNodeAnimatorFlyStraight(Start, End, TimeForWay, Loop, StartTime, PingPong);
 
105
 
 
106
        return newAnimator;
 
107
}
 
108
 
 
109
 
 
110
} // end namespace scene
 
111
} // end namespace irr
 
112