OgreGrid2DPageStrategy.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-2011 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 
00029 #ifndef __Ogre_Grid2DPageStrategy_H__
00030 #define __Ogre_Grid2DPageStrategy_H__
00031 
00032 #include "OgrePagingPrerequisites.h"
00033 #include "OgrePageStrategy.h"
00034 #include "OgreVector2.h"
00035 #include "OgreVector3.h"
00036 #include "OgreQuaternion.h"
00037 
00038 namespace Ogre
00039 {
00047 
00048 
00050     enum Grid2DMode
00051     {
00053         G2D_X_Z = 0, 
00055         G2D_X_Y = 1, 
00057         G2D_Y_Z = 2
00058     };
00119     class _OgrePagingExport Grid2DPageStrategyData : public PageStrategyData
00120     {
00121     protected:
00123         Grid2DMode mMode;
00125         Vector3 mWorldOrigin;
00127         Vector2 mOrigin;
00129         Real mCellSize;
00131         Real mLoadRadius;
00133         Real mHoldRadius;
00134         Real mLoadRadiusInCells;
00135         Real mHoldRadiusInCells;
00136         int32 mMinCellX;
00137         int32 mMinCellY;
00138         int32 mMaxCellX;
00139         int32 mMaxCellY;
00140 
00141         void updateDerivedMetrics();
00142 
00143     public:
00144         static const uint32 CHUNK_ID;
00145         static const uint16 CHUNK_VERSION;
00146 
00147         Grid2DPageStrategyData();
00148         ~Grid2DPageStrategyData();
00149 
00151         virtual void setMode(Grid2DMode mode);
00152 
00154         virtual Grid2DMode getMode() const { return mMode; }
00155 
00157         virtual void setOrigin(const Vector3& worldOrigin);
00159         virtual const Vector3& getOrigin(const Vector3& worldOrigin) { return mWorldOrigin; }
00161         virtual void setCellSize(Real sz);
00163         virtual Real getCellSize() const { return mCellSize; }
00165         virtual void setLoadRadius(Real sz);
00167         virtual Real getLoadRadius() const { return mLoadRadius; }
00169         virtual void setHoldRadius(Real sz);
00171         virtual Real getHoldRadius() const { return mHoldRadius; }
00173         virtual Real getLoadRadiusInCells() { return mLoadRadiusInCells; }
00175         virtual Real getHoldRadiusInCells(){ return mHoldRadiusInCells; }
00176 
00178         virtual void setCellRange(int32 minX, int32 minY, int32 maxX, int32 maxY);
00180         virtual void setCellRangeMinX(int32 minX);
00182         virtual void setCellRangeMinY(int32 minY);
00184         virtual void setCellRangeMaxX(int32 maxX);
00186         virtual void setCellRangeMaxY(int32 maxY);
00188         virtual int32 getCellRangeMinX() const { return mMinCellX; }
00190         virtual int32 getCellRangeMinY() const { return mMinCellY; }
00192         virtual int32 getCellRangeMaxX() const { return mMaxCellX; }
00194         virtual int32 getCellRangeMaxY() const { return mMaxCellY; }
00195 
00197         bool load(StreamSerialiser& stream);
00199         void save(StreamSerialiser& stream);
00200 
00202         virtual void convertWorldToGridSpace(const Vector3& world, Vector2& grid);
00204         virtual void convertGridToWorldSpace(const Vector2& grid, Vector3& world);
00206         virtual void getMidPointGridSpace(int32 x, int32 y, Vector2& mid);
00208         virtual void getBottomLeftGridSpace(int32 x, int32 y, Vector2& bl);
00213         virtual void getCornersGridSpace(int32 x, int32 y, Vector2* pFourPoints);
00214         
00216         void determineGridLocation(const Vector2& gridpos, int32* x, int32* y);
00217 
00218         PageID calculatePageID(int32 x, int32 y);
00219         void calculateCell(PageID inPageID, int32* x, int32* y);
00220 
00221     };
00222 
00223 
00230     class _OgrePagingExport Grid2DPageStrategy : public PageStrategy
00231     {
00232     public:
00233         Grid2DPageStrategy(PageManager* manager);
00234 
00235         ~Grid2DPageStrategy();
00236 
00237         // Overridden members
00238         void notifyCamera(Camera* cam, PagedWorldSection* section);
00239         PageStrategyData* createData();
00240         void destroyData(PageStrategyData* d);
00241         void updateDebugDisplay(Page* p, SceneNode* sn);
00242         PageID getPageID(const Vector3& worldPos, PagedWorldSection* section);
00243     };
00244 
00247 }
00248 
00249 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sat Jan 14 2012 18:40:43