Color Class Reference


Detailed Description

Represents a color with four components: red, green, blue, alpha.

Each component is represented by a 32 bit float value. The value 0 for the alpha means full transparency, while 1 means fully opaque.

Examples:

FixedFunctionMaterial/FixedFunctionMaterial.h, and ToonMaterial/ToonMaterial.h.

Definition at line 659 of file math.h.

#include <math.h>

List of all members.

Public Member Functions

  Color (float fRed=1.0f, float fGreen=1.0f, float fBlue=1.0f, float fAlpha=1.0f)
  Constructs a color object with specified values.
void  Set (float fRed, float fGreen, float fBlue, float fAlpha=1.0f)
  Sets the current value of the color.
  operator const float * (void) const
  Returns a pointer to the color data, which consists of four floats (R, G, B, and A).
float &  operator[] (unsigned int iChannel)
  Returns a color component based on its index.
  operator unsigned int (void) const
  Converts the color value into a singe 32 bit integer, where each component takes eight bits.
Color operator*= (const float f)
  Multiplies each component of the color with a single scalar value.
Color  operator* (float f) const
  Multiplies the color by a scalar value.
Color  operator/ (float f) const
  Divides the color by a scalar value.
Color  operator* (const Color &c) const
  Multiplies two colors and returns the result.
Color operator*= (const Color &c)
  Mutliplies two colors, puts the result into the current object, and returns it.
Color  operator+ (const Color &c) const
  Adds two colors and returns the result.
Color  operator- (const Color &c) const
  Subtracts two colors and returns the result.
Color operator+= (const Color &c)
  Adds two colors, puts the result into the current object, and returns it.
bool  operator== (const Color &c) const
  Returns true if the two colors are identical, false otherwise.
bool  operator!= (const Color &c) const
  Returns true if the two colors are different, false otherwise.
Color  Mix (const Color &c, float f) const
  Mix two colors based on a scalar value which should be within the range 0 and 1.
float  Luminance () const
  Returns the luminance value for the color.

Public Attributes

union {
   struct {
      float   m_fRed
      float   m_fGreen
      float   m_fBlue
      float   m_fAlpha
   } 
   struct {
      float   r
      float   g
      float   b
      float   a
   } 
   float   m_fData [4]
   double   m_dAlignDummy
   __m128   m_vAlignDummy
}; 

Static Public Attributes

static Color  black
static Color  white
static Color  red
static Color  green
static Color  blue
static Color  gray

Constructor & Destructor Documentation

Color ( float  fRed = 1.0f,
float  fGreen = 1.0f,
float  fBlue = 1.0f,
float  fAlpha = 1.0f 
) [inline]

Constructs a color object with specified values.

If no parameters used, the color will be white.

Definition at line 666 of file math.h.

    { m_fRed = fRed; m_fGreen = fGreen; m_fBlue = fBlue, m_fAlpha = fAlpha; };

Member Function Documentation

void Set ( float  fRed,
float  fGreen,
float  fBlue,
float  fAlpha = 1.0f 
) [inline]

Sets the current value of the color.

Definition at line 680 of file math.h.

    { r = fRed; g = fGreen; b = fBlue; a = fAlpha; };
operator const float * ( void  ) const [inline]

Returns a pointer to the color data, which consists of four floats (R, G, B, and A).

Do not delete this pointer.

Definition at line 686 of file math.h.

{ return &m_fRed; };
float& operator[] ( unsigned int  iChannel ) [inline]

Returns a color component based on its index.

Definition at line 689 of file math.h.

    { MB_ASSERT( iChannel < 4 ); return m_fData[iChannel]; };
operator unsigned int ( void  ) const [inline]

Converts the color value into a singe 32 bit integer, where each component takes eight bits.

This format is used by some external libraries.

Definition at line 694 of file math.h.

        { return (unsigned int)(0xff*m_fRed)+(((unsigned int)(0xff*m_fGreen))<<8)+
            (((unsigned int)(0xff*m_fBlue))<<16)+(((unsigned int)(0xff*m_fAlpha))<<24); };
Color& operator*= ( const float  f ) [inline]

Multiplies each component of the color with a single scalar value.

The alpha value is unchanged. The result is returned.

Definition at line 701 of file math.h.

{ r*=f; g*=f; b*=f; return *this; };
Color operator* ( float  f ) const [inline]

Multiplies the color by a scalar value.

Definition at line 704 of file math.h.

        { return Color( r*f, g*f, b*f, a*f ); };
Color operator/ ( float  f ) const [inline]

Divides the color by a scalar value.

Definition at line 708 of file math.h.

        { return operator *( 1/f ); };
Color operator* ( const Color c ) const [inline]

Multiplies two colors and returns the result.

Definition at line 712 of file math.h.

        { return Color( r*c.r, g*c.g, b*c.b, a*c.a ); };
Color& operator*= ( const Color c ) [inline]

Mutliplies two colors, puts the result into the current object, and returns it.

Definition at line 717 of file math.h.

    { r *= c.r; g *= c.g; b *= c.b; a *= c.a; return *this; };
Color operator+ ( const Color c ) const [inline]

Adds two colors and returns the result.

Definition at line 721 of file math.h.

        { return Color( r+c.r, g+c.g, b+c.b, a+c.a ); };
Color operator- ( const Color c ) const [inline]

Subtracts two colors and returns the result.

Definition at line 725 of file math.h.

        { return Color( r-c.r, g-c.g, b-c.b, a-c.a ); };
Color& operator+= ( const Color c ) [inline]

Adds two colors, puts the result into the current object, and returns it.

Definition at line 729 of file math.h.

    { r += c.r; g += c.g; b += c.b; a += c.a; return *this; };
bool operator== ( const Color c ) const [inline]

Returns true if the two colors are identical, false otherwise.

Definition at line 733 of file math.h.

        { return r == c.r && g == c.g && b == c.b && a == c.a; };
bool operator!= ( const Color c ) const [inline]

Returns true if the two colors are different, false otherwise.

Definition at line 737 of file math.h.

{ return !operator ==( c ); };
Color Mix ( const Color c,
float  f 
) const [inline]

Mix two colors based on a scalar value which should be within the range 0 and 1.

Return the result.

The scalar value controls how much of this color, and how much of the passed-in color are included in the mix. Setting the f value closer to 1 biases the result towards this color; setting the f value closer to zero biases the result towards the passed-in colour.

Definition at line 747 of file math.h.

    { return Color( r*f+c.r*(1-f), g*f+c.g*(1-f), b*f+c.b*(1-f), a*f+c.a*(1-f) ); };
float Luminance ( ) const [inline]

Returns the luminance value for the color.

Definition at line 751 of file math.h.

        { return 0.299f * r + 0.587f * g + 0.114f * b; }

Member Data Documentation

float m_fRed

Definition at line 762 of file math.h.

float m_fGreen

Definition at line 762 of file math.h.

float m_fBlue

Definition at line 762 of file math.h.

float m_fAlpha

Definition at line 762 of file math.h.

float r

Definition at line 763 of file math.h.

float g

Definition at line 763 of file math.h.

float b

Definition at line 763 of file math.h.

float a

Definition at line 763 of file math.h.

float m_fData[4]

Definition at line 764 of file math.h.

double m_dAlignDummy

Definition at line 766 of file math.h.

__m128 m_vAlignDummy

Definition at line 768 of file math.h.

Color black [static]

Definition at line 772 of file math.h.

Color white [static]

Definition at line 773 of file math.h.

Color red [static]

Definition at line 774 of file math.h.

Color green [static]

Definition at line 775 of file math.h.

Color blue [static]

Definition at line 776 of file math.h.

Color gray [static]

Definition at line 777 of file math.h.


The documentation for this class was generated from the following file:

Color Color Color Color Color Color Color Color Color Color
Color Color Color Color Color Color Color Color Color Color