Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
TreeLoader2D.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------------------
2Copyright (c) 2006 John Judnich
3
4This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
5Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
6 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
7 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
8 3. This notice may not be removed or altered from any source distribution.
9-------------------------------------------------------------------------------------*/
10
11#ifndef __TreeLoader2D_H__
12#define __TreeLoader2D_H__
13
14#include "PagedGeometry.h"
15#include "PropertyMaps.h"
16
17#include <OgrePrerequisites.h>
18
19
20namespace Forests {
21
52{
53public:
57 TreeLoader2D(PagedGeometry *geom, const TBounds &bounds);
59
78 void addTree(Ogre::Entity *entity, const Ogre::Vector3 &position, Ogre::Degree yaw = Ogre::Degree(0), Ogre::Real scale = 1.0f, void* userData = NULL);
79
88 void deleteTrees(const Ogre::Vector3 &position, Ogre::Real radius = 0.001f, Ogre::Entity *type = NULL);
89
96 void deleteTrees(TBounds area, Ogre::Entity *type = NULL);
97
130 void setHeightFunction(Ogre::Real (*heightFunction)(Ogre::Real x, Ogre::Real z, void *userData), void *userData = NULL)
131 {
133 heightFunctionUserData = userData;
134 }
135
149 void setColorMap(const Ogre::String &mapFile, MapChannel channel = CHANNEL_COLOR);
150
158 void setColorMap(Ogre::TexturePtr map, MapChannel channel = CHANNEL_COLOR);
159
170
181 {
182 colorMapFilter = filter;
183 if (colorMap)
185 }
186
196 void setMaximumScale(Ogre::Real maxScale) { maximumScale = maxScale; }
197
203 Ogre::Real getMaximumScale() const { return maximumScale; }
204
214 void setMinimumScale(Ogre::Real minScale) { minimumScale = minScale; }
215
221 Ogre::Real getMinimumScale() const { return minimumScale; }
222
227 const TBounds &getBounds() const { return actualBounds; }
228
229 void loadPage(PageInfo &page);
230
231private:
232
233 struct TreeDef
234 {
235 Ogre::uint16 xPos, zPos;
236 Ogre::uint8 scale, rotation;
237 };
238
239 //Information about the 2D grid of pages
241 Ogre::Real pageSize;
243
245
246 //Colormap
249
250 //Height data
251 Ogre::Real (*heightFunction)(Ogre::Real x, Ogre::Real z, void *userData); //Pointer to height function
253
254 //Misc.
256
257 //A std::map of 2D grid arrays. Each array is the same size (pageGridX x pageGridZ), and
258 //contains a std::vector list of trees. Each std::map entry corresponds to a single tree
259 //type, and every tree defined in the std::map entry's grid should be of that tree type.
260 std::map<Ogre::Entity*, std::vector<TreeDef>*> pageGridList;
261 typedef std::map<Ogre::Entity*, std::vector<TreeDef>*>::iterator PageGridListIterator;
262 typedef std::pair<Ogre::Entity*, std::vector<TreeDef>*> PageGridListValue;
263
264 inline std::vector<TreeDef> &_getGridPage(std::vector<TreeDef> *grid, int x, int z)
265 {
266 #ifdef _DEBUG
267 if(x >= pageGridX || z >= pageGridZ )
268 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
269 "Grid dimension is out of bounds",
270 "TreeLoader2D::_getGridPage()");
271 #endif
272
273 return grid[z * pageGridX + x];
274 }
275
276 inline void _setGridPage(std::vector<TreeDef> *grid, int x, int z, const std::vector<TreeDef> &page)
277 {
278 #ifdef _DEBUG
279 if(x >= pageGridX || z >= pageGridZ )
280 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
281 "Grid dimension is out of bounds",
282 "TreeLoader2D::_getGridPage()");
283 #endif
284
285 grid[z * pageGridX + x] = page;
286 }
287};
288
289
290
291} // namespace Forests
292
293#endif
A 2D greyscale image that is assigned to a certain region of your world to represent color levels.
void setFilter(MapFilter filter)
Sets the filtering mode used for this color map.
A class which you extend to provide a callback function for loading entities.
A class providing highly optimized methods for rendering massive amounts of geometry.
A PageLoader-derived object you can use with PagedGeometry to easily place trees on your terrain.
void setMaximumScale(Ogre::Real maxScale)
Sets the maximum tree scale value.
void setColorMapFilter(MapFilter filter)
Sets the filtering mode used for the color map.
void setMinimumScale(Ogre::Real minScale)
Sets the minimum tree scale value.
Ogre::Real getMinimumScale() const
Gets the minimum tree scale value.
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.
const TBounds & getBounds() const
Gets the tree boundary area.
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.
void setHeightFunction(Ogre::Real(*heightFunction)(Ogre::Real x, Ogre::Real z, void *userData), void *userData=NULL)
Sets the height function used to calculate tree height coordinates.
Ogre::Real getMaximumScale() const
Gets the maximum tree scale value.
std::vector< TreeDef > & _getGridPage(std::vector< TreeDef > *grid, int x, int z)
PagedGeometry * geom
void loadPage(PageInfo &page)
This should be overridden to load a specified region of entities.
void _setGridPage(std::vector< TreeDef > *grid, int x, int z, const std::vector< TreeDef > &page)
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)
ColorMap * getColorMap()
Gets a pointer to the color map being used.
std::map< Ogre::Entity *, std::vector< TreeDef > * >::iterator PageGridListIterator
MapFilter
Specifies the filtering method used to interpret property maps.
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.
@ CHANNEL_COLOR
Use the image's full RGB color information.
Useful page information supplied to a pageloader.