21 #ifndef __RandomTreeLoader_H__
22 #define __RandomTreeLoader_H__
24 #include "RoRPrerequisites.h"
25 #include "PagedGeometry.h"
26 #include "PropertyMaps.h"
27 #include "TreeLoader2D.h"
40 RandomTreeLoader(PagedGeometry *geom,
const TBounds &bounds) : TreeLoader2D(geom, bounds)
51 page.xIndex -= Math::Floor(gridBounds.left / pageSize);
52 page.zIndex -= Math::Floor(gridBounds.top / pageSize);
55 if (page.xIndex < 0 || page.zIndex < 0 || page.xIndex >= pageGridX || page.zIndex >= pageGridZ)
59 std::vector<TreeDef> *pageGrid = pageGridList.begin()->second;
60 std::vector<TreeDef> &treeList = _getGridPage(pageGrid, page.xIndex, page.zIndex);
67 if (treeList.size() == 0)
70 for (
int n=0; n < pageSize/10; n++)
73 Real xrel = Math::RangeRandom(0, pageSize);
74 Real zrel = Math::RangeRandom(0, pageSize);
75 Degree yaw(Math::RangeRandom(0, 360));
76 Real scale = Math::RangeRandom(minimumScale, maximumScale);
79 tree.xPos = 65535 * (xrel - (page.xIndex * pageSize)) / pageSize;
80 tree.zPos = 65535 * (zrel - (page.zIndex * pageSize)) / pageSize;
81 tree.rotation = 255 * (yaw.valueDegrees() / 360.0f);
82 tree.scale = 255 * ((scale - minimumScale) / maximumScale);
83 treeList.push_back(tree);
88 TreeLoader2D::loadPage(page);
94 page.xIndex -= Math::Floor(gridBounds.left / pageSize);
95 page.zIndex -= Math::Floor(gridBounds.top / pageSize);
98 if (page.xIndex < 0 || page.zIndex < 0 || page.xIndex >= pageGridX || page.zIndex >= pageGridZ)
102 std::vector<TreeDef> *pageGrid = pageGridList.begin()->second;
103 std::vector<TreeDef> &treeList = _getGridPage(pageGrid, page.xIndex, page.zIndex);
107 while (i < treeList.size()){
109 #ifdef USE_PAGEDGEOMETRY_USER_DATA
110 deletedUserData.push_back(treeList[i].userData);
113 treeList[i] = treeList.back();
119 TreeLoader2D::unloadPage(page);