renderstack::color Class Reference

simple rgb triplet

#include <color.hpp>

Public Member Functions

 color (float r_, float g_, float b_)
 color (vec3 const &v)
float max_component () const
float min_component () const
vec3 hsv () const

Data Fields

float r
float g
float b

Detailed Description

Definition at line 36 of file color.hpp.


Constructor & Destructor Documentation

renderstack::color::color ( float  r_,
float  g_,
float  b_ 
) [inline]

Definition at line 39 of file color.hpp.

00040     :   r(r_)
00041     ,   g(g_)
00042     ,   b(b_)
00043     {
00044     }

renderstack::color::color ( vec3 const &  v  )  [inline]

Definition at line 46 of file color.hpp.

00047     :   r(v.x)
00048     ,   g(v.y)
00049     ,   b(v.y)
00050     {
00051     }


Member Function Documentation

float renderstack::color::max_component (  )  const

Definition at line 84 of file color.cpp.

00085 {
00086     float max;
00087 
00088     if(r > g)
00089     {
00090         max = r;
00091     }
00092     else
00093     {
00094         max = g;
00095     }
00096     if(b > max)
00097     {
00098         max = b;
00099     }
00100     return max;
00101 }

float renderstack::color::min_component (  )  const

Definition at line 103 of file color.cpp.

00104 {
00105     float min;
00106 
00107     if(r < g)
00108     {
00109         min = r;
00110     }
00111     else
00112     {
00113         min = g;
00114     }
00115     if(b < min)
00116     {
00117         min = b;
00118     }
00119     return min;
00120 }

vec3 renderstack::color::hsv (  )  const

Definition at line 122 of file color.cpp.

00123 {
00124     float h = 0;
00125     float s = 1.0f;
00126     float v = 1.0f;
00127     float max_v;
00128     float min_v;
00129     float diff;
00130     float r_dist;
00131     float g_dist;
00132     float b_dist;
00133     float undefined = 0;
00134 
00135     max_v = max_component();
00136     min_v = min_component();
00137     diff  = max_v - min_v;
00138     v     = max_v;
00139 
00140     if(RS_NEAR_ZERO(max_v))
00141     {
00142         s = 0;
00143     }
00144     else
00145     {
00146         s = diff / max_v;
00147     }
00148     if(s == 0)
00149     {
00150         h = undefined;
00151     }
00152     else
00153     {
00154         r_dist = (max_v - r) / diff;
00155         g_dist = (max_v - g) / diff;
00156         b_dist = (max_v - b) / diff;
00157         if(r == max_v)
00158         {
00159             h = b_dist - g_dist;
00160         }
00161         else
00162         {
00163             if(g == max_v)
00164             {
00165                 h = 2.0f + r_dist - b_dist;
00166             }
00167             else
00168             {
00169                 if(b == max_v)
00170                 {
00171                     h = 4.0f + g_dist - r_dist;
00172                 }
00173             }
00174         }
00175         h = h * 60.0f;
00176         if(h < 0)
00177         {
00178             h += 360.0f;
00179         }
00180     }
00181     return vec3(h, s, v);
00182 }


Field Documentation

Definition at line 58 of file color.hpp.

Definition at line 59 of file color.hpp.

Definition at line 60 of file color.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Apr 11 12:23:11 2010 for RenderStack by  doxygen 1.6.3