PixelLightAPI  .
SceneHierarchyNode.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SceneHierarchyNode.h                           *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLSCENE_SCENEHIERARCHYNODE_H__
00024 #define __PLSCENE_SCENEHIERARCHYNODE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLMath/AABoundingBox.h>
00032 #include "PLScene/PLScene.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Forward declarations                                  ]
00037 //[-------------------------------------------------------]
00038 namespace PLGraphics {
00039     class Color4;
00040 }
00041 namespace PLMath {
00042     class Line;
00043     class Plane;
00044     class PlaneSet;
00045 }
00046 namespace PLScene {
00047     class SceneNode;
00048     class SceneContext;
00049     class SceneHierarchy;
00050     class SceneHierarchyNodeItem;
00051 }
00052 
00053 
00054 //[-------------------------------------------------------]
00055 //[ Namespace                                             ]
00056 //[-------------------------------------------------------]
00057 namespace PLScene {
00058 
00059 
00060 //[-------------------------------------------------------]
00061 //[ Classes                                               ]
00062 //[-------------------------------------------------------]
00063 /**
00064 *  @brief
00065 *    Abstract scene hierarchy node class
00066 *
00067 *  @remarks
00068 *    A scene hierarchy node can contain multiple scene hierarchy node items.
00069 */
00070 class SceneHierarchyNode {
00071 
00072 
00073     //[-------------------------------------------------------]
00074     //[ Friends                                               ]
00075     //[-------------------------------------------------------]
00076     friend class SceneHierarchy;
00077     friend class SceneHierarchyNodeItem;
00078 
00079 
00080     //[-------------------------------------------------------]
00081     //[ Public functions                                      ]
00082     //[-------------------------------------------------------]
00083     public:
00084         /**
00085         *  @brief
00086         *    Returns the scene context the scene hierarchy node is in
00087         *
00088         *  @return
00089         *    The scene context the scene hierarchy node is in, can but shouldn't be a null pointer
00090         */
00091         PLS_API SceneContext *GetSceneContext() const;
00092 
00093         /**
00094         *  @brief
00095         *    Returns the owner scene hierarchy
00096         *
00097         *  @return
00098         *    The owner scene hierarchy (NEVER a null pointer!)
00099         */
00100         PLS_API SceneHierarchy *GetHierarchy() const;
00101 
00102         /**
00103         *  @brief
00104         *    Returns the parent scene hierarchy node
00105         *
00106         *  @return
00107         *    The parent scene hierarchy node, if a null pointer, this is the root
00108         */
00109         PLS_API SceneHierarchyNode *GetParentNode() const;
00110 
00111         /**
00112         *  @brief
00113         *    Returns the unique ID of the scene hierarchy node
00114         *
00115         *  @return
00116         *    The unique ID of the scene hierarchy node
00117         *
00118         *  @remarks
00119         *    Some scene queries may need to hold some extra information per scene hierarchy node.
00120         *    In such cases, an unique node ID is quite useful to manage this information within for
00121         *    instance an array. SQCull for example may cache scene hierarchy node visibility information
00122         *    from the previous frame for the coherent hierarchical occlusion culling algorithm. In order
00123         *    to keep this unique node ID system working, ONLY SceneHierarchy::GetFreeNode() and
00124         *    SceneHierarchy::FreeNode() are used during runtime instead of new/delete. Have a look at
00125         *    the SceneHierarchy::GetFreeNode() documentation for more information about this.
00126         */
00127         PLS_API PLCore::uint32 GetID() const;
00128 
00129         /**
00130         *  @brief
00131         *    Returns the level/tree depth of the scene hierarchy node
00132         *
00133         *  @return
00134         *    The level/tree depth of the scene hierarchy node
00135         */
00136         PLS_API PLCore::uint8 GetLevel() const;
00137 
00138         /**
00139         *  @brief
00140         *    Returns the axis aligned bounding box of the scene hierarchy node
00141         *
00142         *  @return
00143         *    The axis aligned bounding box of the scene hierarchy node
00144         */
00145         PLS_API const PLMath::AABoundingBox &GetAABoundingBox() const;
00146 
00147         /**
00148         *  @brief
00149         *    Checks whether the scene hierarchy node volume is intersecting the given line
00150         *
00151         *  @param[in] cLine
00152         *    Line to check against
00153         *
00154         *  @return
00155         *    'false' if the scene hierarchy node volume is not intersecting the given line, else 'true'
00156         */
00157         PLS_API bool CheckLine(const PLMath::Line &cLine) const;
00158 
00159         /**
00160         *  @brief
00161         *    Checks whether the scene hierarchy node volume is within the given plane set
00162         *
00163         *  @param[in]  cPlaneSet
00164         *    Plane set to check against
00165         *  @param[out] pnOutClipMask
00166         *    If not a null pointer, this clip mask will receive the intersection state of a
00167         *    maximum number of 32 planes if the box intersects the plane set.
00168         *
00169         *  @return
00170         *    'false' if the scene hierarchy node volume is not within the given plane set, else 'true'
00171         */
00172         PLS_API bool CheckPlaneSet(const PLMath::PlaneSet &cPlaneSet, PLCore::uint32 *pnOutClipMask = nullptr) const;
00173 
00174         /**
00175         *  @brief
00176         *    Returns the side of the plane the scene hierarchy node volume is on
00177         *
00178         *  @param[in] cPlane
00179         *    Plane to check against
00180         *
00181         *  @return
00182         *    '-1' if of scene hierarchy node volume is behind the plane, '0' if it is
00183         *    intersecting the plane, '1' if the volume is in front of the plane
00184         */
00185         PLS_API char GetPlaneSide(const PLMath::Plane &cPlane) const;
00186 
00187         /**
00188         *  @brief
00189         *    Returns the shortest distance from a given point to the scene hierarchy node volume
00190         *
00191         *  @param[in] vPoint
00192         *    Point to get the shortest distance from
00193         *
00194         *  @return
00195         *    Shortest distance (squared) from the given point to the scene hierarchy node volume
00196         */
00197         PLS_API float GetShortestDistance(const PLMath::Vector3 &vPoint) const;
00198 
00199         /**
00200         *  @brief
00201         *    Returns the number of scene hierarchy node items
00202         *
00203         *  @return
00204         *    The number of scene hierarchy node items
00205         */
00206         PLS_API PLCore::uint32 GetNumOfItems() const;
00207 
00208         /**
00209         *  @brief
00210         *    Returns the first scene hierarchy node item
00211         *
00212         *  @return
00213         *    The first scene hierarchy node item, a null pointer if there are no items
00214         *
00215         *  @note
00216         *    - Use SceneHierarchyNodeItem::GetPreviousItem()/SceneHierarchyNodeItem::GetNextItem()
00217         *      get the previous/next scene hierarchy node item
00218         */
00219         PLS_API SceneHierarchyNodeItem *GetFirstItem() const;
00220 
00221 
00222     //[-------------------------------------------------------]
00223     //[ Public virtual SceneHierarchyNode functions           ]
00224     //[-------------------------------------------------------]
00225     public:
00226         /**
00227         *  @brief
00228         *    Touches the scene hierarchy scene node
00229         *
00230         *  @param[in] bRecursive
00231         *    Touch recursive?
00232         *
00233         *  @remarks
00234         *    Scene node distribution (splitt/merge) within the scene hierarchy is only performed if this function
00235         *    is called. If during for instance a visibility determination a scene hierarchy node is used the first
00236         *    time during this process, one should call this 'touch' function to inform the scene hierarchy that this
00237         *    scene hierarchy node is going to be used. This function will split a scene hierarchy node if certain conditions
00238         *    like a maximum number of items per scene hierarchy node are given. If other conditions are given a merge operation
00239         *    is performed which 'combines' scene hierarchy nodes instead of splitting them. As result of this function,
00240         *    normally only the scene hierarchy parts which are currently used will be updated. ("lazy evaluation" :)
00241         *    If 'bRecursive' is set to true, all child nodes are touched to - but this may only be useful for instance when
00242         *    initializing the scene hierarchy.
00243         */
00244         virtual void Touch(bool bRecursive = false) = 0;
00245 
00246         /**
00247         *  @brief
00248         *    Returns the number of child scene hierarchy nodes
00249         *
00250         *  @return
00251         *    The number of child scene hierarchy nodes
00252         */
00253         virtual PLCore::uint32 GetNumOfNodes() const = 0;
00254 
00255         /**
00256         *  @brief
00257         *    Returns a child scene hierarchy node
00258         *
00259         *  @param[in] nIndex
00260         *    Index of the requested child scene hierarchy node
00261         *
00262         *  @return
00263         *    The requested child scene hierarchy node, a null pointer on error
00264         */
00265         virtual SceneHierarchyNode *GetNode(PLCore::uint32 nIndex) const = 0;
00266 
00267 
00268     //[-------------------------------------------------------]
00269     //[ Protected functions                                   ]
00270     //[-------------------------------------------------------]
00271     protected:
00272         /**
00273         *  @brief
00274         *    Constructor
00275         *
00276         *  @param[in] cHierarchy
00277         *    The owner hierarchy
00278         */
00279         PLS_API SceneHierarchyNode(SceneHierarchy &cHierarchy);
00280 
00281         /**
00282         *  @brief
00283         *    Destructor
00284         */
00285         PLS_API virtual ~SceneHierarchyNode();
00286 
00287         /**
00288         *  @brief
00289         *    Returns a free scene hierarchy node
00290         *
00291         *  @return
00292         *    Free scene hierarchy node
00293         *
00294         *  @remarks
00295         *    This function will return a free scene hierarchy node. If there are no free nodes available,
00296         *    a new one is created. After a node is no longer required it is put into the list of free nodes
00297         *    by using FreeNode() instead of destroying it. This way, frequently creation and destruction of
00298         *    nodes is avoided and the management of the unique node ID's becomes quite simple.
00299         *    See SceneHierarchyNode::GetID() for more information about the unique node ID's.
00300         */
00301         PLS_API SceneHierarchyNode &GetFreeNode();
00302 
00303         /**
00304         *  @brief
00305         *    Marks a scene hierarchy node as free
00306         *
00307         *  @param[in] cNode
00308         *    Scene hierarchy node to mark as free
00309         *
00310         *  @see
00311         *    - GetFreeNode()
00312         */
00313         PLS_API void FreeNode(SceneHierarchyNode &cNode);
00314 
00315 
00316     //[-------------------------------------------------------]
00317     //[ Protected virtual SceneHierarchyNode functions        ]
00318     //[-------------------------------------------------------]
00319     protected:
00320         /**
00321         *  @brief
00322         *    Initializes the scene hierarchy node variables
00323         */
00324         PLS_API virtual void Init();
00325 
00326 
00327     //[-------------------------------------------------------]
00328     //[ Private functions                                     ]
00329     //[-------------------------------------------------------]
00330     private:
00331         /**
00332         *  @brief
00333         *    Adds a scene node to this scene hierarchy node
00334         *
00335         *  @param[in] cSceneNode
00336         *    Scene node to add
00337         */
00338         void AddSceneNode(SceneNode &cSceneNode);
00339 
00340         /**
00341         *  @brief
00342         *    Deletes all items attached to this scene hierarchy node
00343         */
00344         void DeleteItems();
00345 
00346         /**
00347         *  @brief
00348         *    Draws the hierarchy node (for debugging)
00349         *
00350         *  @param[in] cRenderer
00351         *    Renderer to use
00352         *  @param[in] cColor
00353         *    Color to use
00354         *  @param[in] mWorldViewProjection
00355         *    World view projection matrix to use
00356         *  @param[in] fLineWidth
00357         *    Line width
00358         */
00359         void Draw(PLRenderer::Renderer &cRenderer, const PLGraphics::Color4 &cColor, const PLMath::Matrix4x4 &mWorldViewProjection, float fLineWidth = 1.0f) const;
00360 
00361 
00362     //[-------------------------------------------------------]
00363     //[ Protected data                                        ]
00364     //[-------------------------------------------------------]
00365     protected:
00366         SceneHierarchy         *m_pHierarchy;       /**< Owner hierarchy (always valid!) */
00367         SceneHierarchyNode     *m_pParentNode;      /**< Parent scene hierarchy node, can be a null pointer */
00368         PLCore::uint32          m_nID;              /**< The unique ID of the scene hierarchy node */
00369         PLCore::uint8           m_nLevel;           /**< Scene hierarchy node level */
00370         PLMath::AABoundingBox   m_cAABoundingBox;   /**< Axis aligned bounding box of this scene hierarchy node */
00371         PLCore::uint32          m_nNumOfItems;      /**< The number of scene hierarchy node items attached to this scene hierarchy node */
00372         SceneHierarchyNodeItem *m_pFirstItem;       /**< The first scene hierarchy node item, can be a null pointer */
00373 
00374 
00375 };
00376 
00377 
00378 //[-------------------------------------------------------]
00379 //[ Namespace                                             ]
00380 //[-------------------------------------------------------]
00381 } // PLScene
00382 
00383 
00384 #endif // __PLSCENE_SCENEHIERARCHYNODE_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:59
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported