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
9 #include "S3DVertex.h"
\r
21 //! Interface for vertex manipulators.
\r
22 /** You should derive your manipulator from this class if it shall be called for every vertex, getting as parameter just the vertex.
\r
24 struct IVertexManipulator
\r
27 //! Vertex manipulator to set color to a fixed color for all vertices
\r
28 class SVertexColorSetManipulator : public IVertexManipulator
\r
31 SVertexColorSetManipulator(video::SColor color) : Color(color) {}
\r
32 void operator()(video::S3DVertex& vertex) const
\r
37 video::SColor Color;
\r
39 //! Vertex manipulator to set the alpha value of the vertex color to a fixed value
\r
40 class SVertexColorSetAlphaManipulator : public IVertexManipulator
\r
43 SVertexColorSetAlphaManipulator(u32 alpha) : Alpha(alpha) {}
\r
44 void operator()(video::S3DVertex& vertex) const
\r
46 vertex.Color.setAlpha(Alpha);
\r
51 //! Vertex manipulator which inverts the RGB values
\r
52 class SVertexColorInvertManipulator : public IVertexManipulator
\r
55 void operator()(video::S3DVertex& vertex) const
\r
57 vertex.Color.setRed(255-vertex.Color.getRed());
\r
58 vertex.Color.setGreen(255-vertex.Color.getGreen());
\r
59 vertex.Color.setBlue(255-vertex.Color.getBlue());
\r
62 //! Vertex manipulator to set vertex color to one of two values depending on a given threshold
\r
63 /** If average of the color value is >Threshold the High color is chosen, else Low. */
\r
64 class SVertexColorThresholdManipulator : public IVertexManipulator
\r
67 SVertexColorThresholdManipulator(u8 threshold, video::SColor low,
\r
68 video::SColor high) : Threshold(threshold), Low(low), High(high) {}
\r
69 void operator()(video::S3DVertex& vertex) const
\r
71 vertex.Color = ((u8)vertex.Color.getAverage()>Threshold)?High:Low;
\r
78 //! Vertex manipulator which adjusts the brightness by the given amount
\r
79 /** A positive value increases brightness, a negative value darkens the colors. */
\r
80 class SVertexColorBrightnessManipulator : public IVertexManipulator
\r
83 SVertexColorBrightnessManipulator(s32 amount) : Amount(amount) {}
\r
84 void operator()(video::S3DVertex& vertex) const
\r
86 vertex.Color.setRed(core::clamp(vertex.Color.getRed()+Amount, 0u, 255u));
\r
87 vertex.Color.setGreen(core::clamp(vertex.Color.getGreen()+Amount, 0u, 255u));
\r
88 vertex.Color.setBlue(core::clamp(vertex.Color.getBlue()+Amount, 0u, 255u));
\r
93 //! Vertex manipulator which adjusts the contrast by the given factor
\r
94 /** Factors over 1 increase contrast, below 1 reduce it. */
\r
95 class SVertexColorContrastManipulator : public IVertexManipulator
\r
98 SVertexColorContrastManipulator(f32 factor) : Factor(factor) {}
\r
99 void operator()(video::S3DVertex& vertex) const
\r
101 vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+128, 0, 255));
\r
102 vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+128, 0, 255));
\r
103 vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+128, 0, 255));
\r
108 //! Vertex manipulator which adjusts the contrast by the given factor and brightness by a signed amount.
\r
109 /** Factors over 1 increase contrast, below 1 reduce it.
\r
110 A positive amount increases brightness, a negative one darkens the colors. */
\r
111 class SVertexColorContrastBrightnessManipulator : public IVertexManipulator
\r
114 SVertexColorContrastBrightnessManipulator(f32 factor, s32 amount) : Factor(factor), Amount(amount+128) {}
\r
115 void operator()(video::S3DVertex& vertex) const
\r
117 vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+Amount, 0, 255));
\r
118 vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+Amount, 0, 255));
\r
119 vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+Amount, 0, 255));
\r
125 //! Vertex manipulator which adjusts the brightness by a gamma operation
\r
126 /** A value over one increases brightness, one below darkens the colors. */
\r
127 class SVertexColorGammaManipulator : public IVertexManipulator
\r
130 SVertexColorGammaManipulator(f32 gamma) : Gamma(1.f)
\r
135 void operator()(video::S3DVertex& vertex) const
\r
137 vertex.Color.setRed(core::clamp(core::round32(powf((f32)(vertex.Color.getRed()),Gamma)), 0, 255));
\r
138 vertex.Color.setGreen(core::clamp(core::round32(powf((f32)(vertex.Color.getGreen()),Gamma)), 0, 255));
\r
139 vertex.Color.setBlue(core::clamp(core::round32(powf((f32)(vertex.Color.getBlue()),Gamma)), 0, 255));
\r
144 //! Vertex manipulator which scales the color values
\r
145 /** Can e.g be used for white balance, factor would be 255.f/brightest color. */
\r
146 class SVertexColorScaleManipulator : public IVertexManipulator
\r
149 SVertexColorScaleManipulator(f32 factor) : Factor(factor) {}
\r
150 void operator()(video::S3DVertex& vertex) const
\r
152 vertex.Color.setRed(core::clamp(core::round32(vertex.Color.getRed()*Factor), 0, 255));
\r
153 vertex.Color.setGreen(core::clamp(core::round32(vertex.Color.getGreen()*Factor), 0, 255));
\r
154 vertex.Color.setBlue(core::clamp(core::round32(vertex.Color.getBlue()*Factor), 0, 255));
\r
159 //! Vertex manipulator which desaturates the color values
\r
160 /** Uses the lightness value of the color. */
\r
161 class SVertexColorDesaturateToLightnessManipulator : public IVertexManipulator
\r
164 void operator()(video::S3DVertex& vertex) const
\r
166 vertex.Color=core::round32(vertex.Color.getLightness());
\r
169 //! Vertex manipulator which desaturates the color values
\r
170 /** Uses the average value of the color. */
\r
171 class SVertexColorDesaturateToAverageManipulator : public IVertexManipulator
\r
174 void operator()(video::S3DVertex& vertex) const
\r
176 vertex.Color=vertex.Color.getAverage();
\r
179 //! Vertex manipulator which desaturates the color values
\r
180 /** Uses the luminance value of the color. */
\r
181 class SVertexColorDesaturateToLuminanceManipulator : public IVertexManipulator
\r
184 void operator()(video::S3DVertex& vertex) const
\r
186 vertex.Color=core::round32(vertex.Color.getLuminance());
\r
189 //! Vertex manipulator which interpolates the color values
\r
190 /** Uses linear interpolation. */
\r
191 class SVertexColorInterpolateLinearManipulator : public IVertexManipulator
\r
194 SVertexColorInterpolateLinearManipulator(video::SColor color, f32 factor) :
\r
195 Color(color), Factor(factor) {}
\r
196 void operator()(video::S3DVertex& vertex) const
\r
198 vertex.Color=vertex.Color.getInterpolated(Color, Factor);
\r
201 video::SColor Color;
\r
204 //! Vertex manipulator which interpolates the color values
\r
205 /** Uses linear interpolation. */
\r
206 class SVertexColorInterpolateQuadraticManipulator : public IVertexManipulator
\r
209 SVertexColorInterpolateQuadraticManipulator(video::SColor color1, video::SColor color2, f32 factor) :
\r
210 Color1(color1), Color2(color2), Factor(factor) {}
\r
211 void operator()(video::S3DVertex& vertex) const
\r
213 vertex.Color=vertex.Color.getInterpolated_quadratic(Color1, Color2, Factor);
\r
216 video::SColor Color1;
\r
217 video::SColor Color2;
\r
221 //! Vertex manipulator which scales the position of the vertex
\r
222 class SVertexPositionScaleManipulator : public IVertexManipulator
\r
225 SVertexPositionScaleManipulator(const core::vector3df& factor) : Factor(factor) {}
\r
226 template <typename VType>
\r
227 void operator()(VType& vertex) const
\r
229 vertex.Pos *= Factor;
\r
232 core::vector3df Factor;
\r
235 //! Vertex manipulator which scales the position of the vertex along the normals
\r
236 /** This can look more pleasing than the usual Scale operator, but
\r
237 depends on the mesh geometry.
\r
239 class SVertexPositionScaleAlongNormalsManipulator : public IVertexManipulator
\r
242 SVertexPositionScaleAlongNormalsManipulator(const core::vector3df& factor) : Factor(factor) {}
\r
243 template <typename VType>
\r
244 void operator()(VType& vertex) const
\r
246 vertex.Pos += vertex.Normal*Factor;
\r
249 core::vector3df Factor;
\r
252 //! Vertex manipulator which transforms the position of the vertex
\r
253 class SVertexPositionTransformManipulator : public IVertexManipulator
\r
256 SVertexPositionTransformManipulator(const core::matrix4& m) : Transformation(m) {}
\r
257 template <typename VType>
\r
258 void operator()(VType& vertex) const
\r
260 Transformation.transformVect(vertex.Pos);
\r
263 core::matrix4 Transformation;
\r
266 //! Vertex manipulator which transforms the normal of the vertex
\r
267 class SVertexNormalTransformManipulator : public IVertexManipulator
\r
270 SVertexNormalTransformManipulator(const core::matrix4& m) : Transformation(m) {}
\r
271 template <typename VType>
\r
272 void operator()(VType& vertex) const
\r
274 Transformation.transformVect(vertex.Normal);
\r
277 core::matrix4 Transformation;
\r
280 //! Vertex manipulator which scales the TCoords of the vertex
\r
281 class SVertexTCoordsScaleManipulator : public IVertexManipulator
\r
284 SVertexTCoordsScaleManipulator(const core::vector2df& factor, u32 uvSet=1) : Factor(factor), UVSet(uvSet) {}
\r
285 void operator()(video::S3DVertex2TCoords& vertex) const
\r
288 vertex.TCoords *= Factor;
\r
290 vertex.TCoords2 *= Factor;
\r
292 template <typename VType>
\r
293 void operator()(VType& vertex) const
\r
296 vertex.TCoords *= Factor;
\r
299 core::vector2df Factor;
\r
303 } // end namespace scene
\r
304 } // end namespace irr
\r