Annotation of /libs/Irrlicht SDK/include/ISceneNode.h
Parent Directory
|
Revision Log
Revision 3 - (view) (download)
| 1 : | teravus | 3 | // Copyright (C) 2002-2007 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 : | #ifndef __I_SCENE_NODE_H_INCLUDED__ | ||
| 6 : | #define __I_SCENE_NODE_H_INCLUDED__ | ||
| 7 : | |||
| 8 : | #include "IUnknown.h" | ||
| 9 : | #include "ESceneNodeTypes.h" | ||
| 10 : | #include "ECullingTypes.h" | ||
| 11 : | #include "EDebugSceneTypes.h" | ||
| 12 : | #include "ISceneManager.h" | ||
| 13 : | #include "ISceneNodeAnimator.h" | ||
| 14 : | #include "ITriangleSelector.h" | ||
| 15 : | #include "SMaterial.h" | ||
| 16 : | #include "irrString.h" | ||
| 17 : | #include "aabbox3d.h" | ||
| 18 : | #include "matrix4.h" | ||
| 19 : | #include "irrList.h" | ||
| 20 : | #include "IAttributes.h" | ||
| 21 : | #include "IAttributeExchangingObject.h" | ||
| 22 : | |||
| 23 : | namespace irr | ||
| 24 : | { | ||
| 25 : | namespace scene | ||
| 26 : | { | ||
| 27 : | //! Scene node interface. | ||
| 28 : | /** A scene node is a node in the hirachical scene graph. Every scene node may have children, | ||
| 29 : | which are other scene nodes. Children move relative the their parents position. If the parent of a node is not | ||
| 30 : | visible, its children won't be visible too. In this way, it is for example easily possible | ||
| 31 : | to attach a light to a moving car, or to place a walking character on a moving platform | ||
| 32 : | on a moving ship. */ | ||
| 33 : | class ISceneNode : public io::IAttributeExchangingObject | ||
| 34 : | { | ||
| 35 : | public: | ||
| 36 : | |||
| 37 : | //! Constructor | ||
| 38 : | ISceneNode( ISceneNode* parent, ISceneManager* mgr, s32 id=-1, | ||
| 39 : | const core::vector3df& position = core::vector3df(0,0,0), | ||
| 40 : | const core::vector3df& rotation = core::vector3df(0,0,0), | ||
| 41 : | const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f)) | ||
| 42 : | : RelativeTranslation(position), RelativeRotation(rotation), RelativeScale(scale), | ||
| 43 : | Parent(parent), ID(id), SceneManager(mgr), TriangleSelector(0), | ||
| 44 : | AutomaticCullingState(EAC_BOX), IsVisible(true), | ||
| 45 : | DebugDataVisible(EDS_OFF), IsDebugObject(false) | ||
| 46 : | { | ||
| 47 : | if (Parent) | ||
| 48 : | Parent->addChild(this); | ||
| 49 : | |||
| 50 : | updateAbsolutePosition(); | ||
| 51 : | } | ||
| 52 : | |||
| 53 : | |||
| 54 : | |||
| 55 : | //! Destructor | ||
| 56 : | virtual ~ISceneNode() | ||
| 57 : | { | ||
| 58 : | // delete all children | ||
| 59 : | removeAll(); | ||
| 60 : | |||
| 61 : | // delete all animators | ||
| 62 : | core::list<ISceneNodeAnimator*>::Iterator ait = Animators.begin(); | ||
| 63 : | for (; ait != Animators.end(); ++ait) | ||
| 64 : | (*ait)->drop(); | ||
| 65 : | |||
| 66 : | if (TriangleSelector) | ||
| 67 : | TriangleSelector->drop(); | ||
| 68 : | } | ||
| 69 : | |||
| 70 : | |||
| 71 : | //! This method is called just before the rendering process of the whole scene. | ||
| 72 : | /** Nodes may register themselves in the render pipeline during this call, | ||
| 73 : | precalculate the geometry which should be renderered, and prevent their | ||
| 74 : | children from being able to register them selfes if they are clipped by simply | ||
| 75 : | not calling their OnRegisterSceneNode-Method. | ||
| 76 : | If you are implementing your own scene node, you should overwrite this method | ||
| 77 : | with an implementtion code looking like this: | ||
| 78 : | \code | ||
| 79 : | if (IsVisible) | ||
| 80 : | SceneManager->registerNodeForRendering(this); | ||
| 81 : | |||
| 82 : | ISceneNode::OnRegisterSceneNode(); | ||
| 83 : | \endcode | ||
| 84 : | */ | ||
| 85 : | virtual void OnRegisterSceneNode() | ||
| 86 : | { | ||
| 87 : | if (IsVisible) | ||
| 88 : | { | ||
| 89 : | core::list<ISceneNode*>::Iterator it = Children.begin(); | ||
| 90 : | for (; it != Children.end(); ++it) | ||
| 91 : | (*it)->OnRegisterSceneNode(); | ||
| 92 : | } | ||
| 93 : | } | ||
| 94 : | |||
| 95 : | |||
| 96 : | //! OnAnimate() is called just before rendering the whole scene. | ||
| 97 : | //! Nodes may calculate or store animations here, and may do other useful things, | ||
| 98 : | //! dependent on what they are. Also, OnAnimate() should be called for all | ||
| 99 : | //! child scene nodes here. This method will called once per frame, independent | ||
| 100 : | //! of if the scene node is visible or not. | ||
| 101 : | //! \param timeMs: Current time in milli seconds. | ||
| 102 : | virtual void OnAnimate(u32 timeMs) | ||
| 103 : | { | ||
| 104 : | if (IsVisible) | ||
| 105 : | { | ||
| 106 : | // animate this node with all animators | ||
| 107 : | |||
| 108 : | core::list<ISceneNodeAnimator*>::Iterator ait = Animators.begin(); | ||
| 109 : | for (; ait != Animators.end(); ++ait) | ||
| 110 : | (*ait)->animateNode(this, timeMs); | ||
| 111 : | |||
| 112 : | // update absolute position | ||
| 113 : | updateAbsolutePosition(); | ||
| 114 : | |||
| 115 : | // perform the post render process on all children | ||
| 116 : | |||
| 117 : | core::list<ISceneNode*>::Iterator it = Children.begin(); | ||
| 118 : | for (; it != Children.end(); ++it) | ||
| 119 : | (*it)->OnAnimate(timeMs); | ||
| 120 : | } | ||
| 121 : | } | ||
| 122 : | |||
| 123 : | |||
| 124 : | //! Renders the node. | ||
| 125 : | virtual void render() = 0; | ||
| 126 : | |||
| 127 : | |||
| 128 : | //! Returns the name of the node. | ||
| 129 : | //! \return Returns name as wide character string. | ||
| 130 : | virtual const c8* getName() const | ||
| 131 : | { | ||
| 132 : | return Name.c_str(); | ||
| 133 : | } | ||
| 134 : | |||
| 135 : | |||
| 136 : | //! Sets the name of the node. | ||
| 137 : | //! \param name: New name of the scene node. | ||
| 138 : | virtual void setName(const c8* name) | ||
| 139 : | { | ||
| 140 : | Name = name; | ||
| 141 : | } | ||
| 142 : | |||
| 143 : | |||
| 144 : | //! Returns the axis aligned, not transformed bounding box of this node. | ||
| 145 : | //! This means that if this node is a animated 3d character, moving in a room, | ||
| 146 : | //! the bounding box will always be around the origin. To get the box in | ||
| 147 : | //! real world coordinates, just transform it with the matrix you receive with | ||
| 148 : | //! getAbsoluteTransformation() or simply use getTransformedBoundingBox(), | ||
| 149 : | //! which does the same. | ||
| 150 : | virtual const core::aabbox3d<f32>& getBoundingBox() const = 0; | ||
| 151 : | |||
| 152 : | |||
| 153 : | //! Returns the axis aligned, transformed and animated absolute bounding box | ||
| 154 : | //! of this node. | ||
| 155 : | virtual const core::aabbox3d<f32> getTransformedBoundingBox() const | ||
| 156 : | { | ||
| 157 : | core::aabbox3d<f32> box = getBoundingBox(); | ||
| 158 : | AbsoluteTransformation.transformBox(box); | ||
| 159 : | return box; | ||
| 160 : | } | ||
| 161 : | |||
| 162 : | |||
| 163 : | //! returns the absolute transformation of the node. Is recalculated every OnAnimate()-call. | ||
| 164 : | const core::matrix4& getAbsoluteTransformation() const | ||
| 165 : | { | ||
| 166 : | return AbsoluteTransformation; | ||
| 167 : | } | ||
| 168 : | |||
| 169 : | |||
| 170 : | //! Returns the relative transformation of the scene node. | ||
| 171 : | //! The relative transformation is stored internally as 3 vectors: | ||
| 172 : | //! translation, rotation and scale. To get the relative transformation | ||
| 173 : | //! matrix, it is calculated from these values. | ||
| 174 : | //! \return Returns the relative transformation matrix. | ||
| 175 : | virtual core::matrix4 getRelativeTransformation() const | ||
| 176 : | { | ||
| 177 : | core::matrix4 mat; | ||
| 178 : | mat.setRotationDegrees(RelativeRotation); | ||
| 179 : | mat.setTranslation(RelativeTranslation); | ||
| 180 : | |||
| 181 : | if (RelativeScale != core::vector3df(1,1,1)) | ||
| 182 : | { | ||
| 183 : | core::matrix4 smat; | ||
| 184 : | smat.setScale(RelativeScale); | ||
| 185 : | mat *= smat; | ||
| 186 : | } | ||
| 187 : | |||
| 188 : | return mat; | ||
| 189 : | } | ||
| 190 : | |||
| 191 : | |||
| 192 : | //! Returns true if the node is visible. This is only an option, set by the user and has | ||
| 193 : | //! nothing to do with geometry culling | ||
| 194 : | virtual bool isVisible() const | ||
| 195 : | { | ||
| 196 : | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
| 197 : | return IsVisible; | ||
| 198 : | } | ||
| 199 : | |||
| 200 : | |||
| 201 : | //! Sets if the node should be visible or not. All children of this node won't be visible too. | ||
| 202 : | virtual void setVisible(bool isVisible) | ||
| 203 : | { | ||
| 204 : | IsVisible = isVisible; | ||
| 205 : | } | ||
| 206 : | |||
| 207 : | |||
| 208 : | //! Returns the id of the scene node. This id can be used to identify the node. | ||
| 209 : | virtual s32 getID() const | ||
| 210 : | { | ||
| 211 : | return ID; | ||
| 212 : | } | ||
| 213 : | |||
| 214 : | |||
| 215 : | //! sets the id of the scene node. This id can be used to identify the node. | ||
| 216 : | virtual void setID(s32 id) | ||
| 217 : | { | ||
| 218 : | ID = id; | ||
| 219 : | } | ||
| 220 : | |||
| 221 : | |||
| 222 : | //! Adds a child to this scene node. If the scene node already | ||
| 223 : | //! has got a parent, it is removed from there as child. | ||
| 224 : | virtual void addChild(ISceneNode* child) | ||
| 225 : | { | ||
| 226 : | if (child) | ||
| 227 : | { | ||
| 228 : | child->grab(); | ||
| 229 : | child->remove(); // remove from old parent | ||
| 230 : | Children.push_back(child); | ||
| 231 : | child->Parent = this; | ||
| 232 : | } | ||
| 233 : | } | ||
| 234 : | |||
| 235 : | |||
| 236 : | //! Removes a child from this scene node. | ||
| 237 : | //! \return Returns true if the child could be removed, and false if not. | ||
| 238 : | virtual bool removeChild(ISceneNode* child) | ||
| 239 : | { | ||
| 240 : | core::list<ISceneNode*>::Iterator it = Children.begin(); | ||
| 241 : | for (; it != Children.end(); ++it) | ||
| 242 : | if ((*it) == child) | ||
| 243 : | { | ||
| 244 : | (*it)->Parent = 0; | ||
| 245 : | (*it)->drop(); | ||
| 246 : | Children.erase(it); | ||
| 247 : | return true; | ||
| 248 : | } | ||
| 249 : | |||
| 250 : | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
| 251 : | return false; | ||
| 252 : | } | ||
| 253 : | |||
| 254 : | |||
| 255 : | //! Removes all children of this scene node | ||
| 256 : | virtual void removeAll() | ||
| 257 : | { | ||
| 258 : | core::list<ISceneNode*>::Iterator it = Children.begin(); | ||
| 259 : | for (; it != Children.end(); ++it) | ||
| 260 : | { | ||
| 261 : | (*it)->Parent = 0; | ||
| 262 : | (*it)->drop(); | ||
| 263 : | } | ||
| 264 : | |||
| 265 : | Children.clear(); | ||
| 266 : | } | ||
| 267 : | |||
| 268 : | |||
| 269 : | //! Removes this scene node from the scene, deleting it. | ||
| 270 : | virtual void remove() | ||
| 271 : | { | ||
| 272 : | if (Parent) | ||
| 273 : | Parent->removeChild(this); | ||
| 274 : | } | ||
| 275 : | |||
| 276 : | |||
| 277 : | //! Adds an animator which should animate this node. | ||
| 278 : | virtual void addAnimator(ISceneNodeAnimator* animator) | ||
| 279 : | { | ||
| 280 : | if (animator) | ||
| 281 : | { | ||
| 282 : | Animators.push_back(animator); | ||
| 283 : | animator->grab(); | ||
| 284 : | } | ||
| 285 : | } | ||
| 286 : | |||
| 287 : | |||
| 288 : | //! Returns a const reference to the list of all scene node animators. | ||
| 289 : | const core::list<ISceneNodeAnimator*>& getAnimators() const | ||
| 290 : | { | ||
| 291 : | return Animators; | ||
| 292 : | } | ||
| 293 : | |||
| 294 : | |||
| 295 : | //! Removes an animator from this scene node. | ||
| 296 : | virtual void removeAnimator(ISceneNodeAnimator* animator) | ||
| 297 : | { | ||
| 298 : | core::list<ISceneNodeAnimator*>::Iterator it = Animators.begin(); | ||
| 299 : | for (; it != Animators.end(); ++it) | ||
| 300 : | if ((*it) == animator) | ||
| 301 : | { | ||
| 302 : | (*it)->drop(); | ||
| 303 : | Animators.erase(it); | ||
| 304 : | return; | ||
| 305 : | } | ||
| 306 : | } | ||
| 307 : | |||
| 308 : | |||
| 309 : | //! Removes all animators from this scene node. | ||
| 310 : | virtual void removeAnimators() | ||
| 311 : | { | ||
| 312 : | core::list<ISceneNodeAnimator*>::Iterator it = Animators.begin(); | ||
| 313 : | for (; it != Animators.end(); ++it) | ||
| 314 : | (*it)->drop(); | ||
| 315 : | |||
| 316 : | Animators.clear(); | ||
| 317 : | } | ||
| 318 : | |||
| 319 : | |||
| 320 : | //! Returns the material based on the zero based index i. To get the amount | ||
| 321 : | //! of materials used by this scene node, use getMaterialCount(). | ||
| 322 : | //! This function is needed for inserting the node into the scene hirachy on a | ||
| 323 : | //! optimal position for minimizing renderstate changes, but can also be used | ||
| 324 : | //! to directly modify the material of a scene node. | ||
| 325 : | //! \param num: Zero based index. The maximal value is getMaterialCount() - 1. | ||
| 326 : | //! \return Returns the material of that index. | ||
| 327 : | virtual video::SMaterial& getMaterial(u32 num) | ||
| 328 : | { | ||
| 329 : | return *((video::SMaterial*)0); | ||
| 330 : | } | ||
| 331 : | |||
| 332 : | |||
| 333 : | //! Returns amount of materials used by this scene node. | ||
| 334 : | //! \return Returns current count of materials used by this scene node. | ||
| 335 : | virtual u32 getMaterialCount() | ||
| 336 : | { | ||
| 337 : | return 0; | ||
| 338 : | } | ||
| 339 : | |||
| 340 : | |||
| 341 : | //! Sets all material flags at once to a new value. Helpful for | ||
| 342 : | //! example, if you want to be the the whole mesh to be lighted by | ||
| 343 : | //! \param flag: Which flag of all materials to be set. | ||
| 344 : | //! \param newvalue: New value of the flag. | ||
| 345 : | void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue) | ||
| 346 : | { | ||
| 347 : | for (u32 i=0; i<getMaterialCount(); ++i) | ||
| 348 : | getMaterial(i).setFlag(flag, newvalue); | ||
| 349 : | } | ||
| 350 : | |||
| 351 : | |||
| 352 : | //! Sets the texture of the specified layer in all materials of this | ||
| 353 : | //! scene node to the new texture. | ||
| 354 : | //! \param textureLayer: Layer of texture to be set. Must be a value greater or | ||
| 355 : | //! equal than 0 and smaller than MATERIAL_MAX_TEXTURES. | ||
| 356 : | //! \param texture: Texture to be used. | ||
| 357 : | void setMaterialTexture(u32 textureLayer, video::ITexture* texture) | ||
| 358 : | { | ||
| 359 : | if (textureLayer>= video::MATERIAL_MAX_TEXTURES) | ||
| 360 : | return; | ||
| 361 : | |||
| 362 : | for (u32 i=0; i<getMaterialCount(); ++i) | ||
| 363 : | getMaterial(i).Textures[textureLayer] = texture; | ||
| 364 : | } | ||
| 365 : | |||
| 366 : | |||
| 367 : | //! Sets the material type of all materials s32 this scene node | ||
| 368 : | //! to a new material type. | ||
| 369 : | //! \param newType: New type of material to be set. | ||
| 370 : | void setMaterialType(video::E_MATERIAL_TYPE newType) | ||
| 371 : | { | ||
| 372 : | for (u32 i=0; i<getMaterialCount(); ++i) | ||
| 373 : | getMaterial(i).MaterialType = newType; | ||
| 374 : | } | ||
| 375 : | |||
| 376 : | |||
| 377 : | //! Gets the scale of the scene node. | ||
| 378 : | /** \return Returns the scale of the scene node. */ | ||
| 379 : | virtual core::vector3df getScale() const | ||
| 380 : | { | ||
| 381 : | return RelativeScale; | ||
| 382 : | } | ||
| 383 : | |||
| 384 : | |||
| 385 : | //! Sets the scale of the scene node. | ||
| 386 : | /** \param scale: New scale of the node */ | ||
| 387 : | virtual void setScale(const core::vector3df& scale) | ||
| 388 : | { | ||
| 389 : | RelativeScale = scale; | ||
| 390 : | } | ||
| 391 : | |||
| 392 : | |||
| 393 : | //! Gets the rotation of the node. | ||
| 394 : | /** Note that this is the relative rotation of the node. | ||
| 395 : | \return Current relative rotation of the scene node. */ | ||
| 396 : | virtual const core::vector3df& getRotation() const | ||
| 397 : | { | ||
| 398 : | return RelativeRotation; | ||
| 399 : | } | ||
| 400 : | |||
| 401 : | |||
| 402 : | //! Sets the rotation of the node. | ||
| 403 : | /** This only modifies the relative rotation of the node. | ||
| 404 : | \param rotation: New rotation of the node in degrees. */ | ||
| 405 : | virtual void setRotation(const core::vector3df& rotation) | ||
| 406 : | { | ||
| 407 : | RelativeRotation = rotation; | ||
| 408 : | } | ||
| 409 : | |||
| 410 : | |||
| 411 : | //! Gets the position of the node. | ||
| 412 : | /** Note that the position is relative to the parent. | ||
| 413 : | \return Returns the current position of the node relative to the parent. */ | ||
| 414 : | virtual const core::vector3df getPosition() const | ||
| 415 : | { | ||
| 416 : | return RelativeTranslation; | ||
| 417 : | } | ||
| 418 : | |||
| 419 : | |||
| 420 : | //! Sets the position of the node. | ||
| 421 : | /** Note that the position is relative to the parent. | ||
| 422 : | \param newpos: New relative postition of the scene node. */ | ||
| 423 : | virtual void setPosition(const core::vector3df& newpos) | ||
| 424 : | { | ||
| 425 : | RelativeTranslation = newpos; | ||
| 426 : | } | ||
| 427 : | |||
| 428 : | |||
| 429 : | //! Gets the abolute position of the node. | ||
| 430 : | /** The position is absolute. | ||
| 431 : | \return Returns the current absolute position of the scene node. */ | ||
| 432 : | virtual core::vector3df getAbsolutePosition() const | ||
| 433 : | { | ||
| 434 : | return AbsoluteTransformation.getTranslation(); | ||
| 435 : | } | ||
| 436 : | |||
| 437 : | |||
| 438 : | //! Enables or disables automatic culling based on the bounding box. | ||
| 439 : | /** Automatic culling is enabled by default. Note that not | ||
| 440 : | all SceneNodes support culling (the billboard scene node for example) | ||
| 441 : | and that some nodes always cull their geometry because it is their | ||
| 442 : | only reason for existence, for example the OctreeSceneNode. | ||
| 443 : | \param state: The culling state to be used. */ | ||
| 444 : | void setAutomaticCulling( E_CULLING_TYPE state) | ||
| 445 : | { | ||
| 446 : | AutomaticCullingState = state; | ||
| 447 : | } | ||
| 448 : | |||
| 449 : | |||
| 450 : | //! Gets the automatic culling state. | ||
| 451 : | /** \return The node is culled based on its bounding box if this method | ||
| 452 : | returns true, otherwise no culling is performed. */ | ||
| 453 : | E_CULLING_TYPE getAutomaticCulling() const | ||
| 454 : | { | ||
| 455 : | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
| 456 : | return AutomaticCullingState; | ||
| 457 : | } | ||
| 458 : | |||
| 459 : | |||
| 460 : | //! Sets if debug data like bounding boxes should be drawn. | ||
| 461 : | /** Please note that not all scene nodes support this feature. */ | ||
| 462 : | virtual void setDebugDataVisible(E_DEBUG_SCENE_TYPE visible) | ||
| 463 : | { | ||
| 464 : | DebugDataVisible = visible; | ||
| 465 : | } | ||
| 466 : | |||
| 467 : | //! Returns if debug data like bounding boxes are drawed. | ||
| 468 : | E_DEBUG_SCENE_TYPE isDebugDataVisible() const | ||
| 469 : | { | ||
| 470 : | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
| 471 : | return DebugDataVisible; | ||
| 472 : | } | ||
| 473 : | |||
| 474 : | |||
| 475 : | //! Sets if this scene node is a debug object. | ||
| 476 : | /** Debug objects have some special properties, for example they can be easily | ||
| 477 : | excluded from collision detection or from serialization, etc. */ | ||
| 478 : | void setIsDebugObject(bool debugObject) | ||
| 479 : | { | ||
| 480 : | IsDebugObject = debugObject; | ||
| 481 : | } | ||
| 482 : | |||
| 483 : | //! Returns if this scene node is a debug object. | ||
| 484 : | /** Debug objects have some special properties, for example they can be easily | ||
| 485 : | excluded from collision detection or from serialization, etc. */ | ||
| 486 : | bool isDebugObject() | ||
| 487 : | { | ||
| 488 : | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
| 489 : | return IsDebugObject; | ||
| 490 : | } | ||
| 491 : | |||
| 492 : | |||
| 493 : | //! Returns a const reference to the list of all children. | ||
| 494 : | const core::list<ISceneNode*>& getChildren() const | ||
| 495 : | { | ||
| 496 : | return Children; | ||
| 497 : | } | ||
| 498 : | |||
| 499 : | |||
| 500 : | //! Changes the parent of the scene node. | ||
| 501 : | virtual void setParent(ISceneNode* newParent) | ||
| 502 : | { | ||
| 503 : | grab(); | ||
| 504 : | remove(); | ||
| 505 : | |||
| 506 : | Parent = newParent; | ||
| 507 : | |||
| 508 : | if (Parent) | ||
| 509 : | Parent->addChild(this); | ||
| 510 : | |||
| 511 : | drop(); | ||
| 512 : | } | ||
| 513 : | |||
| 514 : | |||
| 515 : | //! Returns the triangle selector attached to this scene node. | ||
| 516 : | //! The Selector can be used by the engine for doing collision | ||
| 517 : | //! detection. You can create a TriangleSelector with | ||
| 518 : | //! ISceneManager::createTriangleSelector() or | ||
| 519 : | //! ISceneManager::createOctTreeTriangleSelector and set it with | ||
| 520 : | //! ISceneNode::setTriangleSelector(). If a scene node got no triangle | ||
| 521 : | //! selector, but collision tests should be done with it, a triangle | ||
| 522 : | //! selector is created using the bounding box of the scene node. | ||
| 523 : | //! \return Returns a pointer to the TriangleSelector or NULL, if there | ||
| 524 : | //! is none. | ||
| 525 : | virtual ITriangleSelector* getTriangleSelector() const | ||
| 526 : | { | ||
| 527 : | return TriangleSelector; | ||
| 528 : | } | ||
| 529 : | |||
| 530 : | |||
| 531 : | //! Sets the triangle selector of the scene node. The Selector can be | ||
| 532 : | //! used by the engine for doing collision detection. You can create a | ||
| 533 : | //! TriangleSelector with ISceneManager::createTriangleSelector() or | ||
| 534 : | //! ISceneManager::createOctTreeTriangleSelector(). Some nodes may | ||
| 535 : | //! create their own selector by default, so it would be good to | ||
| 536 : | //! check if there is already a selector in this node by calling | ||
| 537 : | //! ISceneNode::getTriangleSelector(). | ||
| 538 : | //! \param selector: New triangle selector for this scene node. | ||
| 539 : | virtual void setTriangleSelector(ITriangleSelector* selector) | ||
| 540 : | { | ||
| 541 : | if (TriangleSelector) | ||
| 542 : | TriangleSelector->drop(); | ||
| 543 : | |||
| 544 : | TriangleSelector = selector; | ||
| 545 : | if (TriangleSelector) | ||
| 546 : | TriangleSelector->grab(); | ||
| 547 : | } | ||
| 548 : | |||
| 549 : | //! updates the absolute position based on the relative and the parents position | ||
| 550 : | virtual void updateAbsolutePosition() | ||
| 551 : | { | ||
| 552 : | if (Parent ) | ||
| 553 : | { | ||
| 554 : | AbsoluteTransformation = | ||
| 555 : | Parent->getAbsoluteTransformation() * getRelativeTransformation(); | ||
| 556 : | } | ||
| 557 : | else | ||
| 558 : | AbsoluteTransformation = getRelativeTransformation(); | ||
| 559 : | } | ||
| 560 : | |||
| 561 : | //! Returns the parent of this scene node | ||
| 562 : | scene::ISceneNode* getParent() const | ||
| 563 : | { | ||
| 564 : | return Parent; | ||
| 565 : | } | ||
| 566 : | |||
| 567 : | //! Returns type of the scene node | ||
| 568 : | virtual ESCENE_NODE_TYPE getType() const | ||
| 569 : | { | ||
| 570 : | return ESNT_UNKNOWN; | ||
| 571 : | } | ||
| 572 : | |||
| 573 : | //! Writes attributes of the scene node. | ||
| 574 : | //! Implement this to expose the attributes of your scene node for | ||
| 575 : | //! scripting languages, editors, debuggers or xml serialization purposes. | ||
| 576 : | virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) | ||
| 577 : | { | ||
| 578 : | out->addString ("Name", Name.c_str()); | ||
| 579 : | out->addInt ("Id", ID ); | ||
| 580 : | |||
| 581 : | out->addVector3d("Position", getPosition() ); | ||
| 582 : | out->addVector3d("Rotation", getRotation() ); | ||
| 583 : | out->addVector3d("Scale", getScale() ); | ||
| 584 : | |||
| 585 : | out->addBool ("Visible", IsVisible ); | ||
| 586 : | out->addEnum ("AutomaticCulling", AutomaticCullingState, AutomaticCullingNames); | ||
| 587 : | out->addInt ("DebugDataVisible", DebugDataVisible ); | ||
| 588 : | out->addBool ("IsDebugObject", IsDebugObject ); | ||
| 589 : | } | ||
| 590 : | |||
| 591 : | //! Reads attributes of the scene node. | ||
| 592 : | //! Implement this to set the attributes of your scene node for | ||
| 593 : | //! scripting languages, editors, debuggers or xml deserialization purposes. | ||
| 594 : | virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) | ||
| 595 : | { | ||
| 596 : | Name = in->getAttributeAsString("Name"); | ||
| 597 : | ID = in->getAttributeAsInt("Id"); | ||
| 598 : | |||
| 599 : | setPosition(in->getAttributeAsVector3d("Position")); | ||
| 600 : | setRotation(in->getAttributeAsVector3d("Rotation")); | ||
| 601 : | setScale(in->getAttributeAsVector3d("Scale")); | ||
| 602 : | |||
| 603 : | IsVisible = in->getAttributeAsBool("Visible"); | ||
| 604 : | AutomaticCullingState = (scene::E_CULLING_TYPE ) in->getAttributeAsEnumeration("AutomaticCulling", scene::AutomaticCullingNames); | ||
| 605 : | |||
| 606 : | DebugDataVisible = (scene::E_DEBUG_SCENE_TYPE ) in->getAttributeAsInt("DebugDataVisible"); | ||
| 607 : | IsDebugObject = in->getAttributeAsBool("IsDebugObject"); | ||
| 608 : | |||
| 609 : | updateAbsolutePosition(); | ||
| 610 : | } | ||
| 611 : | |||
| 612 : | //! Creates a clone of this scene node and its children. | ||
| 613 : | virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) | ||
| 614 : | { | ||
| 615 : | return 0; // to be implemented by derived classes | ||
| 616 : | } | ||
| 617 : | |||
| 618 : | protected: | ||
| 619 : | |||
| 620 : | //! this method can be used by clone() implementations of derived classes | ||
| 621 : | void cloneMembers(ISceneNode* toCopyFrom, ISceneManager* newManager) | ||
| 622 : | { | ||
| 623 : | Name = toCopyFrom->Name; | ||
| 624 : | AbsoluteTransformation = toCopyFrom->AbsoluteTransformation; | ||
| 625 : | RelativeTranslation = toCopyFrom->RelativeTranslation; | ||
| 626 : | RelativeRotation = toCopyFrom->RelativeRotation; | ||
| 627 : | RelativeScale = toCopyFrom->RelativeScale; | ||
| 628 : | ID = toCopyFrom->ID; | ||
| 629 : | setTriangleSelector(toCopyFrom->TriangleSelector); | ||
| 630 : | AutomaticCullingState = toCopyFrom->AutomaticCullingState; | ||
| 631 : | DebugDataVisible = toCopyFrom->DebugDataVisible; | ||
| 632 : | IsVisible = toCopyFrom->IsVisible; | ||
| 633 : | IsDebugObject = toCopyFrom->IsDebugObject; | ||
| 634 : | |||
| 635 : | if (newManager) | ||
| 636 : | SceneManager = newManager; | ||
| 637 : | else | ||
| 638 : | SceneManager = toCopyFrom->SceneManager; | ||
| 639 : | |||
| 640 : | // clone children | ||
| 641 : | |||
| 642 : | core::list<ISceneNode*>::Iterator it = toCopyFrom->Children.begin(); | ||
| 643 : | for (; it != toCopyFrom->Children.end(); ++it) | ||
| 644 : | (*it)->clone(this, newManager); | ||
| 645 : | |||
| 646 : | // clone animators | ||
| 647 : | |||
| 648 : | core::list<ISceneNodeAnimator*>::Iterator ait = toCopyFrom->Animators.begin(); | ||
| 649 : | for (; ait != toCopyFrom->Animators.end(); ++ait) | ||
| 650 : | { | ||
| 651 : | ISceneNodeAnimator* anim = (*ait)->createClone(this, SceneManager); | ||
| 652 : | if (anim) | ||
| 653 : | { | ||
| 654 : | addAnimator(anim); | ||
| 655 : | anim->drop(); | ||
| 656 : | } | ||
| 657 : | } | ||
| 658 : | } | ||
| 659 : | |||
| 660 : | //! name of the scene node. | ||
| 661 : | core::stringc Name; | ||
| 662 : | |||
| 663 : | //! absolute transformation of the node. | ||
| 664 : | core::matrix4 AbsoluteTransformation; | ||
| 665 : | |||
| 666 : | //! relative translation of the scene node. | ||
| 667 : | core::vector3df RelativeTranslation; | ||
| 668 : | |||
| 669 : | //! relative rotation of the scene node. | ||
| 670 : | core::vector3df RelativeRotation; | ||
| 671 : | |||
| 672 : | //! relative scale of the scene node. | ||
| 673 : | core::vector3df RelativeScale; | ||
| 674 : | |||
| 675 : | //! Pointer to the parent | ||
| 676 : | ISceneNode* Parent; | ||
| 677 : | |||
| 678 : | //! List of all children of this node | ||
| 679 : | core::list<ISceneNode*> Children; | ||
| 680 : | |||
| 681 : | //! List of all animator nodes | ||
| 682 : | core::list<ISceneNodeAnimator*> Animators; | ||
| 683 : | |||
| 684 : | //! id of the node. | ||
| 685 : | s32 ID; | ||
| 686 : | |||
| 687 : | //! pointer to the scene manager | ||
| 688 : | ISceneManager* SceneManager; | ||
| 689 : | |||
| 690 : | //! pointer to the triangle selector | ||
| 691 : | ITriangleSelector* TriangleSelector; | ||
| 692 : | |||
| 693 : | //! automatic culling | ||
| 694 : | E_CULLING_TYPE AutomaticCullingState; | ||
| 695 : | |||
| 696 : | //! is the node visible? | ||
| 697 : | bool IsVisible; | ||
| 698 : | |||
| 699 : | //! flag if debug data should be drawn, such as Bounding Boxes. | ||
| 700 : | E_DEBUG_SCENE_TYPE DebugDataVisible; | ||
| 701 : | |||
| 702 : | //! is debug object? | ||
| 703 : | bool IsDebugObject; | ||
| 704 : | }; | ||
| 705 : | |||
| 706 : | } // end namespace scene | ||
| 707 : | } // end namespace irr | ||
| 708 : | |||
| 709 : | #endif | ||
| 710 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

