Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials
SVertexManipulator.h
Go to the documentation of this file.
1 // Copyright (C) 2009 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:
30  SVertexColorSetManipulator(video::SColor color) : Color(color) {}
31  void operator()(video::S3DVertex& vertex) const
32  {
33  vertex.Color=Color;
34  }
35  private:
36  video::SColor Color;
37  };
40  {
41  public:
42  SVertexColorSetAlphaManipulator(u32 alpha) : Alpha(alpha) {}
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:
129  SVertexColorGammaManipulator(f32 gamma) : Gamma(1.f)
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:
255  SVertexPositionTransformManipulator(const core::matrix4& m) : Transformation(m) {}
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  SVertexTCoordsScaleManipulator(const core::vector2df& factor, u32 uvSet=1) : Factor(factor), UVSet(uvSet) {}
271  {
272  if (1==UVSet)
273  vertex.TCoords *= Factor;
274  else if (2==UVSet)
275  vertex.TCoords2 *= Factor;
276  }
277  template <typename VType>
278  void operator()(VType& vertex) const
279  {
280  if (1==UVSet)
281  vertex.TCoords *= Factor;
282  }
283  private:
284  core::vector2df Factor;
285  u32 UVSet;
286  };
287 
288 } // end namespace scene
289 } // end namespace irr
290 
291 
292 #endif

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Tue Jun 5 2012 17:57:15 by Doxygen (1.8.1)