Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gfx/Color3

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)1996 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: Color3 1030 2004-02-11 20:46:17Z jungd $
00019   $Revision: 1.7 $
00020   $Date: 2004-02-11 15:46:17 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _GFX_COLOR3_
00026 #define _GFX_COLOR3_
00027 
00028 #include <gfx/gfx>
00029 
00030 #include <iostream>
00031 
00032 namespace gfx {
00033 
00034 class Color3 {
00035 
00036 public:
00037   Color3() { r=g=b=Real(0); }
00038   Color3(const String& name) { *this = lookupColor(name); }
00039   Color3(const Color3& c) { r=c.r; g=c.g; b=c.b; }
00040   Color3(Real rc, Real gc, Real bc)
00041     { r = rc; g = gc; b = bc; }
00042   ~Color3() {}
00043 
00044   Color3& operator=(const Color3& c)
00045   { r=c.r; g=c.g; b=c.b; return *this; }
00046 
00047   bool operator==(const Color3& c) const
00048   { return ((r==c.r) && (g==c.g) && (b==c.b)); }
00049 
00050   bool equals(const Color3& c, Real epsilon = consts::epsilon) const
00051   { return base::equals(r,c.r,epsilon) && base::equals(g,c.g,epsilon) && base::equals(b,c.b,epsilon); }
00052 
00053   void setZero() { r=g=b=Real(0); }
00054         
00055   Color3& operator*=(Real s) 
00056   { s=base::abs(s); if (s<1.0) { r*=s; g*=s; b*=s; } return *this; }
00057 
00058   static Color3 interpolate(const Color3& c1, const Color3& c2, Real t)
00059   { return Color3((1.0-t)*c1.r+t*c2.r,(1.0-t)*c1.g+t*c2.g,(1.0-t)*c1.b+t*c2.b); }
00060 
00061   Real* c_array() { return &r; }
00062 
00063   Real r,g,b;
00064   
00065 protected:
00066   struct ColorDatabaseEntry {
00067     base::Byte r,g,b;
00068     String name;
00069   };
00070 
00071   static ColorDatabaseEntry colorDatabase[];
00072   static Color3 lookupColor(const String& name);
00073   
00074 };
00075 
00076 inline Color3 operator*(const Color3& c, Real s)
00077 { Color3 r(c); r*=s; return r; }
00078 
00079 inline std::ostream& operator<<(std::ostream& out, const Color3& c) // Output
00080 { return out << "(" << c.r << "," << c.g << "," << c.b << ")"; }
00081 
00082 } // gfx
00083 
00084 #endif

Generated on Thu Jul 29 15:56:18 2004 for OpenSim by doxygen 1.3.6