PixelLightAPI  .
SNSky.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SNSky.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_SCENENODE_SKY_H__
00024 #define __PLSCENE_SCENENODE_SKY_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/Tools/Loadable.h>
00032 #include "PLScene/Scene/SceneNode.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLScene {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Forward declarations                                  ]
00043 //[-------------------------------------------------------]
00044 class SNSky;
00045 
00046 
00047 //[-------------------------------------------------------]
00048 //[ Classes                                               ]
00049 //[-------------------------------------------------------]
00050 /**
00051 *  @brief
00052 *    Sky layer
00053 *
00054 *  @note
00055 *  - Each sky mesh geometry has it's own material
00056 *  - A sky plane has one geometry
00057 *  - A sky cube has 6 geometries\n
00058 *    Order: x-positive (0), x-negative (1), y-positive (2),
00059 *    y-negative (3), z-positive (4), z-negative (5)
00060 *
00061 */
00062 class SkyLayer : public PLCore::Object, public PLCore::Element<SkyLayer> {
00063 
00064 
00065     //[-------------------------------------------------------]
00066     //[ Friends                                               ]
00067     //[-------------------------------------------------------]
00068     friend class SNSky;
00069 
00070 
00071     //[-------------------------------------------------------]
00072     //[ Public definitions                                    ]
00073     //[-------------------------------------------------------]
00074     public:
00075         /**
00076         *  @brief
00077         *    Sky layer type
00078         */
00079         enum EType {
00080             Unknown  = 0,   /**< Unknown sky type */
00081             Plane    = 1,   /**< Sky plane */
00082             Cube     = 2,   /**< Sky cube */
00083             Sphere   = 3,   /**< Sky sphere */
00084             Dome     = 4,   /**< Sky dome */
00085             Cylinder = 5    /**< Sky cylinder */
00086         };
00087         pl_enum(EType)
00088             pl_enum_value(Unknown,  "Unknown sky type")
00089             pl_enum_value(Plane,    "Sky plane")
00090             pl_enum_value(Cube,     "Sky cube")
00091             pl_enum_value(Sphere,   "Sky sphere")
00092             pl_enum_value(Dome,     "Sky dome")
00093             pl_enum_value(Cylinder, "Sky cylinder")
00094         pl_enum_end
00095 
00096 
00097     //[-------------------------------------------------------]
00098     //[ RTTI interface                                        ]
00099     //[-------------------------------------------------------]
00100     pl_class(PLS_RTTI_EXPORT, SkyLayer, "PLScene", PLCore::Object, "Sky layer")
00101         // Attributes
00102         pl_attribute(Type,      pl_enum_type(EType),    Unknown,                            ReadWrite,  GetSet, "Sky layer type",                                                           "")
00103         pl_attribute(Position,  PLMath::Vector3,        PLMath::Vector3(0.0f, 0.0f, 0.0f),  ReadWrite,  GetSet, "Sky layer position",                                                       "")
00104         pl_attribute(Rotation,  PLMath::Vector3,        PLMath::Vector3(0.0f, 0.0f, 0.0f),  ReadWrite,  GetSet, "Sky layer rotation",                                                       "")
00105         pl_attribute(Scale,     PLMath::Vector3,        PLMath::Vector3(1.0f, 1.0f, 1.0f),  ReadWrite,  GetSet, "Sky layer scale",                                                          "")
00106         pl_attribute(Name,      PLCore::String,         "",                                 ReadWrite,  GetSet, "Optional sky layer name. If not defined, a name is chosen automatically.", "")
00107     pl_class_end
00108 
00109 
00110     //[-------------------------------------------------------]
00111     //[ Public RTTI get/set functions                         ]
00112     //[-------------------------------------------------------]
00113     public:
00114         PLS_API EType GetType() const;
00115         PLS_API void SetType(EType nValue);
00116         PLS_API const PLMath::Vector3 &GetPosition() const;
00117         PLS_API void SetPosition(const PLMath::Vector3 &vValue);
00118         PLS_API const PLMath::Vector3 &GetRotation() const;
00119         PLS_API void SetRotation(const PLMath::Vector3 &vValue);
00120         PLS_API const PLMath::Vector3 &GetScale() const;
00121         PLS_API void SetScale(const PLMath::Vector3 &vValue);
00122 
00123 
00124     //[-------------------------------------------------------]
00125     //[ Public functions                                      ]
00126     //[-------------------------------------------------------]
00127     public:
00128         /**
00129         *  @brief
00130         *    Destructor
00131         */
00132         PLS_API virtual ~SkyLayer();
00133 
00134         /**
00135         *  @brief
00136         *    Returns the sky this sky layer is in
00137         *
00138         *  @return
00139         *    The sky this sky layer is in, NEVER a null pointer
00140         */
00141         PLS_API SNSky *GetSky() const;
00142 
00143         /**
00144         *  @brief
00145         *    Returns the sky layer mesh handler
00146         *
00147         *  @return
00148         *    The mesh of the sky layer handler, a null pointer on error
00149         */
00150         PLS_API PLMesh::MeshHandler *GetMeshHandler() const;
00151 
00152         /**
00153         *  @brief
00154         *    Loads a material
00155         *
00156         *  @param[in] sFilename
00157         *    Material filename
00158         *  @param[in] nMaterial
00159         *    Material ID
00160         *
00161         *  @return
00162         *    'true' if all went fine, else 'false'
00163         */
00164         PLS_API bool LoadMaterial(const PLCore::String &sFilename, PLCore::uint32 nMaterial = 0);
00165 
00166         /**
00167         *  @brief
00168         *    Returns the current final transform matrix
00169         *
00170         *  @return
00171         *    The current final transform matrix
00172         *
00173         *  @note
00174         *    - If position, rotation or scale was changed, the current transform matrix
00175         *      is recalculated internally before it is returned
00176         */
00177         PLS_API const PLMath::Matrix3x4 &GetTransformMatrix();
00178 
00179 
00180     //[-------------------------------------------------------]
00181     //[ Private functions                                     ]
00182     //[-------------------------------------------------------]
00183     private:
00184         /**
00185         *  @brief
00186         *    Constructor
00187         *
00188         *  @param[in] sName
00189         *    Element name to set
00190         *  @param[in] pManager
00191         *    Element manager using this element, can be a null pointer
00192         */
00193         SkyLayer(const PLCore::String &sName, PLCore::ElementManager<SkyLayer> *pManager);
00194 
00195 
00196     //[-------------------------------------------------------]
00197     //[ Private data                                          ]
00198     //[-------------------------------------------------------]
00199     private:
00200         EType                m_nType;                   /**< Sky layer type */
00201         PLMath::Vector3      m_vPos;                    /**< Sky layer position */
00202         PLMath::Vector3      m_vRot;                    /**< Sky layer rotation */
00203         PLMath::Vector3      m_vScale;                  /**< Sky layer scale */
00204         PLMesh::MeshHandler *m_pMeshHandler;            /**< Sky layer mesh (ALWAYS valid!) */
00205         PLMath::Matrix3x4    m_mTrans;                  /**< Current final transform matrix */
00206         bool                 m_bRecalculateWorldMatrix; /**< World matrix recalculation required? */
00207 
00208 
00209 };
00210 
00211 /**
00212 *  @brief
00213 *    Sky scene node
00214 */
00215 class SNSky : public SceneNode, public PLCore::ElementManager<SkyLayer>, public PLCore::Loadable {
00216 
00217 
00218     //[-------------------------------------------------------]
00219     //[ RTTI interface                                        ]
00220     //[-------------------------------------------------------]
00221     pl_class(PLS_RTTI_EXPORT, SNSky, "PLScene", PLScene::SceneNode, "Sky scene node")
00222         // Attributes
00223             // Overwritten SceneNode attributes
00224         pl_attribute(Flags,             pl_flag_type(EFlags),   NoCulling,                                          ReadWrite,  GetSet,     "Flags",                                                                                                                            "")
00225         pl_attribute(MaxDrawDistance,   float,                  -10000.0f,                                          ReadWrite,  ModifyAttr, "Maximum draw distance of the scene node to the camera, if 0 do always draw, if negative, do always draw this node before other",   "")
00226         pl_attribute(AABBMin,           PLMath::Vector3,        PLMath::Vector3(-10000.0f, -10000.0f, -10000.0f),   ReadWrite,  GetSet,     "Minimum position of the 'scene node space' axis aligned bounding box",                                                             "")
00227         pl_attribute(AABBMax,           PLMath::Vector3,        PLMath::Vector3( 10000.0f,  10000.0f,  10000.0f),   ReadWrite,  GetSet,     "Maximum position of the 'scene node space' axis aligned bounding box",                                                             "")
00228             // Overwritten PLCore::Loadable attributes
00229         pl_attribute(Filename,          PLCore::String,         "",                                                 ReadWrite,  GetSet,     "Sky filename",                                                                                                                     "Type='Sky'")
00230         // Constructors
00231         pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00232     pl_class_end
00233 
00234 
00235     //[-------------------------------------------------------]
00236     //[ Public RTTI get/set functions                         ]
00237     //[-------------------------------------------------------]
00238     public:
00239         PLS_API void SetFilename(const PLCore::String &sValue);
00240 
00241 
00242     //[-------------------------------------------------------]
00243     //[ Public functions                                      ]
00244     //[-------------------------------------------------------]
00245     public:
00246         /**
00247         *  @brief
00248         *    Default constructor
00249         */
00250         PLS_API SNSky();
00251 
00252         /**
00253         *  @brief
00254         *    Destructor
00255         */
00256         PLS_API virtual ~SNSky();
00257 
00258 
00259     //[-------------------------------------------------------]
00260     //[ Public virtual SceneNode functions                    ]
00261     //[-------------------------------------------------------]
00262     public:
00263         PLS_API virtual void DrawPre(PLRenderer::Renderer &cRenderer, const VisNode *pVisNode = nullptr) override;
00264 
00265 
00266     //[-------------------------------------------------------]
00267     //[ Private virtual SceneNode functions                   ]
00268     //[-------------------------------------------------------]
00269     private:
00270         virtual void InitFunction() override;
00271         virtual void OnActivate(bool bActivate) override;
00272 
00273 
00274     //[-------------------------------------------------------]
00275     //[ Private virtual PLCore::ElementManager functions      ]
00276     //[-------------------------------------------------------]
00277     private:
00278         virtual SkyLayer *CreateElement(const PLCore::String &sName) override;
00279 
00280 
00281     //[-------------------------------------------------------]
00282     //[ Public virtual PLCore::Loadable functions             ]
00283     //[-------------------------------------------------------]
00284     public:
00285         PLS_API virtual bool Unload() override;
00286         PLS_API virtual PLCore::String GetLoadableTypeName() const override;
00287 
00288 
00289     //[-------------------------------------------------------]
00290     //[ Private virtual PLCore::Loadable functions            ]
00291     //[-------------------------------------------------------]
00292     private:
00293         virtual bool CallLoadable(PLCore::File &cFile, PLCore::Loader &cLoader, const PLCore::String &sMethod, const PLCore::String &sParams) override;
00294 
00295 
00296     //[-------------------------------------------------------]
00297     //[ Private functions                                     ]
00298     //[-------------------------------------------------------]
00299     private:
00300         /**
00301         *  @brief
00302         *    Called when the scene node needs to be updated
00303         */
00304         void OnUpdate();
00305 
00306 
00307     //[-------------------------------------------------------]
00308     //[ Private event handlers                                ]
00309     //[-------------------------------------------------------]
00310     private:
00311         PLCore::EventHandler<> EventHandlerUpdate;
00312 
00313 
00314 };
00315 
00316 
00317 //[-------------------------------------------------------]
00318 //[ Namespace                                             ]
00319 //[-------------------------------------------------------]
00320 } // PLScene
00321 
00322 
00323 #endif // __PLSCENE_SCENENODE_SKY_H__


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