- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | Static Public Attributes

# Color Class Reference

Search for all occurrences

## 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 662 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
static Color | transparent

## 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 669 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]`

Search for all occurrences

Sets the current value of the color.

Definition at line 683 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 689 of file math.h.

    { return &m_fRed; };

float& operator[] | ( | unsigned int | iChannel | ) | `[inline]`

Returns a color component based on its index.

Definition at line 692 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 697 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 704 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 707 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 711 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 715 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 720 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 724 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 728 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 732 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 736 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 740 of file math.h.

    { return !operator ==( c ); };

Color Mix | ( | const Color & | c,
|  | float | f
| ) |  | const `[inline]`

Search for all occurrences

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 750 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]`

Search for all occurrences

Returns the luminance value for the color.

Definition at line 754 of file math.h.

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

## Member Data Documentation

float m_fRed

Search for all occurrences

Definition at line 765 of file math.h.

float m_fGreen

Search for all occurrences

Definition at line 765 of file math.h.

float m_fBlue

Search for all occurrences

Definition at line 765 of file math.h.

float m_fAlpha

Search for all occurrences

Definition at line 765 of file math.h.

float r

Search for all occurrences

Definition at line 766 of file math.h.

float g

Search for all occurrences

Definition at line 766 of file math.h.

float b

Search for all occurrences

Definition at line 766 of file math.h.

float a

Search for all occurrences

Definition at line 766 of file math.h.

float m_fData[4]

Search for all occurrences

Definition at line 767 of file math.h.

double m_dAlignDummy

Search for all occurrences

Definition at line 769 of file math.h.

__m128 m_vAlignDummy

Search for all occurrences

Definition at line 771 of file math.h.

union { ... }

Search for all occurrences

Color black `[static]`

Search for all occurrences

Definition at line 775 of file math.h.

Color white `[static]`

Search for all occurrences

Definition at line 776 of file math.h.

Color red `[static]`

Search for all occurrences

Definition at line 777 of file math.h.

Color green `[static]`

Search for all occurrences

Definition at line 778 of file math.h.

Color blue `[static]`

Search for all occurrences

Definition at line 779 of file math.h.

Color gray `[static]`

Search for all occurrences

Definition at line 780 of file math.h.

Color transparent `[static]`

Search for all occurrences

Definition at line 781 of file math.h.

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

- Mudbox/math.h

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