]> git.lizzy.rs Git - irrlicht.git/blob - include/SVertexManipulator.h
Get rid of various old compiler and platform checks
[irrlicht.git] / include / SVertexManipulator.h
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
4 \r
5 #ifndef __S_VERTEX_MANIPULATOR_H_INCLUDED__\r
6 #define __S_VERTEX_MANIPULATOR_H_INCLUDED__\r
7 \r
8 #include "matrix4.h"\r
9 #include "S3DVertex.h"\r
10 #include "SColor.h"\r
11 \r
12 namespace irr\r
13 {\r
14 namespace scene\r
15 {\r
16 \r
17         class IMesh;\r
18         class IMeshBuffer;\r
19         struct SMesh;\r
20 \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
23         */\r
24         struct IVertexManipulator\r
25         {\r
26         };\r
27         //! Vertex manipulator to set color to a fixed color for all vertices\r
28         class SVertexColorSetManipulator : public IVertexManipulator\r
29         {\r
30         public:\r
31                 SVertexColorSetManipulator(video::SColor color) : Color(color) {}\r
32                 void operator()(video::S3DVertex& vertex) const\r
33                 {\r
34                         vertex.Color=Color;\r
35                 }\r
36         private:\r
37                 video::SColor Color;\r
38         };\r
39         //! Vertex manipulator to set the alpha value of the vertex color to a fixed value\r
40         class SVertexColorSetAlphaManipulator : public IVertexManipulator\r
41         {\r
42         public:\r
43                 SVertexColorSetAlphaManipulator(u32 alpha) : Alpha(alpha) {}\r
44                 void operator()(video::S3DVertex& vertex) const\r
45                 {\r
46                         vertex.Color.setAlpha(Alpha);\r
47                 }\r
48         private:\r
49                 u32 Alpha;\r
50         };\r
51         //! Vertex manipulator which inverts the RGB values\r
52         class SVertexColorInvertManipulator : public IVertexManipulator\r
53         {\r
54         public:\r
55                 void operator()(video::S3DVertex& vertex) const\r
56                 {\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
60                 }\r
61         };\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
65         {\r
66         public:\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
70                 {\r
71                         vertex.Color = ((u8)vertex.Color.getAverage()>Threshold)?High:Low;\r
72                 }\r
73         private:\r
74                 u8 Threshold;\r
75                 video::SColor Low;\r
76                 video::SColor High;\r
77         };\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
81         {\r
82         public:\r
83                 SVertexColorBrightnessManipulator(s32 amount) : Amount(amount) {}\r
84                 void operator()(video::S3DVertex& vertex) const\r
85                 {\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
89                 }\r
90         private:\r
91                 s32 Amount;\r
92         };\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
96         {\r
97         public:\r
98                 SVertexColorContrastManipulator(f32 factor) : Factor(factor) {}\r
99                 void operator()(video::S3DVertex& vertex) const\r
100                 {\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
104                 }\r
105         private:\r
106                 f32 Factor;\r
107         };\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
112         {\r
113         public:\r
114                 SVertexColorContrastBrightnessManipulator(f32 factor, s32 amount) : Factor(factor), Amount(amount+128) {}\r
115                 void operator()(video::S3DVertex& vertex) const\r
116                 {\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
120                 }\r
121         private:\r
122                 f32 Factor;\r
123                 s32 Amount;\r
124         };\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
128         {\r
129         public:\r
130                 SVertexColorGammaManipulator(f32 gamma) : Gamma(1.f)\r
131                 {\r
132                         if (gamma != 0.f)\r
133                                 Gamma = 1.f/gamma;\r
134                 }\r
135                 void operator()(video::S3DVertex& vertex) const\r
136                 {\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
140                 }\r
141         private:\r
142                 f32 Gamma;\r
143         };\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
147         {\r
148         public:\r
149                 SVertexColorScaleManipulator(f32 factor) : Factor(factor) {}\r
150                 void operator()(video::S3DVertex& vertex) const\r
151                 {\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
155                 }\r
156         private:\r
157                 f32 Factor;\r
158         };\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
162         {\r
163         public:\r
164                 void operator()(video::S3DVertex& vertex) const\r
165                 {\r
166                         vertex.Color=core::round32(vertex.Color.getLightness());\r
167                 }\r
168         };\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
172         {\r
173         public:\r
174                 void operator()(video::S3DVertex& vertex) const\r
175                 {\r
176                         vertex.Color=vertex.Color.getAverage();\r
177                 }\r
178         };\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
182         {\r
183         public:\r
184                 void operator()(video::S3DVertex& vertex) const\r
185                 {\r
186                         vertex.Color=core::round32(vertex.Color.getLuminance());\r
187                 }\r
188         };\r
189         //! Vertex manipulator which interpolates the color values\r
190         /** Uses linear interpolation. */\r
191         class SVertexColorInterpolateLinearManipulator : public IVertexManipulator\r
192         {\r
193         public:\r
194                 SVertexColorInterpolateLinearManipulator(video::SColor color, f32 factor) :\r
195                   Color(color), Factor(factor) {}\r
196                 void operator()(video::S3DVertex& vertex) const\r
197                 {\r
198                         vertex.Color=vertex.Color.getInterpolated(Color, Factor);\r
199                 }\r
200         private:\r
201                 video::SColor Color;\r
202                 f32 Factor;\r
203         };\r
204         //! Vertex manipulator which interpolates the color values\r
205         /** Uses linear interpolation. */\r
206         class SVertexColorInterpolateQuadraticManipulator : public IVertexManipulator\r
207         {\r
208         public:\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
212                 {\r
213                         vertex.Color=vertex.Color.getInterpolated_quadratic(Color1, Color2, Factor);\r
214                 }\r
215         private:\r
216                 video::SColor Color1;\r
217                 video::SColor Color2;\r
218                 f32 Factor;\r
219         };\r
220 \r
221         //! Vertex manipulator which scales the position of the vertex\r
222         class SVertexPositionScaleManipulator : public IVertexManipulator\r
223         {\r
224         public:\r
225                 SVertexPositionScaleManipulator(const core::vector3df& factor) : Factor(factor) {}\r
226                 template <typename VType>\r
227                 void operator()(VType& vertex) const\r
228                 {\r
229                         vertex.Pos *= Factor;\r
230                 }\r
231         private:\r
232                 core::vector3df Factor;\r
233         };\r
234 \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
238         */\r
239         class SVertexPositionScaleAlongNormalsManipulator : public IVertexManipulator\r
240         {\r
241         public:\r
242                 SVertexPositionScaleAlongNormalsManipulator(const core::vector3df& factor) : Factor(factor) {}\r
243                 template <typename VType>\r
244                 void operator()(VType& vertex) const\r
245                 {\r
246                         vertex.Pos += vertex.Normal*Factor;\r
247                 }\r
248         private:\r
249                 core::vector3df Factor;\r
250         };\r
251 \r
252         //! Vertex manipulator which transforms the position of the vertex\r
253         class SVertexPositionTransformManipulator : public IVertexManipulator\r
254         {\r
255         public:\r
256                 SVertexPositionTransformManipulator(const core::matrix4& m) : Transformation(m) {}\r
257                 template <typename VType>\r
258                 void operator()(VType& vertex) const\r
259                 {\r
260                         Transformation.transformVect(vertex.Pos);\r
261                 }\r
262         private:\r
263                 core::matrix4 Transformation;\r
264         };\r
265 \r
266         //! Vertex manipulator which transforms the normal of the vertex\r
267         class SVertexNormalTransformManipulator : public IVertexManipulator\r
268         {\r
269         public:\r
270                 SVertexNormalTransformManipulator(const core::matrix4& m) : Transformation(m) {}\r
271                 template <typename VType>\r
272                 void operator()(VType& vertex) const\r
273                 {\r
274                         Transformation.transformVect(vertex.Normal);\r
275                 }\r
276         private:\r
277                 core::matrix4 Transformation;\r
278         };\r
279 \r
280         //! Vertex manipulator which scales the TCoords of the vertex\r
281         class SVertexTCoordsScaleManipulator : public IVertexManipulator\r
282         {\r
283         public:\r
284                 SVertexTCoordsScaleManipulator(const core::vector2df& factor, u32 uvSet=1) : Factor(factor), UVSet(uvSet) {}\r
285                 void operator()(video::S3DVertex2TCoords& vertex) const\r
286                 {\r
287                         if (1==UVSet)\r
288                                 vertex.TCoords *= Factor;\r
289                         else if (2==UVSet)\r
290                                 vertex.TCoords2 *= Factor;\r
291                 }\r
292                 template <typename VType>\r
293                 void operator()(VType& vertex) const\r
294                 {\r
295                         if (1==UVSet)\r
296                                 vertex.TCoords *= Factor;\r
297                 }\r
298         private:\r
299                 core::vector2df Factor;\r
300                 u32 UVSet;\r
301         };\r
302 \r
303 } // end namespace scene\r
304 } // end namespace irr\r
305 \r
306 \r
307 #endif\r