]> git.lizzy.rs Git - irrlicht.git/blob - include/SAnimatedMesh.h
Use non-static member vars for SDL clipboard / primary selection buffers
[irrlicht.git] / include / SAnimatedMesh.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __S_ANIMATED_MESH_H_INCLUDED__\r
6 #define __S_ANIMATED_MESH_H_INCLUDED__\r
7 \r
8 #include "IAnimatedMesh.h"\r
9 #include "IMesh.h"\r
10 #include "aabbox3d.h"\r
11 #include "irrArray.h"\r
12 \r
13 namespace irr\r
14 {\r
15 namespace scene\r
16 {\r
17 \r
18         //! Simple implementation of the IAnimatedMesh interface.\r
19         struct SAnimatedMesh : public IAnimatedMesh\r
20         {\r
21                 //! constructor\r
22                 SAnimatedMesh(scene::IMesh* mesh=0, scene::E_ANIMATED_MESH_TYPE type=scene::EAMT_UNKNOWN) : IAnimatedMesh(), FramesPerSecond(25.f), Type(type)\r
23                 {\r
24                         #ifdef _DEBUG\r
25                         setDebugName("SAnimatedMesh");\r
26                         #endif\r
27                         addMesh(mesh);\r
28                         recalculateBoundingBox();\r
29                 }\r
30 \r
31                 //! destructor\r
32                 virtual ~SAnimatedMesh()\r
33                 {\r
34                         // drop meshes\r
35                         for (u32 i=0; i<Meshes.size(); ++i)\r
36                                 Meshes[i]->drop();\r
37                 }\r
38 \r
39                 //! Gets the frame count of the animated mesh.\r
40                 /** \return Amount of frames. If the amount is 1, it is a static, non animated mesh. */\r
41                 u32 getFrameCount() const override\r
42                 {\r
43                         return Meshes.size();\r
44                 }\r
45 \r
46                 //! Gets the default animation speed of the animated mesh.\r
47                 /** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */\r
48                 f32 getAnimationSpeed() const override\r
49                 {\r
50                         return FramesPerSecond;\r
51                 }\r
52 \r
53                 //! Gets the frame count of the animated mesh.\r
54                 /** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.\r
55                 The actual speed is set in the scene node the mesh is instantiated in.*/\r
56                 void setAnimationSpeed(f32 fps) override\r
57                 {\r
58                         FramesPerSecond=fps;\r
59                 }\r
60 \r
61                 //! Returns the IMesh interface for a frame.\r
62                 /** \param frame: Frame number as zero based index. The maximum frame number is\r
63                 getFrameCount() - 1;\r
64                 \param detailLevel: Level of detail. 0 is the lowest,\r
65                 255 the highest level of detail. Most meshes will ignore the detail level.\r
66                 \param startFrameLoop: start frame\r
67                 \param endFrameLoop: end frame\r
68                 \return The animated mesh based on a detail level. */\r
69                 IMesh* getMesh(s32 frame, s32 detailLevel=255, s32 startFrameLoop=-1, s32 endFrameLoop=-1) override\r
70                 {\r
71                         if (Meshes.empty())\r
72                                 return 0;\r
73 \r
74                         return Meshes[frame];\r
75                 }\r
76 \r
77                 //! adds a Mesh\r
78                 void addMesh(IMesh* mesh)\r
79                 {\r
80                         if (mesh)\r
81                         {\r
82                                 mesh->grab();\r
83                                 Meshes.push_back(mesh);\r
84                         }\r
85                 }\r
86 \r
87                 //! Returns an axis aligned bounding box of the mesh.\r
88                 /** \return A bounding box of this mesh is returned. */\r
89                 const core::aabbox3d<f32>& getBoundingBox() const override\r
90                 {\r
91                         return Box;\r
92                 }\r
93 \r
94                 //! set user axis aligned bounding box\r
95                 void setBoundingBox(const core::aabbox3df& box) override\r
96                 {\r
97                         Box = box;\r
98                 }\r
99 \r
100                 //! Recalculates the bounding box.\r
101                 void recalculateBoundingBox()\r
102                 {\r
103                         Box.reset(0,0,0);\r
104 \r
105                         if (Meshes.empty())\r
106                                 return;\r
107 \r
108                         Box = Meshes[0]->getBoundingBox();\r
109 \r
110                         for (u32 i=1; i<Meshes.size(); ++i)\r
111                                 Box.addInternalBox(Meshes[i]->getBoundingBox());\r
112                 }\r
113 \r
114                 //! Returns the type of the animated mesh.\r
115                 E_ANIMATED_MESH_TYPE getMeshType() const override\r
116                 {\r
117                         return Type;\r
118                 }\r
119 \r
120                 //! returns amount of mesh buffers.\r
121                 u32 getMeshBufferCount() const override\r
122                 {\r
123                         if (Meshes.empty())\r
124                                 return 0;\r
125 \r
126                         return Meshes[0]->getMeshBufferCount();\r
127                 }\r
128 \r
129                 //! returns pointer to a mesh buffer\r
130                 IMeshBuffer* getMeshBuffer(u32 nr) const override\r
131                 {\r
132                         if (Meshes.empty())\r
133                                 return 0;\r
134 \r
135                         return Meshes[0]->getMeshBuffer(nr);\r
136                 }\r
137 \r
138                 //! Returns pointer to a mesh buffer which fits a material\r
139                 /** \param material: material to search for\r
140                 \return Returns the pointer to the mesh buffer or\r
141                 NULL if there is no such mesh buffer. */\r
142                 IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const override\r
143                 {\r
144                         if (Meshes.empty())\r
145                                 return 0;\r
146 \r
147                         return Meshes[0]->getMeshBuffer(material);\r
148                 }\r
149 \r
150                 //! Set a material flag for all meshbuffers of this mesh.\r
151                 void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) override\r
152                 {\r
153                         for (u32 i=0; i<Meshes.size(); ++i)\r
154                                 Meshes[i]->setMaterialFlag(flag, newvalue);\r
155                 }\r
156 \r
157                 //! set the hardware mapping hint, for driver\r
158                 void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) override\r
159                 {\r
160                         for (u32 i=0; i<Meshes.size(); ++i)\r
161                                 Meshes[i]->setHardwareMappingHint(newMappingHint, buffer);\r
162                 }\r
163 \r
164                 //! flags the meshbuffer as changed, reloads hardware buffers\r
165                 void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override\r
166                 {\r
167                         for (u32 i=0; i<Meshes.size(); ++i)\r
168                                 Meshes[i]->setDirty(buffer);\r
169                 }\r
170 \r
171                 //! All meshes defining the animated mesh\r
172                 core::array<IMesh*> Meshes;\r
173 \r
174                 //! The bounding box of this mesh\r
175                 core::aabbox3d<f32> Box;\r
176 \r
177                 //! Default animation speed of this mesh.\r
178                 f32 FramesPerSecond;\r
179 \r
180                 //! The type of the mesh.\r
181                 E_ANIMATED_MESH_TYPE Type;\r
182         };\r
183 \r
184 \r
185 } // end namespace scene\r
186 } // end namespace irr\r
187 \r
188 #endif\r
189 \r