Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
PropertyMaps.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:
61. 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.
72. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
83. This notice may not be removed or altered from any source distribution.
9-------------------------------------------------------------------------------------*/
10#ifndef __PropertyMaps_H__
11#define __PropertyMaps_H__
12
13#include <OgrePrerequisites.h>
14#include <OgrePixelFormat.h>
15#include <OgreColourValue.h>
16#include <OgreRoot.h>
17#include <OgreRenderSystem.h>
18
19namespace Forests
20{
21
36
45
55 {
56 public:
57 static DensityMap *load(const Ogre::String &fileName, MapChannel channel = CHANNEL_COLOR);
58 static DensityMap *load(Ogre::TexturePtr texture, MapChannel channel = CHANNEL_COLOR);
59 void unload();
60
70 void setFilter(MapFilter filter) { this->filter = filter; }
71
74
85 Ogre::PixelBox getPixelBox()
86 {
87 assert(pixels);
88 return *pixels;
89 }
90
96 Ogre::Real getDensityAt(Ogre::Real x, Ogre::Real z, const Ogre::TRect<Ogre::Real> &mapBounds)
97 {
99 return _getDensityAt_Unfiltered(x, z, mapBounds);
100 else
101 return _getDensityAt_Bilinear(x, z, mapBounds);
102 }
103
104 Ogre::Real _getDensityAt_Unfiltered(Ogre::Real x, Ogre::Real z, const Ogre::TRect<Ogre::Real> &mapBounds);
105 Ogre::Real _getDensityAt_Bilinear(Ogre::Real x, Ogre::Real z, const Ogre::TRect<Ogre::Real> &mapBounds);
106
107 private:
108 DensityMap(Ogre::TexturePtr texture, MapChannel channel);
109 ~DensityMap();
110
111 static std::map<Ogre::String, DensityMap*> selfList;
112 Ogre::String selfKey;
113 Ogre::uint32 refCount;
114
116 Ogre::PixelBox *pixels;
117 };
118
128 {
129 public:
130 static ColorMap *load(const Ogre::String &fileName, MapChannel channel = CHANNEL_COLOR);
131 static ColorMap *load(Ogre::TexturePtr texture, MapChannel channel = CHANNEL_COLOR);
132 void unload();
133
143 void setFilter(MapFilter filter) { this->filter = filter; }
144
147
159 Ogre::PixelBox getPixelBox()
160 {
161 assert(pixels);
162 return *pixels;
163 }
164
173 Ogre::uint32 getColorAt(Ogre::Real x, Ogre::Real z, const Ogre::TRect<Ogre::Real> &mapBounds)
174 {
176 }
177
181 Ogre::ColourValue getColorAt_Unpacked(Ogre::Real x, Ogre::Real z, const Ogre::TRect<Ogre::Real> &mapBounds)
182 {
184 float r, g, b, a;
185 static Ogre::VertexElementType format = Ogre::Root::getSingleton().getRenderSystem()->getColourVertexElementType();
186 if (format == Ogre::VET_COLOUR_ARGB)
187 {
188 // 1/255 = 0,0039215686274509803921568627451
189 b = ((c) & 0xFF) * 0.0039215686f;
190 g = ((c >> 8) & 0xFF) * 0.0039215686f;
191 r = ((c >> 16) & 0xFF) * 0.0039215686f;
192 a = ((c >> 24) & 0xFF) * 0.0039215686f;
193 }
194 else
195 {
196 r = ((c) & 0xFF) * 0.0039215686f;
197 g = ((c >> 8) & 0xFF) * 0.0039215686f;
198 b = ((c >> 16) & 0xFF) * 0.0039215686f;
199 a = ((c >> 24) & 0xFF) * 0.0039215686f;
200 }
201
202 return Ogre::ColourValue(r, g, b, a);
203 }
204
205 private:
206 ColorMap(Ogre::TexturePtr map, MapChannel channel);
207 ~ColorMap();
208
209 static std::map<Ogre::String, ColorMap*> selfList;
210 Ogre::String selfKey;
211 Ogre::uint32 refCount;
212
213 //Directly interpolates two Ogre::uint32 colors
214 Ogre::uint32 _interpolateColor(Ogre::uint32 color1, Ogre::uint32 color2, Ogre::Real ratio, Ogre::Real ratioInv);
215
216 //Returns the color map value at the given location
217 Ogre::uint32 _getColorAt(Ogre::Real x, Ogre::Real z, const Ogre::TRect<Ogre::Real> &mapBounds);
218
219 //Returns the color map value at the given location with bilinear filtering
220 Ogre::uint32 _getColorAt_Bilinear(Ogre::Real x, Ogre::Real z, const Ogre::TRect<Ogre::Real> &mapBounds);
221
223 Ogre::PixelBox *pixels;
224 Ogre::TRect<Ogre::Real> mapBounds;
225 };
226
227}
228
229#endif
A 2D greyscale image that is assigned to a certain region of your world to represent color levels.
Ogre::PixelBox * pixels
Ogre::String selfKey
static ColorMap * load(const Ogre::String &fileName, MapChannel channel=CHANNEL_COLOR)
Ogre::uint32 _getColorAt_Bilinear(Ogre::Real x, Ogre::Real z, const Ogre::TRect< Ogre::Real > &mapBounds)
Ogre::uint32 _getColorAt(Ogre::Real x, Ogre::Real z, const Ogre::TRect< Ogre::Real > &mapBounds)
Ogre::PixelBox getPixelBox()
Gets a pointer to the pixel data of the color map.
void setFilter(MapFilter filter)
Sets the filtering mode used for this color map.
Ogre::uint32 getColorAt(Ogre::Real x, Ogre::Real z, const Ogre::TRect< Ogre::Real > &mapBounds)
Gets the color value at the specified position.
Ogre::TRect< Ogre::Real > mapBounds
static std::map< Ogre::String, ColorMap * > selfList
Ogre::uint32 refCount
Ogre::uint32 _interpolateColor(Ogre::uint32 color1, Ogre::uint32 color2, Ogre::Real ratio, Ogre::Real ratioInv)
static ColorMap * load(Ogre::TexturePtr texture, MapChannel channel=CHANNEL_COLOR)
MapFilter getFilter()
Returns the filtering mode being 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.
A 2D greyscale image that is assigned to a certain region of your world to represent density levels.
Ogre::Real _getDensityAt_Bilinear(Ogre::Real x, Ogre::Real z, const Ogre::TRect< Ogre::Real > &mapBounds)
static std::map< Ogre::String, DensityMap * > selfList
Ogre::PixelBox getPixelBox()
Gets a pointer to the pixel data of the density map.
Ogre::PixelBox * pixels
MapFilter getFilter()
Returns the filtering mode being used for this density map.
static DensityMap * load(Ogre::TexturePtr texture, MapChannel channel=CHANNEL_COLOR)
static DensityMap * load(const Ogre::String &fileName, MapChannel channel=CHANNEL_COLOR)
void setFilter(MapFilter filter)
Sets the filtering mode used for this density map.
Ogre::uint32 refCount
Ogre::Real _getDensityAt_Unfiltered(Ogre::Real x, Ogre::Real z, const Ogre::TRect< Ogre::Real > &mapBounds)
Ogre::String selfKey
Ogre::Real getDensityAt(Ogre::Real x, Ogre::Real z, const Ogre::TRect< Ogre::Real > &mapBounds)
Gets the density level at the specified position.
MapFilter
Specifies the filtering method used to interpret property maps.
@ MAPFILTER_NONE
Use no filtering - fast, but may appear blocky.
@ MAPFILTER_BILINEAR
Use bilinear filtering - slower, but will appear less blocky.
MapChannel
Specifies which color channel(s) to extract from an image.
@ CHANNEL_GREEN
Use only the image's green color channel.
@ CHANNEL_BLUE
Use only the image's blue color channel.
@ CHANNEL_ALPHA
Use only the image's alpha channel.
@ CHANNEL_RED
Use only the image's red color channel.
@ CHANNEL_COLOR
Use the image's full RGB color information.