arsa  2.7
SVertexManipulator.h
Go to the documentation of this file.
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 irrlicht.h
4 
5 #ifndef __S_VERTEX_MANIPULATOR_H_INCLUDED__
6 #define __S_VERTEX_MANIPULATOR_H_INCLUDED__
7 
8 #include "S3DVertex.h"
9 #include "SColor.h"
10 
11 namespace irr
12 {
13 namespace scene
14 {
15 
16  class IMesh;
17  class IMeshBuffer;
18  struct SMesh;
19 
21 
24  {
25  };
28  {
29  public:
31  void operator()(video::S3DVertex& vertex) const
32  {
33  vertex.Color=Color;
34  }
35  private:
36  video::SColor Color;
37  };
40  {
41  public:
43  void operator()(video::S3DVertex& vertex) const
44  {
45  vertex.Color.setAlpha(Alpha);
46  }
47  private:
48  u32 Alpha;
49  };
52  {
53  public:
54  void operator()(video::S3DVertex& vertex) const
55  {
56  vertex.Color.setRed(255-vertex.Color.getRed());
57  vertex.Color.setGreen(255-vertex.Color.getGreen());
58  vertex.Color.setBlue(255-vertex.Color.getBlue());
59  }
60  };
62 
64  {
65  public:
67  video::SColor high) : Threshold(threshold), Low(low), High(high) {}
68  void operator()(video::S3DVertex& vertex) const
69  {
70  vertex.Color = ((u8)vertex.Color.getAverage()>Threshold)?High:Low;
71  }
72  private:
73  u8 Threshold;
74  video::SColor Low;
75  video::SColor High;
76  };
78 
80  {
81  public:
82  SVertexColorBrightnessManipulator(s32 amount) : Amount(amount) {}
83  void operator()(video::S3DVertex& vertex) const
84  {
85  vertex.Color.setRed(core::clamp(vertex.Color.getRed()+Amount, 0u, 255u));
86  vertex.Color.setGreen(core::clamp(vertex.Color.getGreen()+Amount, 0u, 255u));
87  vertex.Color.setBlue(core::clamp(vertex.Color.getBlue()+Amount, 0u, 255u));
88  }
89  private:
90  s32 Amount;
91  };
93 
95  {
96  public:
97  SVertexColorContrastManipulator(f32 factor) : Factor(factor) {}
98  void operator()(video::S3DVertex& vertex) const
99  {
100  vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+128, 0, 255));
101  vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+128, 0, 255));
102  vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+128, 0, 255));
103  }
104  private:
105  f32 Factor;
106  };
108 
111  {
112  public:
113  SVertexColorContrastBrightnessManipulator(f32 factor, s32 amount) : Factor(factor), Amount(amount+128) {}
114  void operator()(video::S3DVertex& vertex) const
115  {
116  vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+Amount, 0, 255));
117  vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+Amount, 0, 255));
118  vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+Amount, 0, 255));
119  }
120  private:
121  f32 Factor;
122  s32 Amount;
123  };
125 
127  {
128  public:
130  {
131  if (gamma != 0.f)
132  Gamma = 1.f/gamma;
133  }
134  void operator()(video::S3DVertex& vertex) const
135  {
136  vertex.Color.setRed(core::clamp(core::round32(powf((f32)(vertex.Color.getRed()),Gamma)), 0, 255));
137  vertex.Color.setGreen(core::clamp(core::round32(powf((f32)(vertex.Color.getGreen()),Gamma)), 0, 255));
138  vertex.Color.setBlue(core::clamp(core::round32(powf((f32)(vertex.Color.getBlue()),Gamma)), 0, 255));
139  }
140  private:
141  f32 Gamma;
142  };
144 
146  {
147  public:
148  SVertexColorScaleManipulator(f32 factor) : Factor(factor) {}
149  void operator()(video::S3DVertex& vertex) const
150  {
151  vertex.Color.setRed(core::clamp(core::round32(vertex.Color.getRed()*Factor), 0, 255));
152  vertex.Color.setGreen(core::clamp(core::round32(vertex.Color.getGreen()*Factor), 0, 255));
153  vertex.Color.setBlue(core::clamp(core::round32(vertex.Color.getBlue()*Factor), 0, 255));
154  }
155  private:
156  f32 Factor;
157  };
159 
161  {
162  public:
163  void operator()(video::S3DVertex& vertex) const
164  {
165  vertex.Color=core::round32(vertex.Color.getLightness());
166  }
167  };
169 
171  {
172  public:
173  void operator()(video::S3DVertex& vertex) const
174  {
175  vertex.Color=vertex.Color.getAverage();
176  }
177  };
179 
181  {
182  public:
183  void operator()(video::S3DVertex& vertex) const
184  {
185  vertex.Color=core::round32(vertex.Color.getLuminance());
186  }
187  };
189 
191  {
192  public:
194  Color(color), Factor(factor) {}
195  void operator()(video::S3DVertex& vertex) const
196  {
197  vertex.Color=vertex.Color.getInterpolated(Color, Factor);
198  }
199  private:
200  video::SColor Color;
201  f32 Factor;
202  };
204 
206  {
207  public:
209  Color1(color1), Color2(color2), Factor(factor) {}
210  void operator()(video::S3DVertex& vertex) const
211  {
212  vertex.Color=vertex.Color.getInterpolated_quadratic(Color1, Color2, Factor);
213  }
214  private:
215  video::SColor Color1;
216  video::SColor Color2;
217  f32 Factor;
218  };
219 
222  {
223  public:
224  SVertexPositionScaleManipulator(const core::vector3df& factor) : Factor(factor) {}
225  template <typename VType>
226  void operator()(VType& vertex) const
227  {
228  vertex.Pos *= Factor;
229  }
230  private:
231  core::vector3df Factor;
232  };
233 
235 
239  {
240  public:
242  template <typename VType>
243  void operator()(VType& vertex) const
244  {
245  vertex.Pos += vertex.Normal*Factor;
246  }
247  private:
248  core::vector3df Factor;
249  };
250 
253  {
254  public:
256  template <typename VType>
257  void operator()(VType& vertex) const
258  {
259  Transformation.transformVect(vertex.Pos);
260  }
261  private:
262  core::matrix4 Transformation;
263  };
264 
267  {
268  public:
269  SVertexNormalTransformManipulator(const core::matrix4& m) : Transformation(m) {}
270  template <typename VType>
271  void operator()(VType& vertex) const
272  {
273  Transformation.transformVect(vertex.Normal);
274  }
275  private:
276  core::matrix4 Transformation;
277  };
278 
281  {
282  public:
283  SVertexTCoordsScaleManipulator(const core::vector2df& factor, u32 uvSet=1) : Factor(factor), UVSet(uvSet) {}
285  {
286  if (1==UVSet)
287  vertex.TCoords *= Factor;
288  else if (2==UVSet)
289  vertex.TCoords2 *= Factor;
290  }
291  template <typename VType>
292  void operator()(VType& vertex) const
293  {
294  if (1==UVSet)
295  vertex.TCoords *= Factor;
296  }
297  private:
298  core::vector2df Factor;
299  u32 UVSet;
300  };
301 
302 } // end namespace scene
303 } // end namespace irr
304 
305 
306 #endif
REALINLINE s32 round32(f32 x)
Definition: irrMath.h:657
void setBlue(u32 b)
Sets the blue component of the Color.
Definition: SColor.h:389
void operator()(video::S3DVertex &vertex) const
core::vector2d< f32 > TCoords2
Second set of texture coordinates.
Definition: S3DVertex.h:148
void operator()(video::S3DVertex &vertex) const
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition: SColor.h:455
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
u32 getGreen() const
Returns the green component of the color.
Definition: SColor.h:346
Vertex manipulator which interpolates the color values.
const GLfloat * m
void setRed(u32 r)
Sets the red component of the Color.
Definition: SColor.h:379
Vertex manipulator which adjusts the brightness by a gamma operation.
f32 getLightness() const
Get lightness of the color in the range [0,255].
Definition: SColor.h:354
Vertex manipulator which desaturates the color values.
Vertex manipulator which inverts the RGB values.
Everything in the Irrlicht Engine can be found in this namespace.
Definition: CARSADPad.h:6
Vertex manipulator which interpolates the color values.
Vertex manipulator to set vertex color to one of two values depending on a given threshold.
SVertexPositionScaleManipulator(const core::vector3df &factor)
Vertex manipulator which scales the position of the vertex.
Vertex manipulator which desaturates the color values.
void operator()(video::S3DVertex &vertex) const
GLfloat GLfloat GLfloat alpha
void setAlpha(u32 a)
Sets the alpha component of the Color.
Definition: SColor.h:374
Vertex manipulator which adjusts the brightness by the given amount.
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:22
SVertexTCoordsScaleManipulator(const core::vector2df &factor, u32 uvSet=1)
Vertex manipulator which adjusts the contrast by the given factor and brightness by a signed amount.
Vertex with two texture coordinates.
Definition: S3DVertex.h:112
void operator()(video::S3DVertex &vertex) const
SVertexColorInterpolateQuadraticManipulator(video::SColor color1, video::SColor color2, f32 factor)
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
Vertex manipulator which transforms the position of the vertex.
GLfloat f
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
Interface for vertex manipulators.
void operator()(video::S3DVertex2TCoords &vertex) const
void operator()(video::S3DVertex &vertex) const
Vertex manipulator which scales the color values.
Vertex manipulator which adjusts the contrast by the given factor.
Vertex manipulator to set the alpha value of the vertex color to a fixed value.
void transformVect(vector3df &vect) const
Transforms the vector by this matrix.
Definition: matrix4.h:1192
standard vertex used by the Irrlicht engine.
Definition: S3DVertex.h:44
void setGreen(u32 g)
Sets the green component of the Color.
Definition: SColor.h:384
void operator()(video::S3DVertex &vertex) const
Vertex manipulator which scales the TCoords of the vertex.
SVertexColorInterpolateLinearManipulator(video::SColor color, f32 factor)
Class representing a 32 bit ARGB color.
Definition: SColor.h:316
Vertex manipulator which desaturates the color values.
SColor Color
Color.
Definition: S3DVertex.h:65
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition: matrix4.h:45
SVertexColorThresholdManipulator(u8 threshold, video::SColor low, video::SColor high)
void operator()(video::S3DVertex &vertex) const
f32 getLuminance() const
Get luminance of the color in the range [0,255].
Definition: SColor.h:360
SVertexPositionScaleAlongNormalsManipulator(const core::vector3df &factor)
GLuint color
void operator()(video::S3DVertex &vertex) const
Vertex manipulator to set color to a fixed color for all vertices.
core::vector2d< f32 > TCoords
Texture coordinates.
Definition: S3DVertex.h:68
void operator()(video::S3DVertex &vertex) const
u32 getRed() const
Returns the red component of the color.
Definition: SColor.h:341
u32 getBlue() const
Returns the blue component of the color.
Definition: SColor.h:351
u32 getAverage() const
Get average intensity of the color in the range [0,255].
Definition: SColor.h:366
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:167
SColor getInterpolated_quadratic(const SColor &c1, const SColor &c2, f32 d) const
Returns interpolated color. ( quadratic )
Definition: SColor.h:469
Vertex manipulator which transforms the normal of the vertex.
Vertex manipulator which scales the position of the vertex along the normals.