basic/color/colorf.cpp

Go to the documentation of this file.
00001 #include "colorf.h"
00002 #include <math.h>
00003 #include "opengl/glos.h"
00004 #include <gl/gl.h>
00005 
00006 namespace Color
00007 {
00008 
00009 const Colorf black        ( 0.0000f,  0.0000f,  0.0000f );
00010 const Colorf blue         ( 0.0000f,  0.0000f,  1.0000f );
00011 const Colorf blue_50      ( 0.0000f,  0.0000f,  1.0000f, 0.5000f );
00012 const Colorf cyan         ( 0.0000f,  1.0000f,  1.0000f );
00013 const Colorf cyan_50      ( 0.0000f,  1.0000f,  1.0000f, 0.5000f );
00014 const Colorf green        ( 0.0000f,  1.0000f,  0.0000f );
00015 const Colorf green_50     ( 0.0000f,  1.0000f,  0.0000f, 0.5000f );
00016 const Colorf magenta      ( 1.0000f,  0.0000f,  1.0000f );
00017 const Colorf magenta_50   ( 1.0000f,  0.0000f,  1.0000f, 0.5000f );
00018 const Colorf opaque       ( 0.0000f,  0.0000f,  0.0000f, 1.0000f );
00019 const Colorf orange       ( 1.0000f,  0.5000f,  0.0000f );
00020 const Colorf red          ( 1.0000f,  0.0000f,  0.0000f );
00021 const Colorf red_50       ( 1.0000f,  0.0000f,  0.0000f, 0.5000f );
00022 const Colorf transparent  ( 0.0000f,  0.0000f,  0.0000f, 0.0000f );
00023 const Colorf white        ( 1.0000f,  1.0000f,  1.0000f );
00024 const Colorf white_50     ( 1.0000f,  1.0000f,  1.0000f, 0.5000f );
00025 const Colorf yellow       ( 1.0000f,  1.0000f,  0.0000f );
00026 const Colorf yellow_50    ( 1.0000f,  1.0000f,  0.0000f, 0.5000f );
00027 
00028 //=============================================================================
00029 // Colorf
00030 //
00031 // constructor for floating point colors
00032 //=============================================================================
00033 Colorf::Colorf( const float r, const float g, const float b, const float a ):
00034     r( r ),
00035     g( g ),
00036     b( b ),
00037     a( a )
00038 {
00039 }
00040    
00041 //=============================================================================
00042 // GlDraw
00043 //
00044 // sets the glColor to this color
00045 //=============================================================================
00046 void Colorf::GlDraw() const
00047 {
00048     ::glColor4f( r, g, b, a );
00049 }
00050 
00051 //=============================================================================
00052 // operator-
00053 //
00054 // componentwise subtraction
00055 //=============================================================================
00056 Colorf Colorf::operator-( const Colorf& right ) const
00057 {
00058     return Colorf( r - right.r, g - right.b, b - right.b, a - right.a );
00059 }
00060 
00061 //=============================================================================
00062 // operator*
00063 //
00064 // scalar multiplication
00065 //=============================================================================
00066 Colorf Colorf::operator*( const float f ) const
00067 {
00068     return Colorf( r * f, g * f, b * f, a * f );
00069 }
00070 
00071 //=============================================================================
00072 // MakeColorHSV
00073 //
00074 // creates a color out of HSV values
00075 //=============================================================================
00076 Colorf MakeColorHSV( const float hue, const float sat, const float val )
00077 {
00078     Colorf returnMe( 0.0f, 0.0f, 0.0f );
00079         float p;
00080     float q;
00081     float t;
00082         if( sat == 0 ) 
00083     {
00084                 // achromatic (grey)
00085                 returnMe.r = val;
00086         returnMe.g = val;
00087         returnMe.b = val;
00088                 return returnMe;
00089         }
00090 
00091     int sector = static_cast< int >( floor( hue / 60.0 ) );
00092     float remainder = hue / 60.0f - sector;
00093         p = val * ( 1 - sat );
00094         q = val * ( 1 - sat * remainder );
00095         t = val * ( 1 - sat * ( 1 - remainder ) );
00096         switch( sector ) 
00097     {
00098                 case 0:
00099                         returnMe.r = val;
00100                         returnMe.g = t;
00101                         returnMe.b = p;
00102                         break;
00103                 case 1:
00104                         returnMe.r = q;
00105                         returnMe.g = val;
00106                         returnMe.b = p;
00107                         break;
00108         case 2:
00109                         returnMe.r = p;
00110                         returnMe.g = val;
00111                         returnMe.b = t;
00112                         break;
00113                 case 3:
00114                         returnMe.r = p;
00115                         returnMe.g = q;
00116                         returnMe.b = val;
00117                         break;
00118                 case 4:
00119                         returnMe.r = t;
00120                         returnMe.g = p;
00121                         returnMe.b = val;
00122                         break;
00123                 default:                // case 5:
00124                         returnMe.r = val;
00125                         returnMe.g = p;
00126                         returnMe.b = q;
00127                         break;
00128         }
00129     return returnMe;
00130 }
00131 
00132 
00133 }

Generated on Sat Apr 1 21:30:30 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO