1
/***************************************************************************
2
OgrePagingLandScapeData2D.h - description
5
copyright : (C) 2002-2006 by Jose A Milan & Tuan Kuranes
6
email : spoke@supercable.es & tuan.kuranes@free.fr
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU Lesser General Public License as *
13
* published by the Free Software Foundation; either version 2 of the *
14
* License, or (at your option) any later version. *
16
***************************************************************************/
18
#ifndef PAGINGLandScapeDATA2D_H
19
#define PAGINGLandScapeDATA2D_H
21
#include "OgrePagingLandScapePrerequisites.h"
23
#include "OgrePagingLandScapeData2DManager.h"
24
#include "OgrePagingLandScapeOptions.h"
26
#include <boost/shared_array.hpp>
31
* Encapsulating 2D Data reading.
33
class PagingLandScapeData2D
36
PagingLandScapeData2D(PagingLandScapeData2DManager* pageMgr);
38
virtual ~PagingLandScapeData2D();
40
virtual PagingLandScapeData2D* newPage() = 0;
42
virtual Ogre::String getName() const = 0;
43
virtual bool load(unsigned int mX, unsigned int mZ);
48
virtual void uninit();
50
virtual void unload();
54
* deform Height Data of the terrain.
55
* \param &deformationPoint
56
* Where modification is, in world coordinates
57
* \param &modificationHeight
58
* What modification do to terrain
60
* Give some info on tile to
61
* help coordinate system change
63
bool deformHeight(const Vector3& deformationPoint, Ogre::Real& modificationHeight);
67
* deform Height Data of the terrain.
69
* x Position on 2d height grid
71
* z Position on 2d height grid
72
* \param &modificationHeight
73
* What modification do to terrain
75
bool deformHeight(unsigned int x, unsigned int z, Ogre::Real& modificationHeight);
78
bool setHeight(unsigned int x, unsigned int z, const Ogre::Real& h);
79
bool setHeight(unsigned int x, unsigned int z, unsigned int Pos, const Ogre::Real& h);
82
* get smallest rectangle containing all deformation
83
* done before an update. (where rectangle is reseted.)
85
* \return Box struct describing rectangle
88
const Image::Box& getDeformationRectangle() const;
92
* Adjust smallest rectangle to make it contain the point
94
* x Position on 2d height grid
96
* z Position on 2d height grid
98
void adjustDeformationRectangle(unsigned int x, unsigned int z);
102
* Reset Deformation rectangle
104
void resetDeformationRectangle();
105
#endif // _MAPSPLITTER
107
virtual Ogre::Vector3 getNormal(const Ogre::Real& mX, const Ogre::Real& mZ) const;
109
virtual Ogre::ColourValue getBase(const Ogre::Real& mX, const Ogre::Real& mZ) const
111
return ColourValue::White;
114
virtual Ogre::ColourValue getCoverage(const Ogre::Real& mX, const Ogre::Real& mZ) const
116
return ColourValue::White;
119
virtual Ogre::Real getShadow(const Ogre::Real& mX, const Ogre::Real& mZ, bool positive) const
124
const Ogre::Real& getShiftX() const
129
const Ogre::Real& getShiftZ() const
134
inline Ogre::Real getHeightAbsolute(const Ogre::Real& x, const Ogre::Real& z) const
136
const Vector3& invScale = mParent->getOptions()->invScale;
138
// adjust x and z to be local to page
139
int i_x = static_cast<int> (x * invScale.x - mShiftX);
140
int i_z = static_cast<int> (z * invScale.z - mShiftZ);
142
// due to Real imprecision on Reals, we have to use boundaries here
143
// otherwise we'll hit asserts.
144
int size = static_cast<int> (mSize-1);
155
const unsigned int u_x = static_cast<unsigned int> (i_x);
156
const unsigned int u_z = static_cast<unsigned int> (i_z);
158
const size_t arraypos = u_z * mSize + u_x;
159
assert (mHeightData && arraypos < mMaxArrayPos);
160
return mHeightData[arraypos];
163
inline Ogre::Real getHeight(const Ogre::Real& x, const Ogre::Real& z) const
165
assert (z < mSize && x < mSize);
166
assert (mHeightData);
167
const unsigned int Pos = static_cast< unsigned int > (z * mSize + x);
168
assert (mMaxArrayPos > Pos);
169
return mHeightData[ Pos ];
172
inline Ogre::Real getHeight(unsigned int x, unsigned int z) const
174
assert (mHeightData);
175
assert (z < mSize && x < mSize);
176
const unsigned int Pos = static_cast <unsigned int> (z * mSize + x);
177
assert (mMaxArrayPos > Pos);
178
return mHeightData[ Pos ];
181
inline Ogre::Real getHeight(int x, int z) const
183
assert (mHeightData);
184
assert (static_cast< unsigned int >(z) < mSize && static_cast< unsigned int >(x) < mSize);
185
const unsigned int Pos = static_cast< unsigned int >(z * mSize + x);
186
assert (mMaxArrayPos > Pos);
187
return mHeightData[ Pos ];
190
inline Ogre::Real getHeight(unsigned int pos) const
192
assert (mHeightData);
193
assert (mMaxArrayPos > pos);
194
return mHeightData[ pos ];
197
inline Ogre::Real getMaxHeight() const
202
// useful to know max height before data is loaded.
203
virtual Ogre::Real getMaxAbsoluteHeight() const = 0;
205
Ogre::Real* getHeightData() const
210
bool isLoaded() const { return mIsLoaded; };
212
void computePowerof2PlusOneSize();
214
virtual size_t getXDimension() const
219
virtual size_t getZDimension() const
224
virtual size_t getSize() const
229
void getCoordinates(unsigned int& X, unsigned int& Z) const
235
inline bool isCoord(unsigned int x, unsigned int z) const { return (mPageX == x && mPageZ == z); };
239
virtual void _save() = 0;
240
virtual bool _load(unsigned int x, unsigned int z) = 0;
241
virtual void _load() = 0;
242
virtual void _unload() = 0;
243
bool _checkSize(size_t s);
245
// computed Height Data (scaled)
249
* @brief A shared array pointer which holds the height data.
251
* This instance determines the lifetime of the data. As the data is handled asynchronously it's important that the data isn't destroyed unless there are no more references to it.
253
boost::shared_array<Ogre::Real> mHeightDataPtr;
255
// maximum position in Array
256
unsigned int mMaxArrayPos;
257
// data side maximum size
261
// data source height
263
// image data maximum size
265
// maximum page/data2d height. (scaled)
267
// if data loaded or not
270
// if data modified or not
272
// if data modified but not yet
273
// readied by other objects (texture or renderable)
274
// to get modification to rect only once per frame.
275
bool mIsRectModified;
282
// coordinate shift based on page number
284
// coordinate shift based on page number
286
PagingLandScapeData2DManager* mParent;