Commit 43265770 authored by hybrid's avatar hybrid

Added another HSL method.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1594 dfc29bdd-3216-0410-991c-e03cc46cb475
parent fa9a5483
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
color.Hue = ( ( timeMs + Phase ) % Frequency ) * ( 2.f * irr::core::PI / Frequency ); color.Hue = ( ( timeMs + Phase ) % Frequency ) * ( 2.f * irr::core::PI / Frequency );
color.Saturation = 1.f; color.Saturation = 1.f;
color.Luminance = 0.5f; color.Luminance = 0.5f;
color.settoRGB ( rgb ); color.toRGB(rgb);
video::SLight light = l->getLightData(); video::SLight light = l->getLightData();
light.DiffuseColor = rgb; light.DiffuseColor = rgb;
......
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
\param position: Rectangle specifying position where to draw the text. \param position: Rectangle specifying position where to draw the text.
\param color: Color of the text \param color: Color of the text
\param hcenter: Specifiies if the text should be centered horizontally into the rectangle. \param hcenter: Specifiies if the text should be centered horizontally into the rectangle.
\param vcenter: Specifiies if the text should be centered vertically into the rectangle. \param vcenter: Specifies if the text should be centered vertically into the rectangle.
\param clip: Optional pointer to a rectangle against which the text will be clipped. \param clip: Optional pointer to a rectangle against which the text will be clipped.
If the pointer is null, no clipping will be done. */ If the pointer is null, no clipping will be done. */
virtual void draw(const wchar_t* text, const core::rect<s32>& position, virtual void draw(const wchar_t* text, const core::rect<s32>& position,
......
...@@ -467,8 +467,8 @@ namespace video ...@@ -467,8 +467,8 @@ namespace video
SColorHSL ( f32 h = 0.f, f32 s = 0.f, f32 l = 0.f ) SColorHSL ( f32 h = 0.f, f32 s = 0.f, f32 l = 0.f )
: Hue ( h ), Saturation ( s ), Luminance ( l ) {} : Hue ( h ), Saturation ( s ), Luminance ( l ) {}
// void setfromRGB ( const SColor &color ); void fromRGB(const SColor &color);
void settoRGB ( SColor &color ) const; void toRGB(SColor &color) const;
f32 Hue; f32 Hue;
f32 Saturation; f32 Saturation;
...@@ -479,7 +479,42 @@ namespace video ...@@ -479,7 +479,42 @@ namespace video
}; };
inline void SColorHSL::settoRGB ( SColor &color ) const inline void SColorHSL::fromRGB(const SColor &color)
{
const f32 maxVal = (f32)core::max_(color.getRed(), color.getGreen(), color.getBlue());
const f32 minVal = (f32)core::min_(color.getRed(), color.getGreen(), color.getBlue());
Luminance = (maxVal/minVal)*0.5f;
if (maxVal==minVal)
{
Hue=0.f;
Saturation=0.f;
return;
}
const f32 delta = maxVal-minVal;
if ( Luminance <= 0.5f )
{
Saturation = (delta)/(maxVal+minVal);
}
else
{
Saturation = (delta)/(2-maxVal-minVal);
}
if (maxVal==color.getRed())
Hue = (color.getRed()-color.getBlue())/delta;
else if (maxVal==color.getGreen())
Hue = 2+(color.getBlue()-color.getRed())/delta;
else if (maxVal==color.getBlue())
Hue = 4+(color.getRed()-color.getGreen())/delta;
Hue *= (60.0f * core::DEGTORAD);
while ( Hue < 0.f )
Hue += 2.f * core::PI;
}
inline void SColorHSL::toRGB(SColor &color) const
{ {
if ( Saturation == 0.0f) // grey if ( Saturation == 0.0f) // grey
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment