aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorTexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorTexture.cpp')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorTexture.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorTexture.cpp b/src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorTexture.cpp
new file mode 100644
index 0000000..1cedf3d
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CSceneNodeAnimatorTexture.cpp
@@ -0,0 +1,140 @@
1// Copyright (C) 2002-2012 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 "CSceneNodeAnimatorTexture.h"
6#include "ITexture.h"
7
8namespace irr
9{
10namespace scene
11{
12
13
14//! constructor
15CSceneNodeAnimatorTexture::CSceneNodeAnimatorTexture(const core::array<video::ITexture*>& textures,
16 s32 timePerFrame, bool loop, u32 now)
17: ISceneNodeAnimatorFinishing(0),
18 TimePerFrame(timePerFrame), StartTime(now), Loop(loop)
19{
20 #ifdef _DEBUG
21 setDebugName("CSceneNodeAnimatorTexture");
22 #endif
23
24 for (u32 i=0; i<textures.size(); ++i)
25 {
26 if (textures[i])
27 textures[i]->grab();
28
29 Textures.push_back(textures[i]);
30 }
31
32 FinishTime = now + (timePerFrame * Textures.size());
33}
34
35
36//! destructor
37CSceneNodeAnimatorTexture::~CSceneNodeAnimatorTexture()
38{
39 clearTextures();
40}
41
42
43void CSceneNodeAnimatorTexture::clearTextures()
44{
45 for (u32 i=0; i<Textures.size(); ++i)
46 if (Textures[i])
47 Textures[i]->drop();
48}
49
50
51//! animates a scene node
52void CSceneNodeAnimatorTexture::animateNode(ISceneNode* node, u32 timeMs)
53{
54 if(!node)
55 return;
56
57 if (Textures.size())
58 {
59 const u32 t = (timeMs-StartTime);
60
61 u32 idx = 0;
62 if (!Loop && timeMs >= FinishTime)
63 {
64 idx = Textures.size() - 1;
65 HasFinished = true;
66 }
67 else
68 {
69 idx = (t/TimePerFrame) % Textures.size();
70 }
71
72 if (idx < Textures.size())
73 node->setMaterialTexture(0, Textures[idx]);
74 }
75}
76
77
78//! Writes attributes of the scene node animator.
79void CSceneNodeAnimatorTexture::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
80{
81 out->addInt("TimePerFrame", TimePerFrame);
82 out->addBool("Loop", Loop);
83
84 // add one texture in addition when serializing for editors
85 // to make it easier to add textures quickly
86
87 u32 count = Textures.size();
88 if ( options && (options->Flags & io::EARWF_FOR_EDITOR))
89 count += 1;
90
91 for (u32 i=0; i<count; ++i)
92 {
93 core::stringc tname = "Texture";
94 tname += (int)(i+1);
95
96 out->addTexture(tname.c_str(), i<Textures.size() ? Textures[i] : 0);
97 }
98}
99
100
101//! Reads attributes of the scene node animator.
102void CSceneNodeAnimatorTexture::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
103{
104 TimePerFrame = in->getAttributeAsInt("TimePerFrame");
105 Loop = in->getAttributeAsBool("Loop");
106
107 clearTextures();
108
109 for(u32 i=1; true; ++i)
110 {
111 core::stringc tname = "Texture";
112 tname += (int)i;
113
114 if (in->existsAttribute(tname.c_str()))
115 {
116 video::ITexture* tex = in->getAttributeAsTexture(tname.c_str());
117 if (tex)
118 {
119 tex->grab();
120 Textures.push_back(tex);
121 }
122 }
123 else
124 break;
125 }
126}
127
128
129ISceneNodeAnimator* CSceneNodeAnimatorTexture::createClone(ISceneNode* node, ISceneManager* newManager)
130{
131 CSceneNodeAnimatorTexture * newAnimator =
132 new CSceneNodeAnimatorTexture(Textures, TimePerFrame, Loop, StartTime);
133
134 return newAnimator;
135}
136
137
138} // end namespace scene
139} // end namespace irr
140