1 // Copyright (C) 2009-2012 Christian Stehno
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __S_VERTEX_MANIPULATOR_H_INCLUDED__
\r
6 #define __S_VERTEX_MANIPULATOR_H_INCLUDED__
\r
8 #include "S3DVertex.h"
\r
20 //! Interface for vertex manipulators.
\r
21 /** You should derive your manipulator from this class if it shall be called for every vertex, getting as parameter just the vertex.
\r
23 struct IVertexManipulator
\r
26 //! Vertex manipulator to set color to a fixed color for all vertices
\r
27 class SVertexColorSetManipulator : public IVertexManipulator
\r
30 SVertexColorSetManipulator(video::SColor color) : Color(color) {}
\r
31 void operator()(video::S3DVertex& vertex) const
\r
36 video::SColor Color;
\r
38 //! Vertex manipulator to set the alpha value of the vertex color to a fixed value
\r
39 class SVertexColorSetAlphaManipulator : public IVertexManipulator
\r
42 SVertexColorSetAlphaManipulator(u32 alpha) : Alpha(alpha) {}
\r
43 void operator()(video::S3DVertex& vertex) const
\r
45 vertex.Color.setAlpha(Alpha);
\r
50 //! Vertex manipulator which inverts the RGB values
\r
51 class SVertexColorInvertManipulator : public IVertexManipulator
\r
54 void operator()(video::S3DVertex& vertex) const
\r
56 vertex.Color.setRed(255-vertex.Color.getRed());
\r
57 vertex.Color.setGreen(255-vertex.Color.getGreen());
\r
58 vertex.Color.setBlue(255-vertex.Color.getBlue());
\r
61 //! Vertex manipulator to set vertex color to one of two values depending on a given threshold
\r
62 /** If average of the color value is >Threshold the High color is chosen, else Low. */
\r
63 class SVertexColorThresholdManipulator : public IVertexManipulator
\r
66 SVertexColorThresholdManipulator(u8 threshold, video::SColor low,
\r
67 video::SColor high) : Threshold(threshold), Low(low), High(high) {}
\r
68 void operator()(video::S3DVertex& vertex) const
\r
70 vertex.Color = ((u8)vertex.Color.getAverage()>Threshold)?High:Low;
\r
77 //! Vertex manipulator which adjusts the brightness by the given amount
\r
78 /** A positive value increases brightness, a negative value darkens the colors. */
\r
79 class SVertexColorBrightnessManipulator : public IVertexManipulator
\r
82 SVertexColorBrightnessManipulator(s32 amount) : Amount(amount) {}
\r
83 void operator()(video::S3DVertex& vertex) const
\r
85 vertex.Color.setRed(core::clamp(vertex.Color.getRed()+Amount, 0u, 255u));
\r
86 vertex.Color.setGreen(core::clamp(vertex.Color.getGreen()+Amount, 0u, 255u));
\r
87 vertex.Color.setBlue(core::clamp(vertex.Color.getBlue()+Amount, 0u, 255u));
\r
92 //! Vertex manipulator which adjusts the contrast by the given factor
\r
93 /** Factors over 1 increase contrast, below 1 reduce it. */
\r
94 class SVertexColorContrastManipulator : public IVertexManipulator
\r
97 SVertexColorContrastManipulator(f32 factor) : Factor(factor) {}
\r
98 void operator()(video::S3DVertex& vertex) const
\r
100 vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+128, 0, 255));
\r
101 vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+128, 0, 255));
\r
102 vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+128, 0, 255));
\r
107 //! Vertex manipulator which adjusts the contrast by the given factor and brightness by a signed amount.
\r
108 /** Factors over 1 increase contrast, below 1 reduce it.
\r
109 A positive amount increases brightness, a negative one darkens the colors. */
\r
110 class SVertexColorContrastBrightnessManipulator : public IVertexManipulator
\r
113 SVertexColorContrastBrightnessManipulator(f32 factor, s32 amount) : Factor(factor), Amount(amount+128) {}
\r
114 void operator()(video::S3DVertex& vertex) const
\r
116 vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+Amount, 0, 255));
\r
117 vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+Amount, 0, 255));
\r
118 vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+Amount, 0, 255));
\r
124 //! Vertex manipulator which adjusts the brightness by a gamma operation
\r
125 /** A value over one increases brightness, one below darkens the colors. */
\r
126 class SVertexColorGammaManipulator : public IVertexManipulator
\r
129 SVertexColorGammaManipulator(f32 gamma) : Gamma(1.f)
\r
134 void operator()(video::S3DVertex& vertex) const
\r
136 vertex.Color.setRed(core::clamp(core::round32(powf((f32)(vertex.Color.getRed()),Gamma)), 0, 255));
\r
137 vertex.Color.setGreen(core::clamp(core::round32(powf((f32)(vertex.Color.getGreen()),Gamma)), 0, 255));
\r
138 vertex.Color.setBlue(core::clamp(core::round32(powf((f32)(vertex.Color.getBlue()),Gamma)), 0, 255));
\r
143 //! Vertex manipulator which scales the color values
\r
144 /** Can e.g be used for white balance, factor would be 255.f/brightest color. */
\r
145 class SVertexColorScaleManipulator : public IVertexManipulator
\r
148 SVertexColorScaleManipulator(f32 factor) : Factor(factor) {}
\r
149 void operator()(video::S3DVertex& vertex) const
\r
151 vertex.Color.setRed(core::clamp(core::round32(vertex.Color.getRed()*Factor), 0, 255));
\r
152 vertex.Color.setGreen(core::clamp(core::round32(vertex.Color.getGreen()*Factor), 0, 255));
\r
153 vertex.Color.setBlue(core::clamp(core::round32(vertex.Color.getBlue()*Factor), 0, 255));
\r
158 //! Vertex manipulator which desaturates the color values
\r
159 /** Uses the lightness value of the color. */
\r
160 class SVertexColorDesaturateToLightnessManipulator : public IVertexManipulator
\r
163 void operator()(video::S3DVertex& vertex) const
\r
165 vertex.Color=core::round32(vertex.Color.getLightness());
\r
168 //! Vertex manipulator which desaturates the color values
\r
169 /** Uses the average value of the color. */
\r
170 class SVertexColorDesaturateToAverageManipulator : public IVertexManipulator
\r
173 void operator()(video::S3DVertex& vertex) const
\r
175 vertex.Color=vertex.Color.getAverage();
\r
178 //! Vertex manipulator which desaturates the color values
\r
179 /** Uses the luminance value of the color. */
\r
180 class SVertexColorDesaturateToLuminanceManipulator : public IVertexManipulator
\r
183 void operator()(video::S3DVertex& vertex) const
\r
185 vertex.Color=core::round32(vertex.Color.getLuminance());
\r
188 //! Vertex manipulator which interpolates the color values
\r
189 /** Uses linear interpolation. */
\r
190 class SVertexColorInterpolateLinearManipulator : public IVertexManipulator
\r
193 SVertexColorInterpolateLinearManipulator(video::SColor color, f32 factor) :
\r
194 Color(color), Factor(factor) {}
\r
195 void operator()(video::S3DVertex& vertex) const
\r
197 vertex.Color=vertex.Color.getInterpolated(Color, Factor);
\r
200 video::SColor Color;
\r
203 //! Vertex manipulator which interpolates the color values
\r
204 /** Uses linear interpolation. */
\r
205 class SVertexColorInterpolateQuadraticManipulator : public IVertexManipulator
\r
208 SVertexColorInterpolateQuadraticManipulator(video::SColor color1, video::SColor color2, f32 factor) :
\r
209 Color1(color1), Color2(color2), Factor(factor) {}
\r
210 void operator()(video::S3DVertex& vertex) const
\r
212 vertex.Color=vertex.Color.getInterpolated_quadratic(Color1, Color2, Factor);
\r
215 video::SColor Color1;
\r
216 video::SColor Color2;
\r
220 //! Vertex manipulator which scales the position of the vertex
\r
221 class SVertexPositionScaleManipulator : public IVertexManipulator
\r
224 SVertexPositionScaleManipulator(const core::vector3df& factor) : Factor(factor) {}
\r
225 template <typename VType>
\r
226 void operator()(VType& vertex) const
\r
228 vertex.Pos *= Factor;
\r
231 core::vector3df Factor;
\r
234 //! Vertex manipulator which scales the position of the vertex along the normals
\r
235 /** This can look more pleasing than the usual Scale operator, but
\r
236 depends on the mesh geometry.
\r
238 class SVertexPositionScaleAlongNormalsManipulator : public IVertexManipulator
\r
241 SVertexPositionScaleAlongNormalsManipulator(const core::vector3df& factor) : Factor(factor) {}
\r
242 template <typename VType>
\r
243 void operator()(VType& vertex) const
\r
245 vertex.Pos += vertex.Normal*Factor;
\r
248 core::vector3df Factor;
\r
251 //! Vertex manipulator which transforms the position of the vertex
\r
252 class SVertexPositionTransformManipulator : public IVertexManipulator
\r
255 SVertexPositionTransformManipulator(const core::matrix4& m) : Transformation(m) {}
\r
256 template <typename VType>
\r
257 void operator()(VType& vertex) const
\r
259 Transformation.transformVect(vertex.Pos);
\r
262 core::matrix4 Transformation;
\r
265 //! Vertex manipulator which transforms the normal of the vertex
\r
266 class SVertexNormalTransformManipulator : public IVertexManipulator
\r
269 SVertexNormalTransformManipulator(const core::matrix4& m) : Transformation(m) {}
\r
270 template <typename VType>
\r
271 void operator()(VType& vertex) const
\r
273 Transformation.transformVect(vertex.Normal);
\r
276 core::matrix4 Transformation;
\r
279 //! Vertex manipulator which scales the TCoords of the vertex
\r
280 class SVertexTCoordsScaleManipulator : public IVertexManipulator
\r
283 SVertexTCoordsScaleManipulator(const core::vector2df& factor, u32 uvSet=1) : Factor(factor), UVSet(uvSet) {}
\r
284 void operator()(video::S3DVertex2TCoords& vertex) const
\r
287 vertex.TCoords *= Factor;
\r
289 vertex.TCoords2 *= Factor;
\r
291 template <typename VType>
\r
292 void operator()(VType& vertex) const
\r
295 vertex.TCoords *= Factor;
\r
298 core::vector2df Factor;
\r
302 } // end namespace scene
\r
303 } // end namespace irr
\r