Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SCENE_SCENENODE_H__
00009 #define __SP_SCENE_SCENENODE_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spDimension.hpp"
00014 #include "Base/spInputOutputLog.hpp"
00015 #include "Base/spMaterialStates.hpp"
00016 #include "Base/spGeometryStructures.hpp"
00017 #include "Base/spNode.hpp"
00018 #include "Base/spMath.hpp"
00019 #include "Base/spTransformation3D.hpp"
00020 #include "SceneGraph/spBoundingVolume.hpp"
00021 #include "RenderSystem/spShaderProgram.hpp"
00022
00023 #include <list>
00024
00025
00026 namespace sp
00027 {
00028 namespace scene
00029 {
00030
00031
00032 class Animation;
00033
00034
00035
00036
00037
00039 extern dim::matrix4f spProjectionMatrix;
00040 extern dim::matrix4f spViewMatrix;
00041 extern dim::matrix4f spViewInvMatrix;
00042 extern dim::matrix4f spWorldMatrix;
00043 extern dim::matrix4f spTextureMatrix[MAX_COUNT_OF_TEXTURES];
00044 extern dim::matrix4f spColorMatrix;
00045
00046
00047
00048
00049
00050
00052 enum ENodeTypes
00053 {
00054 NODE_BASICNODE,
00055 NODE_CUSTOM,
00056 NODE_SCENEGRAPH,
00057 NODE_CAMERA,
00058 NODE_LIGHT,
00059 NODE_MESH,
00060 NODE_BILLBOARD,
00061 NODE_TERRAIN,
00062 };
00063
00064
00070 class SP_EXPORT SceneNode : public Node
00071 {
00072
00073 public:
00074
00075
00076
00077 SceneNode(const ENodeTypes Type = NODE_BASICNODE);
00078 virtual ~SceneNode();
00079
00080
00081
00082 SceneNode* copy() const;
00083
00090 void setPositionMatrix(const dim::matrix4f &Position, bool isGlobal);
00091 dim::matrix4f getPositionMatrix(bool isGlobal) const;
00092
00093 void setRotationMatrix(const dim::matrix4f &Rotation, bool isGlobal);
00094 dim::matrix4f getRotationMatrix(bool isGlobal) const;
00095
00096 void setScaleMatrix(const dim::matrix4f &Scale, bool isGlobal);
00097 dim::matrix4f getScaleMatrix(bool isGlobal) const;
00098
00099 void setPosition(const dim::vector3df &Position, bool isGlobal = false);
00100 dim::vector3df getPosition(bool isGlobal = false) const;
00101
00108 void setRotation(const dim::vector3df &Rotation, bool isGlobal = false);
00109 dim::vector3df getRotation(bool isGlobal = false) const;
00110
00111 void setScale(const dim::vector3df &Scale, bool isGlobal = false);
00112 dim::vector3df getScale(bool isGlobal = false) const;
00113
00114 virtual void lookAt(const dim::vector3df &Position, bool isGlobal = false);
00115
00121 virtual void addAnimation(Animation* Anim);
00122
00124 virtual void removeAnimation(Animation* Anim);
00125
00127 virtual void clearAnimations();
00128
00130 virtual Animation* getFirstAnimation() const;
00131
00133 virtual Animation* getAnimation(u32 Index = 0) const;
00134
00136 virtual Animation* findAnimation(const io::stringc &Name) const;
00137
00138
00139
00144 virtual bool getVisible(bool isGlobal = false) const;
00145
00156 void setParent(SceneNode* Parent, bool isGlobal);
00157
00158
00159
00161 virtual void addChild(SceneNode* Child);
00162
00164 virtual void addChildren(const std::list<SceneNode*> &Children);
00165
00167 virtual bool removeChild(SceneNode* Child);
00168
00170 virtual bool removeChild();
00171
00173 virtual u32 removeChildren(const std::list<SceneNode*> &Children);
00174
00176 virtual void removeChildren();
00177
00178
00179
00181 virtual void updateTransformation();
00182 virtual void updateTransformationBase(const dim::matrix4f &BaseMatrix);
00183
00184 Transformation getTransformation(bool isGlobal) const;
00185
00187 virtual void loadTransformation();
00188
00189
00190
00192 inline ENodeTypes getType() const
00193 {
00194 return Type_;
00195 }
00196
00197 inline void setBoundingVolume(const BoundingVolume &BoundVolume)
00198 {
00199 BoundVolume_ = BoundVolume;
00200 }
00201
00202 inline BoundingVolume& getBoundingVolume()
00203 {
00204 return BoundVolume_;
00205 }
00206 inline const BoundingVolume& getBoundingVolume() const
00207 {
00208 return BoundVolume_;
00209 }
00210
00211 inline void setPositionMatrix(const dim::matrix4f &Position)
00212 {
00213 Transform_.setPosition(Position.getPosition());
00214 }
00215 inline dim::matrix4f getPositionMatrix() const
00216 {
00217 return dim::getPositionMatrix(Transform_.getPosition());
00218 }
00219
00220 inline void setRotationMatrix(const dim::matrix4f &Rotation)
00221 {
00222 Transform_.setRotation(Rotation);
00223 }
00224 inline dim::matrix4f getRotationMatrix() const
00225 {
00226 return Transform_.getRotationMatrix();
00227 }
00228
00229 inline void setScaleMatrix(const dim::matrix4f &Scale)
00230 {
00231 Transform_.setScale(Scale.getScale());
00232 }
00233 inline dim::matrix4f getScaleMatrix() const
00234 {
00235 return dim::getScaleMatrix(Transform_.getScale());
00236 }
00237
00239 inline void setupTransformation(bool isGlobal)
00240 {
00241 FinalWorldMatrix_ = getTransformation(isGlobal).getMatrix();
00242 }
00244 inline void setupWorldMatrix(const dim::matrix4f &WorldMatrix)
00245 {
00246 FinalWorldMatrix_ = WorldMatrix;
00247 }
00248
00249 inline const Transformation& getTransformation() const
00250 {
00251 return Transform_;
00252 }
00253 inline Transformation& getTransformation()
00254 {
00255 return Transform_;
00256 }
00257
00258 inline dim::matrix4f getTransformMatrix(bool isGlobal = false) const
00259 {
00260 return getTransformation(isGlobal).getMatrix();
00261 }
00262
00263 inline void setTransformation(const Transformation &Transform)
00264 {
00265 Transform_ = Transform;
00266 }
00267
00269 inline const std::vector<SceneNode*> &getSceneChildren() const
00270 {
00271 return SceneChildren_;
00272 }
00273 inline std::vector<SceneNode*> &getSceneChildren()
00274 {
00275 return SceneChildren_;
00276 }
00277
00279 inline void setParent(SceneNode* Parent)
00280 {
00281 SceneParent_ = Parent;
00282 }
00283 inline SceneNode* getParent() const
00284 {
00285 return SceneParent_;
00286 }
00287
00289 inline const std::vector<Animation*>& getAnimationList() const
00290 {
00291 return AnimationList_;
00292 }
00293
00295 inline u32 getAnimationCount() const
00296 {
00297 return AnimationList_.size();
00298 }
00299
00301 inline void move(const dim::vector3df &Direction)
00302 {
00303 Transform_.move(Direction);
00304 }
00306 inline void turn(const dim::vector3df &Rotation)
00307 {
00308 Transform_.turn(Rotation);
00309 }
00311 inline void translate(const dim::vector3df &Direction)
00312 {
00313 Transform_.translate(Direction);
00314 }
00316 inline void transform(const dim::vector3df &Size)
00317 {
00318 Transform_.transform(Size);
00319 }
00320
00321 protected:
00322
00323 friend class Animation;
00324
00325
00326
00327 void copyRoot(SceneNode* NewNode) const;
00328
00329
00330
00331 BoundingVolume BoundVolume_;
00332 Transformation Transform_;
00333
00334 dim::matrix4f FinalWorldMatrix_;
00335
00336 SceneNode* SceneParent_;
00337
00338 std::vector<SceneNode*> SceneChildren_;
00339
00340 std::vector<Animation*> AnimationList_;
00341
00342 private:
00343
00344
00345
00346 ENodeTypes Type_;
00347
00348 };
00349
00350
00351 }
00352
00353 }
00354
00355
00356 #endif
00357
00358
00359
00360