12#include <OgreException.h>
13#include <OgreVector3.h>
14#include <OgreQuaternion.h>
15#include <OgreLogManager.h>
16#include <OgreStringConverter.h>
69 Vector3 pos = position;
73 const Real smallVal = 0.01f;
75 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Tree position is out of bounds",
"TreeLoader::addTree()");
77 OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Tree scale out of range",
"TreeLoader::addTree()");
94 std::vector<TreeDef> *pageGrid = 0;
112 int pageX = (int)Math::Floor(xrel /
pageSize);
113 int pageZ = (int)Math::Floor(zrel /
pageSize);
114 std::vector<TreeDef> &treeList =
_getGridPage(pageGrid, pageX, pageZ);
120 tree.
rotation =
static_cast<uint8
>(Ogre::Real(0.708) * yaw.valueDegrees());
124 treeList.push_back(tree);
133 Vector3 pos = position;
154 Real radiusSq = radius * radius;
156 if (minPageX < 0) minPageX = 0;
else if (minPageX >=
pageGridX) minPageX =
pageGridX-1;
157 if (minPageZ < 0) minPageZ = 0;
else if (minPageZ >=
pageGridZ) minPageZ =
pageGridZ-1;
158 if (maxPageX < 0) maxPageX = 0;
else if (maxPageX >=
pageGridX) maxPageX =
pageGridX-1;
159 if (maxPageZ < 0) maxPageZ = 0;
else if (maxPageZ >=
pageGridZ) maxPageZ =
pageGridZ-1;
175 std::vector<TreeDef> *pageGrid = it->second;
177 for (
int tileZ = minPageZ; tileZ <= maxPageZ; ++tileZ){
178 for (
int tileX = minPageX; tileX <= maxPageX; ++tileX){
179 bool modified =
false;
182 std::vector<TreeDef> &treeList =
_getGridPage(pageGrid, tileX, tileZ);
184 while (i < treeList.size())
189 Ogre::Real distSq = distX * distX + distZ * distZ;
191 if (distSq <= radiusSq){
193 treeList[i] = treeList.back();
231 if (minPageX < 0) minPageX = 0;
else if (minPageX >=
pageGridX) minPageX =
pageGridX-1;
232 if (minPageZ < 0) minPageZ = 0;
else if (minPageZ >=
pageGridZ) minPageZ =
pageGridZ-1;
233 if (maxPageX < 0) maxPageX = 0;
else if (maxPageX >=
pageGridX) maxPageX =
pageGridX-1;
234 if (maxPageZ < 0) maxPageZ = 0;
else if (maxPageZ >=
pageGridZ) maxPageZ =
pageGridZ-1;
250 std::vector<TreeDef> *pageGrid = it->second;
252 for (
int tileZ = minPageZ; tileZ <= maxPageZ; ++tileZ){
253 for (
int tileX = minPageX; tileX <= maxPageX; ++tileX){
254 bool modified =
false;
257 std::vector<TreeDef> &treeList =
_getGridPage(pageGrid, tileX, tileZ);
259 while (i < treeList.size()){
263 if (posX >= area.left && posX <= area.right && posZ >= area.top && posZ <= area.bottom) {
265 treeList[i] = treeList.back();
323 std::vector<TreeDef> *pageGrid = i->second;
325 Entity *entity = i->first;
328 std::vector<TreeDef>::iterator o;
329 for (o = treeList.begin(); o != treeList.end(); ++o){
342 Degree angle((Real)o->rotation * (360.0f / 255));
343 Quaternion rot(angle, Vector3::UNIT_Y);
356 color = ColourValue::White;
358 addEntity(entity, pos, rot, scale, color);
static ColorMap * load(const Ogre::String &fileName, MapChannel channel=CHANNEL_COLOR)
void setFilter(MapFilter filter)
Sets the filtering mode used for this color map.
Ogre::ColourValue getColorAt_Unpacked(Ogre::Real x, Ogre::Real z, const Ogre::TRect< Ogre::Real > &mapBounds)
Gets the color value at the specified position.
void addEntity(Ogre::Entity *ent, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, const Ogre::Vector3 &scale=Ogre::Vector3::UNIT_SCALE, const Ogre::ColourValue &color=Ogre::ColourValue::White)
Call this from loadPage() to add an entity to the page being loaded.
A class providing highly optimized methods for rendering massive amounts of geometry.
Ogre::Real getPageSize()
Gets the current page size.
const TBounds & getBounds() const
Gets the current geometry boundary.
void reloadGeometryPage(const Ogre::Vector3 &point)
Reloads geometry at the given location.
TreeLoader2D(PagedGeometry *geom, const TBounds &bounds)
Creates a new TreeLoader2D object.
void * heightFunctionUserData
void deleteTrees(const Ogre::Vector3 &position, Ogre::Real radius=0.001f, Ogre::Entity *type=NULL)
Deletes trees within a certain radius of the given coordinates.
std::pair< Ogre::Entity *, std::vector< TreeDef > * > PageGridListValue
void setColorMap(const Ogre::String &mapFile, MapChannel channel=CHANNEL_COLOR)
Sets the color map used to color trees.
std::vector< TreeDef > & _getGridPage(std::vector< TreeDef > *grid, int x, int z)
void loadPage(PageInfo &page)
This should be overridden to load a specified region of entities.
std::map< Ogre::Entity *, std::vector< TreeDef > * > pageGridList
void addTree(Ogre::Entity *entity, const Ogre::Vector3 &position, Ogre::Degree yaw=Ogre::Degree(0), Ogre::Real scale=1.0f, void *userData=NULL)
Adds an entity to the scene with the specified location, rotation, and scale.
Ogre::Real(* heightFunction)(Ogre::Real x, Ogre::Real z, void *userData)
std::map< Ogre::Entity *, std::vector< TreeDef > * >::iterator PageGridListIterator
@ MAPFILTER_NONE
Use no filtering - fast, but may appear blocky.
Ogre::TRect< Ogre::Real > TBounds
Define TBounds as a TRect using Real numeric units.
MapChannel
Specifies which color channel(s) to extract from an image.
Useful page information supplied to a pageloader.
int zIndex
The Z index of the page tile.
TBounds bounds
The page boundaries in which all entities should be placed.
int xIndex
The X index of the page tile.