PixelLightAPI  .
VisNode.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: VisNode.h                                      *
00003  *
00004  *  Copyright (C) 2002-2011 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_VISIBILITY_VISNODE_H__
00024 #define __PLSCENE_VISIBILITY_VISNODE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLMath/Matrix3x4.h>
00032 #include <PLMath/Matrix4x4.h>
00033 #include "PLScene/PLScene.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLScene {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 class SceneNode;
00046 class VisContainer;
00047 class SceneNodeHandler;
00048 
00049 
00050 //[-------------------------------------------------------]
00051 //[ Classes                                               ]
00052 //[-------------------------------------------------------]
00053 /**
00054 *  @brief
00055 *    Node of the visibility tree
00056 */
00057 class VisNode {
00058 
00059 
00060     //[-------------------------------------------------------]
00061     //[ Friends                                               ]
00062     //[-------------------------------------------------------]
00063     friend class SQCull;
00064     friend class VisManager;
00065     friend class VisContainer;
00066 
00067 
00068     //[-------------------------------------------------------]
00069     //[ Public functions                                      ]
00070     //[-------------------------------------------------------]
00071     public:
00072         /**
00073         *  @brief
00074         *    Returns the visibility root container
00075         *
00076         *  @return
00077         *    The visibility root container, a null pointer on error
00078         */
00079         PLS_API const VisContainer *GetVisRootContainer() const;
00080 
00081         /**
00082         *  @brief
00083         *    Returns the parent visibility node
00084         *
00085         *  @return
00086         *    The parent visibility node, a null pointer if this is the root
00087         *
00088         *  @remarks
00089         *    The parent visibility node can be a VisContainer or a VisPortal. If the parent
00090         *    is a portal, this visibility node is the cell it links to.
00091         */
00092         PLS_API const VisNode *GetParent() const;
00093 
00094         /**
00095         *  @brief
00096         *    Returns the scene node this visibility node links to
00097         *
00098         *  @return
00099         *    The scene node this visibility node links to, a null pointer if there's no scene node
00100         *    linked to this visibility node (maybe the scene node this visibility node was
00101         *    linked to was killed?)
00102         */
00103         PLS_API SceneNode *GetSceneNode() const;
00104 
00105         /**
00106         *  @brief
00107         *    Returns the used projection matrix
00108         *
00109         *  @return
00110         *    The used projection matrix
00111         */
00112         PLS_API const PLMath::Matrix4x4 &GetProjectionMatrix() const;
00113 
00114         /**
00115         *  @brief
00116         *    Returns the used view matrix
00117         *
00118         *  @return
00119         *    The used view matrix
00120         */
00121         PLS_API const PLMath::Matrix4x4 &GetViewMatrix() const;
00122 
00123         /**
00124         *  @brief
00125         *    Returns the used view projection matrix
00126         *
00127         *  @return
00128         *    The used view projection matrix
00129         */
00130         PLS_API const PLMath::Matrix4x4 &GetViewProjectionMatrix() const;
00131 
00132         /**
00133         *  @brief
00134         *    Returns the absolute world matrix of the scene node
00135         *
00136         *  @return
00137         *    The absolute world matrix of the scene node
00138         *
00139         *  @remarks
00140         *    If the camera is within a container, this world matrix is relative to
00141         *    the container the camera is in.
00142         */
00143         PLS_API const PLMath::Matrix3x4 &GetWorldMatrix() const;
00144 
00145         // [TODO] VisNode refactoring -> currently, this method should not be used if possible because it doesn't update for example GetInverseWorldMatrix()
00146         void SetWorldMatrix(const PLMath::Matrix3x4 &mWorld);
00147 
00148         /**
00149         *  @brief
00150         *    Returns the absolute inverse world matrix of the scene node
00151         *
00152         *  @return
00153         *    The absolute inverse world matrix of the scene node
00154         *
00155         *  @remarks
00156         *    If the camera is within a container, this world matrix is relative to
00157         *    the container the camera is in.
00158         */
00159         PLS_API const PLMath::Matrix3x4 &GetInverseWorldMatrix() const;
00160 
00161         /**
00162         *  @brief
00163         *    Returns the absolute world view matrix of the scene node
00164         *
00165         *  @return
00166         *    The absolute world view matrix of the scene node
00167         *
00168         *  @remarks
00169         *    You can use for example
00170         *      Matrix4x4 mWorldViewProjection(cRenderer.GetTransformState(Transform::View));
00171         *      mWorldViewProjection *= pVisNode->GetWorldMatrix();
00172         *    to calculate the matrix by yourself. But for instance a advanced per pixel lighting scene
00173         *    renderer may need this final matrix of the node multiple times per frame, so, it's recommended
00174         *    to use this precalculated one.
00175         */
00176         PLS_API const PLMath::Matrix4x4 &GetWorldViewMatrix() const;
00177 
00178         /**
00179         *  @brief
00180         *    Returns the absolute world view projection matrix of the scene node
00181         *
00182         *  @return
00183         *    The absolute world view projection matrix of the scene node
00184         *
00185         *  @remarks
00186         *    You can use for example
00187         *      Matrix4x4 mWorldViewProjection(cRenderer.GetTransformState(Transform::Projection));
00188         *      mWorldViewProjection *= cRenderer.GetTransformState(Transform::View);
00189         *      mWorldViewProjection *= pVisNode->GetWorldMatrix();
00190         *    to calculate the matrix by yourself. But for instance a advanced per pixel lighting scene
00191         *    renderer may need this final matrix of the node multiple times per frame, so, it's recommended
00192         *    to use this precalculated one.
00193         */
00194         PLS_API const PLMath::Matrix4x4 &GetWorldViewProjectionMatrix() const;
00195 
00196         /**
00197         *  @brief
00198         *    Returns the squared distance to the camera
00199         *
00200         *  @return
00201         *    The squared distance to the camera
00202         */
00203         PLS_API float GetSquaredDistanceToCamera() const;
00204 
00205 
00206     //[-------------------------------------------------------]
00207     //[ Public virtual VisNodes functions                     ]
00208     //[-------------------------------------------------------]
00209     public:
00210         /**
00211         *  @brief
00212         *    Returns whether or not this is a container visibility node (VisContainer, links to a SceneContainer scene node)
00213         *
00214         *  @return
00215         *    'true' if this is a container visibility node, else 'false'
00216         */
00217         PLS_API virtual bool IsContainer() const;
00218 
00219         /**
00220         *  @brief
00221         *    Returns whether or not this is a cell visibility node (VisContainer, links to a SNCell scene node)
00222         *
00223         *  @return
00224         *    'true' if this is a cell visibility node, else 'false'
00225         */
00226         PLS_API virtual bool IsCell() const;
00227 
00228         /**
00229         *  @brief
00230         *    Returns whether or not this is a portal visibility node (VisPortal, links to a SNCellPortal scene node)
00231         *
00232         *  @return
00233         *    'true' if this is a portal visibility node, else 'false'
00234         */
00235         PLS_API virtual bool IsPortal() const;
00236 
00237 
00238     //[-------------------------------------------------------]
00239     //[ Protected functions                                   ]
00240     //[-------------------------------------------------------]
00241     protected:
00242         /**
00243         *  @brief
00244         *    Constructor
00245         *
00246         *  @param[in] pParent
00247         *    The parent visibility node, a null pointer if this is the root
00248         */
00249         VisNode(VisNode *pParent = nullptr);
00250 
00251         /**
00252         *  @brief
00253         *    Destructor
00254         */
00255         virtual ~VisNode();
00256 
00257 
00258     //[-------------------------------------------------------]
00259     //[ Private definitions                                   ]
00260     //[-------------------------------------------------------]
00261     private:
00262         /**
00263         *  @brief
00264         *    Flags which hold ínternal information
00265         */
00266         enum EInternalFlags {
00267             RecalculateInvWorld      = 1<<0,    /**< Recalculation of the current absolute inverse world matrix of the scene node required */
00268             RecalculateWorldView     = 1<<1,    /**< Recalculation of the current absolute world view matrix of the scene node required */
00269             RecalculateWorldViewProj = 1<<2     /**< Recalculation of the current absolute world view projection matrix of the scene node required */
00270         };
00271 
00272 
00273     //[-------------------------------------------------------]
00274     //[ Private data                                          ]
00275     //[-------------------------------------------------------]
00276     private:
00277         VisNode           *m_pParent;                   /**< Parent visibility node (VisContainer or VisPortal, can be a null pointer) */
00278         SceneNodeHandler  *m_pSceneNodeHandler;         /**< Scene node this visibility node is linked to (always valid!) */
00279         PLMath::Matrix3x4  m_mWorld;                    /**< Absolute world matrix of the scene node */
00280         float              m_fSquaredDistanceToCamera;  /**< Squared distance to the camera */
00281         // Lazy evaluation
00282         mutable PLCore::uint8     m_nInternalFlags;     /**< Internal flags */
00283         mutable PLMath::Matrix3x4 m_mInvWorld;          /**< Absolute inverse world matrix of the scene node (derived on demand from m_mWorld and SQCull data) */
00284         mutable PLMath::Matrix4x4 m_mWorldView;         /**< Absolute world view matrix of the scene node (derived on demand from m_mWorld and SQCull data) */
00285         mutable PLMath::Matrix4x4 m_mWorldViewProj;     /**< Absolute world view projection matrix of the scene node (derived on demand from m_mWorld and SQCull data) */
00286 
00287 
00288 };
00289 
00290 
00291 //[-------------------------------------------------------]
00292 //[ Namespace                                             ]
00293 //[-------------------------------------------------------]
00294 } // PLScene
00295 
00296 
00297 #endif // __PLSCENE_VISIBILITY_VISNODE_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:05
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported