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