Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
SVertexManipulator.hpp
1// Copyright (C) 2009-2012 Christian Stehno
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in nirtcpp/nirtcpp.hpp
4
5#ifndef S_VERTEX_MANIPULATOR_HPP_INCLUDED
6#define S_VERTEX_MANIPULATOR_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/matrix4.hpp>
9#include <nirtcpp/core/engine/S3DVertex.hpp>
10#include <nirtcpp/core/engine/SColor.hpp>
11
12namespace nirt
13{
14namespace scene
15{
16
17 class IMesh;
18 class IMeshBuffer;
19 class SMesh;
20
22
25 {
26 };
29 {
30 public:
31 SVertexColorSetManipulator(video::SColor color) : Color(color) {}
32 void operator()(video::S3DVertex& vertex) const
33 {
34 vertex.Color=Color;
35 }
36 private:
37 video::SColor Color;
38 };
41 {
42 public:
43 SVertexColorSetAlphaManipulator(u32 alpha) : Alpha(alpha) {}
44 void operator()(video::S3DVertex& vertex) const
45 {
46 vertex.Color.setAlpha(Alpha);
47 }
48 private:
49 u32 Alpha;
50 };
53 {
54 public:
55 void operator()(video::S3DVertex& vertex) const
56 {
57 vertex.Color.setRed(255-vertex.Color.getRed());
58 vertex.Color.setGreen(255-vertex.Color.getGreen());
59 vertex.Color.setBlue(255-vertex.Color.getBlue());
60 }
61 };
63
65 {
66 public:
68 video::SColor high) : Threshold(threshold), Low(low), High(high) {}
69 void operator()(video::S3DVertex& vertex) const
70 {
71 vertex.Color = ((u8)vertex.Color.getAverage()>Threshold)?High:Low;
72 }
73 private:
74 u8 Threshold;
75 video::SColor Low;
76 video::SColor High;
77 };
79
81 {
82 public:
83 SVertexColorBrightnessManipulator(s32 amount) : Amount(amount) {}
84 void operator()(video::S3DVertex& vertex) const
85 {
86 vertex.Color.setRed(core::clamp(vertex.Color.getRed()+Amount, 0u, 255u));
87 vertex.Color.setGreen(core::clamp(vertex.Color.getGreen()+Amount, 0u, 255u));
88 vertex.Color.setBlue(core::clamp(vertex.Color.getBlue()+Amount, 0u, 255u));
89 }
90 private:
91 s32 Amount;
92 };
94
96 {
97 public:
98 SVertexColorContrastManipulator(f32 factor) : Factor(factor) {}
99 void operator()(video::S3DVertex& vertex) const
100 {
101 vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+128, 0, 255));
102 vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+128, 0, 255));
103 vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+128, 0, 255));
104 }
105 private:
106 f32 Factor;
107 };
109
112 {
113 public:
114 SVertexColorContrastBrightnessManipulator(f32 factor, s32 amount) : Factor(factor), Amount(amount+128) {}
115 void operator()(video::S3DVertex& vertex) const
116 {
117 vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+Amount, 0, 255));
118 vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+Amount, 0, 255));
119 vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+Amount, 0, 255));
120 }
121 private:
122 f32 Factor;
123 s32 Amount;
124 };
126
128 {
129 public:
130 SVertexColorGammaManipulator(f32 gamma) : Gamma(1.f)
131 {
132 if (gamma != 0.f)
133 Gamma = 1.f/gamma;
134 }
135 void operator()(video::S3DVertex& vertex) const
136 {
137 vertex.Color.setRed(core::clamp(core::round32(powf((f32)(vertex.Color.getRed()),Gamma)), 0, 255));
138 vertex.Color.setGreen(core::clamp(core::round32(powf((f32)(vertex.Color.getGreen()),Gamma)), 0, 255));
139 vertex.Color.setBlue(core::clamp(core::round32(powf((f32)(vertex.Color.getBlue()),Gamma)), 0, 255));
140 }
141 private:
142 f32 Gamma;
143 };
145
147 {
148 public:
149 SVertexColorScaleManipulator(f32 factor) : Factor(factor) {}
150 void operator()(video::S3DVertex& vertex) const
151 {
152 vertex.Color.setRed(core::clamp(core::round32(vertex.Color.getRed()*Factor), 0, 255));
153 vertex.Color.setGreen(core::clamp(core::round32(vertex.Color.getGreen()*Factor), 0, 255));
154 vertex.Color.setBlue(core::clamp(core::round32(vertex.Color.getBlue()*Factor), 0, 255));
155 }
156 private:
157 f32 Factor;
158 };
160
162 {
163 public:
164 void operator()(video::S3DVertex& vertex) const
165 {
166 vertex.Color=core::round32(vertex.Color.getLightness());
167 }
168 };
170
172 {
173 public:
174 void operator()(video::S3DVertex& vertex) const
175 {
176 vertex.Color=vertex.Color.getAverage();
177 }
178 };
180
182 {
183 public:
184 void operator()(video::S3DVertex& vertex) const
185 {
186 vertex.Color=core::round32(vertex.Color.getLuminance());
187 }
188 };
190
192 {
193 public:
195 Color(color), Factor(factor) {}
196 void operator()(video::S3DVertex& vertex) const
197 {
198 vertex.Color=vertex.Color.getInterpolated(Color, Factor);
199 }
200 private:
201 video::SColor Color;
202 f32 Factor;
203 };
205
207 {
208 public:
210 Color1(color1), Color2(color2), Factor(factor) {}
211 void operator()(video::S3DVertex& vertex) const
212 {
213 vertex.Color=vertex.Color.getInterpolated_quadratic(Color1, Color2, Factor);
214 }
215 private:
216 video::SColor Color1;
217 video::SColor Color2;
218 f32 Factor;
219 };
220
223 {
224 public:
225 SVertexPositionScaleManipulator(const core::vector3df& factor) : Factor(factor) {}
226 template <typename VType>
227 void operator()(VType& vertex) const
228 {
229 vertex.Pos *= Factor;
230 }
231 private:
232 core::vector3df Factor;
233 };
234
236
240 {
241 public:
242 SVertexPositionScaleAlongNormalsManipulator(const core::vector3df& factor) : Factor(factor) {}
243 template <typename VType>
244 void operator()(VType& vertex) const
245 {
246 vertex.Pos += vertex.Normal*Factor;
247 }
248 private:
249 core::vector3df Factor;
250 };
251
254 {
255 public:
256 SVertexPositionTransformManipulator(const core::matrix4& m) : Transformation(m) {}
257 template <typename VType>
258 void operator()(VType& vertex) const
259 {
260 Transformation.transformVect(vertex.Pos);
261 }
262 private:
263 core::matrix4 Transformation;
264 };
265
268 {
269 public:
270 SVertexNormalTransformManipulator(const core::matrix4& m) : Transformation(m) {}
271 template <typename VType>
272 void operator()(VType& vertex) const
273 {
274 Transformation.transformVect(vertex.Normal);
275 }
276 private:
277 core::matrix4 Transformation;
278 };
279
282 {
283 public:
284 SVertexNormalRotateScaleManipulator(const core::matrix4& m) : Transformation(m) {}
285 template <typename VType>
286 void operator()(VType& vertex) const
287 {
288 Transformation.rotateVect(vertex.Normal);
289 }
290 private:
291 core::matrix4 Transformation;
292 };
293
296 {
297 public:
299 template <typename VType>
300 void operator()(VType& vertex) const
301 {
302 vertex.Normal.normalize();
303 }
304 };
305
308 {
309 public:
310 SVertexTCoordsScaleManipulator(const core::vector2df& factor, u32 uvSet=1) : Factor(factor), UVSet(uvSet) {}
311 void operator()(video::S3DVertex2TCoords& vertex) const
312 {
313 if (1==UVSet)
314 vertex.TCoords *= Factor;
315 else if (2==UVSet)
316 vertex.TCoords2 *= Factor;
317 }
318 template <typename VType>
319 void operator()(VType& vertex) const
320 {
321 if (1==UVSet)
322 vertex.TCoords *= Factor;
323 }
324 private:
325 core::vector2df Factor;
326 u32 UVSet;
327 };
328
329} // end namespace scene
330} // end namespace nirt
331
332#endif
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.hpp:49
void rotateVect(vector3df &vect) const
Transform (rotate/scale) a vector by the rotation part of this matrix.
Definition matrix4.hpp:1188
void transformVect(vector3df &vect) const
Transforms the vector by this matrix.
Definition matrix4.hpp:1224
Interface for vertex manipulators.
Definition SVertexManipulator.hpp:25
Vertex manipulator which adjusts the brightness by the given amount.
Definition SVertexManipulator.hpp:81
Vertex manipulator which adjusts the contrast by the given factor and brightness by a signed amount.
Definition SVertexManipulator.hpp:112
Vertex manipulator which adjusts the contrast by the given factor.
Definition SVertexManipulator.hpp:96
Vertex manipulator which desaturates the color values.
Definition SVertexManipulator.hpp:172
Vertex manipulator which desaturates the color values.
Definition SVertexManipulator.hpp:162
Vertex manipulator which desaturates the color values.
Definition SVertexManipulator.hpp:182
Vertex manipulator which adjusts the brightness by a gamma operation.
Definition SVertexManipulator.hpp:128
Vertex manipulator which interpolates the color values.
Definition SVertexManipulator.hpp:192
Vertex manipulator which interpolates the color values.
Definition SVertexManipulator.hpp:207
Vertex manipulator which inverts the RGB values.
Definition SVertexManipulator.hpp:53
Vertex manipulator which scales the color values.
Definition SVertexManipulator.hpp:147
Vertex manipulator to set the alpha value of the vertex color to a fixed value.
Definition SVertexManipulator.hpp:41
Vertex manipulator to set color to a fixed color for all vertices.
Definition SVertexManipulator.hpp:29
Vertex manipulator to set vertex color to one of two values depending on a given threshold.
Definition SVertexManipulator.hpp:65
Vertex manipulator which transforms the normal of the vertex with the rotate/scale part of the given ...
Definition SVertexManipulator.hpp:282
Vertex manipulator which transforms the normal of the vertex.
Definition SVertexManipulator.hpp:268
Vertex manipulator which normalizes the normal of the vertex.
Definition SVertexManipulator.hpp:296
Vertex manipulator which scales the position of the vertex along the normals.
Definition SVertexManipulator.hpp:240
Vertex manipulator which scales the position of the vertex.
Definition SVertexManipulator.hpp:223
Vertex manipulator which transforms the position of the vertex.
Definition SVertexManipulator.hpp:254
Vertex manipulator which scales the TCoords of the vertex.
Definition SVertexManipulator.hpp:308
Vertex with two texture coordinates.
Definition S3DVertex.hpp:116
core::vector2d< f32 > TCoords2
Second set of texture coordinates.
Definition S3DVertex.hpp:153
standard vertex used by the Nirtcpp engine.
Definition S3DVertex.hpp:45
SColor Color
Color.
Definition S3DVertex.hpp:67
core::vector2d< f32 > TCoords
Texture coordinates.
Definition S3DVertex.hpp:70
Class representing a 32 bit ARGB color.
Definition SColor.hpp:317
f32 getLightness() const
Get lightness of the color in the range [0,255].
Definition SColor.hpp:354
u32 getAverage() const
Get average intensity of the color in the range [0,255].
Definition SColor.hpp:366
SColor getInterpolated_quadratic(const SColor &c1, const SColor &c2, f32 d) const
Returns interpolated color. ( quadratic )
Definition SColor.hpp:469
f32 getLuminance() const
Get luminance of the color in the range [0,255].
Definition SColor.hpp:360
u32 getGreen() const
Returns the green component of the color.
Definition SColor.hpp:346
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition SColor.hpp:455
u32 getRed() const
Returns the red component of the color.
Definition SColor.hpp:341
u32 getBlue() const
Returns the blue component of the color.
Definition SColor.hpp:351
void setRed(u32 r)
Sets the red component of the Color.
Definition SColor.hpp:379
void setAlpha(u32 a)
Sets the alpha component of the Color.
Definition SColor.hpp:374
void setGreen(u32 g)
Sets the green component of the Color.
Definition SColor.hpp:384
void setBlue(u32 b)
Sets the blue component of the Color.
Definition SColor.hpp:389
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned char u8
8 bit unsigned variable.
Definition irrTypes.hpp:24
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110

Nirtcpp    @cppfx.xyz

Utxcpp    utx::print