OpenMW
components/terrain/storage.hpp
Go to the documentation of this file.
00001 #ifndef COMPONENTS_TERRAIN_STORAGE_H
00002 #define COMPONENTS_TERRAIN_STORAGE_H
00003 
00004 #include <components/esm/loadland.hpp>
00005 #include <components/esm/loadltex.hpp>
00006 
00007 #include <OgreAxisAlignedBox.h>
00008 
00009 #include <OgreHardwareVertexBuffer.h>
00010 
00011 namespace Terrain
00012 {
00013 
00014     struct LayerInfo
00015     {
00016         std::string mDiffuseMap;
00017         std::string mNormalMap;
00018         bool mParallax; // Height info in normal map alpha channel?
00019     };
00020 
00022     class Storage
00023     {
00024     public:
00025         virtual ~Storage() {}
00026     private:
00027         virtual ESM::Land* getLand (int cellX, int cellY) = 0;
00028         virtual const ESM::LandTexture* getLandTexture(int index, short plugin) = 0;
00029 
00030     public:
00032         virtual Ogre::AxisAlignedBox getBounds() = 0;
00033 
00042         bool getMinMaxHeights (float size, const Ogre::Vector2& center, float& min, float& max);
00043 
00051         void fillVertexBuffers (int lodLevel, float size, const Ogre::Vector2& center,
00052                                 Ogre::HardwareVertexBufferSharedPtr vertexBuffer,
00053                                 Ogre::HardwareVertexBufferSharedPtr normalBuffer,
00054                                 Ogre::HardwareVertexBufferSharedPtr colourBuffer);
00055 
00066         void getBlendmaps (float chunkSize, const Ogre::Vector2& chunkCenter, bool pack,
00067                            std::vector<Ogre::TexturePtr>& blendmaps,
00068                            std::vector<LayerInfo>& layerList);
00069 
00070         float getHeightAt (const Ogre::Vector3& worldPos);
00071 
00072     private:
00073         void fixNormal (Ogre::Vector3& normal, int cellX, int cellY, int col, int row);
00074         void fixColour (Ogre::ColourValue& colour, int cellX, int cellY, int col, int row);
00075         void averageNormal (Ogre::Vector3& normal, int cellX, int cellY, int col, int row);
00076 
00077         float getVertexHeight (const ESM::Land* land, int x, int y);
00078 
00079         // Since plugins can define new texture palettes, we need to know the plugin index too
00080         // in order to retrieve the correct texture name.
00081         // pair  <texture id, plugin id>
00082         typedef std::pair<short, short> UniqueTextureId;
00083 
00084         UniqueTextureId getVtexIndexAt(int cellX, int cellY,
00085                                                int x, int y);
00086         std::string getTextureName (UniqueTextureId id);
00087 
00088         std::map<std::string, LayerInfo> mLayerInfoMap;
00089 
00090         LayerInfo getLayerInfo(const std::string& texture);
00091     };
00092 
00093 }
00094 
00095 #endif