PixelLightAPI  .
SNSpotLight.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: SNSpotLight.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_SPOTLIGHT_H__
00024 #define __PLSCENE_SPOTLIGHT_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLMath/Frustum.h>
00032 #include <PLMath/Matrix4x4.h>
00033 #include "PLScene/Scene/SNPointLight.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLScene {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Classes                                               ]
00044 //[-------------------------------------------------------]
00045 /**
00046 *  @brief
00047 *    Spot light scene node
00048 *
00049 *  @remarks
00050 *    PixelLight is using a right-handed coordinate system like OpenGL does, therefore the spot light usually looks
00051 *    along the negative z-axis. While this fact may be ok in 'low level' functionality, it makes spot lights less
00052 *    comfortable within the scene graph because this 'look along negative z' doesn't go along with universal
00053 *    features like 'look at this point'. So, we decided to 'break' the right-handed coordinate system convention
00054 *    within the spot light scene node when it's coming to 'look along negative z'. Instead we 'look along positive z'
00055 *    and we profit from an universal behavior and don't need to care about flipping axis.
00056 *
00057 *  @note
00058 *    - By default, the 'NoCone' flag is not set meaning that the given outer and inner angles are
00059 *      used for lighting
00060 */
00061 class SNSpotLight : public SNPointLight {
00062 
00063 
00064     //[-------------------------------------------------------]
00065     //[ Public definitions                                    ]
00066     //[-------------------------------------------------------]
00067     public:
00068         /**
00069         *  @brief
00070         *    Scene node flags (SceneNode flags extension)
00071         */
00072         enum EFlags {
00073             NoCone = 1<<13  /**< Do not use the given outer and inner angles for lighting */
00074         };
00075         pl_enum(EFlags)
00076             pl_enum_base(SNPointLight::EFlags)
00077             pl_enum_value(NoCone, "Do not use the given outer and inner angles for lighting")
00078         pl_enum_end
00079 
00080         /**
00081         *  @brief
00082         *    Scene node debug flags (SceneNode debug flags extension)
00083         */
00084         enum EDebugFlags {
00085             DebugDepthTest       = 1<<9,    /**< Perform a depth test when render the debug stuff like lines */
00086             DebugNoFrustum       = 1<<10,   /**< Do not draw the (green) frustum */
00087             DebugFrustumVertices = 1<<11    /**< Draw the (green) frustum vertices */
00088         };
00089         pl_enum(EDebugFlags)
00090             pl_enum_base(SNPointLight::EDebugFlags)
00091             pl_enum_value(DebugDepthTest,       "Perform a depth test when render the debug stuff like lines")
00092             pl_enum_value(DebugNoFrustum,       "Do not draw the (green) frustum")
00093             pl_enum_value(DebugFrustumVertices, "Draw the (green) frustum vertices")
00094         pl_enum_end
00095 
00096 
00097     //[-------------------------------------------------------]
00098     //[ RTTI interface                                        ]
00099     //[-------------------------------------------------------]
00100     pl_class(PLS_RTTI_EXPORT, SNSpotLight, "PLScene", PLScene::SNPointLight, "Spot light scene node")
00101         // Attributes
00102         pl_attribute(OuterAngle,    float,                      45.0f,  ReadWrite,  GetSet, "Outer cone angle in degree",                                   "")
00103         pl_attribute(InnerAngle,    float,                      35.0f,  ReadWrite,  GetSet, "Inner cone angle in degree (smaller than the outer angle)",    "")
00104         pl_attribute(ZNear,         float,                      0.1f,   ReadWrite,  GetSet, "Near clipping plane",                                          "")
00105         pl_attribute(Aspect,        float,                      1.0f,   ReadWrite,  GetSet, "Aspect factor (only used if 'NoCone'-flag is set!)",           "")
00106             // Overwritten SceneNode attributes
00107         pl_attribute(Flags,         pl_flag_type(EFlags),       0,      ReadWrite,  GetSet, "Flags",                                                        "")
00108         pl_attribute(DebugFlags,    pl_flag_type(EDebugFlags),  0,      ReadWrite,  GetSet, "Debug flags",                                                  "")
00109         // Constructors
00110         pl_constructor_0(DefaultConstructor,    "Default constructor",  "")
00111     pl_class_end
00112 
00113 
00114     //[-------------------------------------------------------]
00115     //[ Public RTTI get/set functions                         ]
00116     //[-------------------------------------------------------]
00117     public:
00118         PLS_API virtual void SetRange(float fValue) override;   // From SNPointLight
00119         PLS_API float GetOuterAngle() const;
00120         PLS_API void SetOuterAngle(float fValue);
00121         PLS_API float GetInnerAngle() const;
00122         PLS_API void SetInnerAngle(float fValue);
00123         PLS_API float GetZNear() const;
00124         PLS_API void SetZNear(float fValue);
00125         PLS_API float GetAspect() const;
00126         PLS_API void SetAspect(float fValue);
00127 
00128 
00129     //[-------------------------------------------------------]
00130     //[ Public functions                                      ]
00131     //[-------------------------------------------------------]
00132     public:
00133         /**
00134         *  @brief
00135         *    Default constructor
00136         */
00137         PLS_API SNSpotLight();
00138 
00139         /**
00140         *  @brief
00141         *    Destructor
00142         */
00143         PLS_API virtual ~SNSpotLight();
00144 
00145         /**
00146         *  @brief
00147         *    Returns the projection matrix
00148         *
00149         *  @return
00150         *    Projection matrix
00151         */
00152         PLS_API const PLMath::Matrix4x4 &GetProjectionMatrix();
00153 
00154         /**
00155         *  @brief
00156         *    Returns the view matrix
00157         *
00158         *  @remarks
00159         *    PixelLight is using a right-handed coordinate system like OpenGL does, therefore the view matrix 'looks'
00160         *    along the negative z-axis. (unlike the spot light scene node itself, have a look into the class documentation)
00161         *
00162         *  @return
00163         *    View matrix
00164         */
00165         PLS_API const PLMath::Matrix3x4 &GetViewMatrix();
00166 
00167         /**
00168         *  @brief
00169         *    Returns the spot light frustum
00170         *
00171         *  @return
00172         *    Spot light frustum in 'scene container space'
00173         */
00174         PLS_API const PLMath::Frustum &GetFrustum();
00175 
00176         /**
00177         *  @brief
00178         *    Returns the 8 spot light frustum vertices
00179         *
00180         *  @return
00181         *    8 spot light frustum vertices in 'scene container space'
00182         *
00183         *  @note
00184         *    - This vertices can for instance be used to check the spot frustum visibility
00185         */
00186         PLS_API const PLCore::Array<PLMath::Vector3> &GetFrustumVertices();
00187 
00188 
00189     //[-------------------------------------------------------]
00190     //[ Protected definitions                                 ]
00191     //[-------------------------------------------------------]
00192     protected:
00193         /**
00194         *  @brief
00195         *    Flags which hold ínternal light information ('SNPointLight::EInternalLightFlags' extension)
00196         */
00197         enum EInternalLightFlags {
00198             // Recalculate
00199             RecalculateProjectionMatrix = 1<<1, /**< Recalculation of projection matrix required */
00200             RecalculateViewMatrix       = 1<<2, /**< Recalculation of view matrix required */
00201             RecalculateFrustum          = 1<<3, /**< Recalculation of frustum required */
00202             RecalculateFrustumVertices  = 1<<4  /**< Recalculation of frustum vertices required */
00203         };
00204 
00205 
00206     //[-------------------------------------------------------]
00207     //[ Private functions                                     ]
00208     //[-------------------------------------------------------]
00209     private:
00210         /**
00211         *  @brief
00212         *    Called when the scene node position or rotation changed
00213         */
00214         void OnPositionRotation();
00215 
00216         /**
00217         *  @brief
00218         *    Calculates and returns the current view rotation
00219         *
00220         *  @return
00221         *    The current view rotation
00222         */
00223         PLMath::Quaternion CalculateViewRotation() const;
00224 
00225 
00226     //[-------------------------------------------------------]
00227     //[ Private event handlers                                ]
00228     //[-------------------------------------------------------]
00229     private:
00230         PLCore::EventHandler<> EventHandlerPositionRotation;
00231 
00232 
00233     //[-------------------------------------------------------]
00234     //[ Private data                                          ]
00235     //[-------------------------------------------------------]
00236     private:
00237         float                          m_fOuterAngle;       /**< Outer cone angle in degree */
00238         float                          m_fInnerAngle;       /**< Inner cone angle in degree (smaller than the outer angle) */
00239         float                          m_fZNear;            /**< Near clipping plane */
00240         float                          m_fAspect;           /**< Aspect factor (only used if 'NoCone'-flag is set!) */
00241         PLMath::Matrix4x4              m_mProj;             /**< Current projection matrix */
00242         PLMath::Matrix3x4              m_mView;             /**< Current view matrix */
00243         PLMath::Frustum                m_cFrustum;          /**< Current frustum */
00244         PLCore::Array<PLMath::Vector3> m_cFrustumVertices;  /**< Current frustum vertices */
00245 
00246 
00247     //[-------------------------------------------------------]
00248     //[ Public virtual SNLight functions                      ]
00249     //[-------------------------------------------------------]
00250     public:
00251         PLS_API virtual bool IsSpotLight() const override;
00252 
00253 
00254     //[-------------------------------------------------------]
00255     //[ Public virtual SceneNode functions                    ]
00256     //[-------------------------------------------------------]
00257     public:
00258         PLS_API virtual void DrawDebug(PLRenderer::Renderer &cRenderer, const VisNode *pVisNode = nullptr) override;
00259 
00260 
00261     //[-------------------------------------------------------]
00262     //[ Protected virtual SceneNode functions                 ]
00263     //[-------------------------------------------------------]
00264     protected:
00265         PLS_API virtual void UpdateAABoundingBox() override;
00266         PLS_API virtual void GetBoundingSphere(PLMath::Sphere &cSphere) override;
00267         PLS_API virtual void GetContainerBoundingSphere(PLMath::Sphere &cSphere) override;
00268 
00269 
00270 };
00271 
00272 
00273 //[-------------------------------------------------------]
00274 //[ Namespace                                             ]
00275 //[-------------------------------------------------------]
00276 } // PLScene
00277 
00278 
00279 #endif // __PLSCENE_SPOTLIGHT_H__


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