OgreShadowCameraSetupFocused.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008 Copyright (c) 2006 Matthias Fink, netAllied GmbH <matthias.fink@web.de>
    00009
    00010 Permission is hereby granted, free of charge, to any person obtaining a copy
    00011 of this software and associated documentation files (the "Software"), to deal
    00012 in the Software without restriction, including without limitation the rights
    00013 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00014 copies of the Software, and to permit persons to whom the Software is
    00015 furnished to do so, subject to the following conditions:
    00016
    00017 The above copyright notice and this permission notice shall be included in
    00018 all copies or substantial portions of the Software.
    00019
    00020 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00021 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00022 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00023 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00024 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00025 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00026 THE SOFTWARE.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __ShadowCameraSetupFocused_H__
    00030 #define __ShadowCameraSetupFocused_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreShadowCameraSetup.h"
    00034 #include "OgrePolygon.h"
    00035 #include "OgreConvexBody.h"
    00036
    00037
    00038 namespace Ogre {
    00039
    00040     class ConvexBody;
    00041
    00057     class _OgreExport FocusedShadowCameraSetup : public ShadowCameraSetup
    00058     {
    00059     protected:
    00067         static const Matrix4 msNormalToLightSpace;
    00068         static const Matrix4 msLightSpaceToNormal;
    00069
    00073         Frustum* mTempFrustum;
    00074
    00077         Camera* mLightFrustumCamera;
    00078         mutable bool mLightFrustumCameraCalculated;
    00079
    00081         bool mUseAggressiveRegion;
    00082
    00085         class _OgreExport PointListBody
    00086         {
    00087             Polygon::VertexList mBodyPoints;
    00088             AxisAlignedBox      mAAB;
    00089
    00090         public:
    00091             PointListBody();
    00092             PointListBody(const ConvexBody& body);
    00093             ~PointListBody();
    00094
    00097             void merge(const PointListBody& plb);
    00098
    00103             void build(const ConvexBody& body, bool filterDuplicates = true);
    00104
    00114             void buildAndIncludeDirection(const ConvexBody& body,
    00115                 Real extrudeDist, const Vector3& dir);
    00116
    00119             const AxisAlignedBox& getAAB(void) const;
    00120
    00123             void addPoint(const Vector3& point);
    00124
    00127             void addAAB(const AxisAlignedBox& aab);
    00128
    00131             const Vector3& getPoint(size_t cnt) const;
    00132
    00135             size_t getPointCount(void) const;
    00136
    00139             void reset(void);
    00140
    00141         };
    00142
    00143         // Persistent calculations to prevent reallocation
    00144         mutable ConvexBody mBodyB;
    00145         mutable PointListBody mPointListBodyB;
    00146         mutable PointListBody mPointListBodyLVS;
    00147
    00148     protected:
    00163         void calculateShadowMappingMatrix(const SceneManager& sm, const Camera& cam,
    00164             const Light& light, Matrix4 *out_view,
    00165             Matrix4 *out_proj, Camera *out_cam) const;
    00166
    00186         void calculateB(const SceneManager& sm, const Camera& cam, const Light& light,
    00187             const AxisAlignedBox& sceneBB, const AxisAlignedBox& receiverBB, PointListBody *out_bodyB) const;
    00188
    00203         void calculateLVS(const SceneManager& sm, const Camera& cam, const Light& light,
    00204             const AxisAlignedBox& sceneBB, PointListBody *out_LVS) const;
    00205
    00215         Vector3 getLSProjViewDir(const Matrix4& lightSpace, const Camera& cam,
    00216             const PointListBody& bodyLVS) const;
    00217
    00227         Vector3 getNearCameraPoint_ws(const Matrix4& viewMatrix,
    00228             const PointListBody& bodyLVS) const;
    00229
    00239         Matrix4 transformToUnitCube(const Matrix4& m, const PointListBody& body) const;
    00240
    00245         Matrix4 buildViewMatrix(const Vector3& pos, const Vector3& dir, const Vector3& up) const;
    00246
    00247     public:
    00252         FocusedShadowCameraSetup(void);
    00253
    00258         virtual ~FocusedShadowCameraSetup(void);
    00259
    00262         virtual void getShadowCamera(const SceneManager *sm, const Camera *cam,
    00263             const Viewport *vp, const Light *light, Camera *texCam, size_t iteration) const;
    00264
    00278         void setUseAggressiveFocusRegion(bool aggressive) { mUseAggressiveRegion = aggressive; }
    00279
    00280         bool getUseAggressiveFocusRegion() const { return mUseAggressiveRegion; }
    00281
    00282     };
    00283
    00287 }
    00288
    00289 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:24