#ifndef __S_VERTEX_MANIPULATOR_H_INCLUDED__
#define __S_VERTEX_MANIPULATOR_H_INCLUDED__
#include "S3DVertex.h"
#include "SColor.h"
namespace irr
{
namespace scene
{
class IMesh;
class IMeshBuffer;
struct SMesh;
struct IVertexManipulator
{
};
class SVertexColorSetManipulator : public IVertexManipulator
{
public:
SVertexColorSetManipulator(video::SColor color) : Color(color) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=Color;
}
private:
video::SColor Color;
};
class SVertexColorSetAlphaManipulator : public IVertexManipulator
{
public:
SVertexColorSetAlphaManipulator(u32 alpha) : Alpha(alpha) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setAlpha(Alpha);
}
private:
u32 Alpha;
};
class SVertexColorInvertManipulator : public IVertexManipulator
{
public:
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(255-vertex.Color.getRed());
vertex.Color.setGreen(255-vertex.Color.getGreen());
vertex.Color.setBlue(255-vertex.Color.getBlue());
}
};
class SVertexColorThresholdManipulator : public IVertexManipulator
{
public:
SVertexColorThresholdManipulator(u8 threshold, video::SColor low,
video::SColor high) : Threshold(threshold), Low(low), High(high) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color = ((u8)vertex.Color.getAverage()>Threshold)?High:Low;
}
private:
u8 Threshold;
video::SColor Low;
video::SColor High;
};
class SVertexColorBrightnessManipulator : public IVertexManipulator
{
public:
SVertexColorBrightnessManipulator(s32 amount) : Amount(amount) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(vertex.Color.getRed()+Amount, 0u, 255u));
vertex.Color.setGreen(core::clamp(vertex.Color.getGreen()+Amount, 0u, 255u));
vertex.Color.setBlue(core::clamp(vertex.Color.getBlue()+Amount, 0u, 255u));
}
private:
s32 Amount;
};
class SVertexColorContrastManipulator : public IVertexManipulator
{
public:
SVertexColorContrastManipulator(f32 factor) : Factor(factor) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+128, 0, 255));
vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+128, 0, 255));
vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+128, 0, 255));
}
private:
f32 Factor;
};
class SVertexColorContrastBrightnessManipulator : public IVertexManipulator
{
public:
SVertexColorContrastBrightnessManipulator(f32 factor, s32 amount) : Factor(factor), Amount(amount+128) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+Amount, 0, 255));
vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+Amount, 0, 255));
vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+Amount, 0, 255));
}
private:
f32 Factor;
s32 Amount;
};
class SVertexColorGammaManipulator : public IVertexManipulator
{
public:
SVertexColorGammaManipulator(f32 gamma) : Gamma(1.f)
{
if (gamma != 0.f)
Gamma = 1.f/gamma;
}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(core::round32(powf((f32)(vertex.Color.getRed()),Gamma)), 0, 255));
vertex.Color.setGreen(core::clamp(core::round32(powf((f32)(vertex.Color.getGreen()),Gamma)), 0, 255));
vertex.Color.setBlue(core::clamp(core::round32(powf((f32)(vertex.Color.getBlue()),Gamma)), 0, 255));
}
private:
f32 Gamma;
};
class SVertexColorScaleManipulator : public IVertexManipulator
{
public:
SVertexColorScaleManipulator(f32 factor) : Factor(factor) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(core::round32(vertex.Color.getRed()*Factor), 0, 255));
vertex.Color.setGreen(core::clamp(core::round32(vertex.Color.getGreen()*Factor), 0, 255));
vertex.Color.setBlue(core::clamp(core::round32(vertex.Color.getBlue()*Factor), 0, 255));
}
private:
f32 Factor;
};
class SVertexColorDesaturateToLightnessManipulator : public IVertexManipulator
{
public:
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=core::round32(vertex.Color.getLightness());
}
};
class SVertexColorDesaturateToAverageManipulator : public IVertexManipulator
{
public:
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=vertex.Color.getAverage();
}
};
class SVertexColorDesaturateToLuminanceManipulator : public IVertexManipulator
{
public:
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=core::round32(vertex.Color.getLuminance());
}
};
class SVertexColorInterpolateLinearManipulator : public IVertexManipulator
{
public:
SVertexColorInterpolateLinearManipulator(video::SColor color, f32 factor) :
Color(color), Factor(factor) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=vertex.Color.getInterpolated(Color, Factor);
}
private:
video::SColor Color;
f32 Factor;
};
class SVertexColorInterpolateQuadraticManipulator : public IVertexManipulator
{
public:
SVertexColorInterpolateQuadraticManipulator(video::SColor color1, video::SColor color2, f32 factor) :
Color1(color1), Color2(color2), Factor(factor) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=vertex.Color.getInterpolated_quadratic(Color1, Color2, Factor);
}
private:
video::SColor Color1;
video::SColor Color2;
f32 Factor;
};
class SVertexPositionScaleManipulator : public IVertexManipulator
{
public:
SVertexPositionScaleManipulator(const core::vector3df& factor) : Factor(factor) {}
template <typename VType>
void operator()(VType& vertex) const
{
vertex.Pos *= Factor;
}
private:
core::vector3df Factor;
};
class SVertexPositionScaleAlongNormalsManipulator : public IVertexManipulator
{
public:
SVertexPositionScaleAlongNormalsManipulator(const core::vector3df& factor) : Factor(factor) {}
template <typename VType>
void operator()(VType& vertex) const
{
vertex.Pos += vertex.Normal*Factor;
}
private:
core::vector3df Factor;
};
class SVertexPositionTransformManipulator : public IVertexManipulator
{
public:
SVertexPositionTransformManipulator(const core::matrix4& m) : Transformation(m) {}
template <typename VType>
void operator()(VType& vertex) const
{
Transformation.transformVect(vertex.Pos);
}
private:
core::matrix4 Transformation;
};
class SVertexTCoordsScaleManipulator : public IVertexManipulator
{
public:
SVertexTCoordsScaleManipulator(const core::vector2df& factor, u32 uvSet=1) : Factor(factor), UVSet(uvSet) {}
void operator()(video::S3DVertex2TCoords& vertex) const
{
if (1==UVSet)
vertex.TCoords *= Factor;
else if (2==UVSet)
vertex.TCoords2 *= Factor;
}
template <typename VType>
void operator()(VType& vertex) const
{
if (1==UVSet)
vertex.TCoords *= Factor;
}
private:
core::vector2df Factor;
u32 UVSet;
};
}
}
#endif