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

gfx/Color4

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: Color4 1030 2004-02-11 20:46:17Z jungd $
00019   $Revision: 1.4 $
00020   $Date: 2004-02-11 15:46:17 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _GFX_COLOR4_
00026 #define _GFX_COLOR4_
00027 
00028 #include <gfx/gfx>
00029 
00030 #include <gfx/Color3>
00031 
00032 namespace gfx {
00033 
00034 class Color4
00035 {
00036 
00037 public:
00038   Color4() { r=g=b=a=Real(0); }
00039   Color4(const Color4& c) { r=c.r; g=c.g; b=c.b; a=c.a; }
00040   Color4(const String& name, Real ac = Real(1)) { *this = Color3(name); a=ac; }
00041   Color4(const Color3& c) { r=c.r; g=c.g; b=c.b; a=Real(1); }
00042   Color4(Real rc, Real gc, Real bc, Real ac = Real(1))
00043   { r = rc; g = gc; b = bc; a = ac; }
00044   ~Color4() {}
00045 
00046   Color4& operator=(const Color4& c)
00047   { r=c.r; g=c.g; b=c.b; a=c.a; return *this; }
00048 
00049   Color4& operator=(const Color3& c)
00050   { r=c.r; g=c.g; b=c.b; a=Real(1); return *this; }
00051 
00052   bool operator==(const Color4& c) const
00053   { return ((r==c.r) && (g==c.g) && (b==c.b) && (a==c.a)); }
00054 
00055   bool equals(const Color4& c, Real epsilon = consts::epsilon) const
00056   { return base::equals(r,c.r,epsilon) && base::equals(g,c.g,epsilon) 
00057            && base::equals(b,c.b,epsilon) && base::equals(a,c.a,epsilon); }
00058 
00059   void setZero() { r=g=b=a=Real(0); }
00060         
00061   Color4& operator*=(Real s) 
00062   { s=base::abs(s); if (s<1.0) { r*=s; g*=s; b*=s; } return *this; }
00063   
00064   static Color4 interpolate(const Color4& c1, const Color4& c2, Real t)
00065   { return Color4((1.0-t)*c1.r+t*c2.r,(1.0-t)*c1.g+t*c2.g,(1.0-t)*c1.b+t*c2.b,(1.0-t)*c1.a+t*c2.a); }
00066 
00067   Real* c_array() { return &r; }
00068 
00069 
00070   Real r,g,b,a;
00071 
00072 };
00073 
00074 inline std::ostream& operator<<(std::ostream& out, const Color4& c) // Output
00075 { return out << "(" << c.r << "," << c.g << "," << c.b << "," << c.a << ")"; }
00076 
00077 } // gfx
00078 
00079 #endif

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