Class Color

3DS Max Plug-In SDK

Class Color

See Also: Class AColor, Structure BMM_Color_24, Structure BMM_Color_32, Structure BMM_Color_48, Structure BMM_Color_64, Structure BMM_Color_fl, Structure RealPixel.

class Color

Description:

This class represents color as three floating point values: r, g, and b. All methods of this class are implemented by the system.

Data Members:

public:

float r,g,b;

These values are in the range 0.0 to 1.0.

Methods:

Prototype:

Color()

Remarks:

Constructor. The resulting object should be initialized with one of the initialization methods.

Prototype:

Color(float R, float G, float B)

Remarks:

Constructor. Initializes the Color to the RGB color values passed.

Parameters:

float R

Specifies the red component of the color.

float G

Specifies the green component of the color.

float B

Specifies the blue component of the color.

Prototype:

Color(double R, double G, double B)

Remarks:

Constructor. Initializes the Color to the RGB color values passed.

Parameters:

double R

Specifies the red component of the color.

double G

Specifies the green component of the color.

double B

Specifies the blue component of the color.

Prototype:

Color(int R, int G, int B)

Remarks:

Constructor. Initializes the Color to the RGB color values passed.

Parameters:

int R

Specifies the red component of the color.

int G

Specifies the green component of the color.

int B

Specifies the blue component of the color.

Prototype:

Color(const Color& a)

Remarks:

Constructor. Initializes the Color to the Color passed.

Parameters:

Color& a

Specifies the initial color.

Prototype:

Color(DWORD rgb)

Remarks:

Constructor. Initializes the color to the Windows RGB value.

Parameters:

DWORD rgb

Specifies the initial color via a Windows RGB value.

Prototype:

Color(Point3 p)

Remarks:

Constructor. Initializes the Color to the value of the Point3 passed.

Parameters:

Point3 p

Specifies the color. r=x, g=y, b=z.

Prototype:

Color(float af[3])

Remarks:

Constructor. Initializes the color to the value passed.

Parameters:

float af[3]

Specifies the color. r=af[0], g=af[1], b=af[2].

Prototype:

Color(const BMM_Color_24& c);

Remarks:

This method is available in release 4.0 and later only.

Constructor. Initializes this Color from the 24 bit color value passed.

Parameters:

const BMM_Color_24& c

The 24 bit color to initialize from.

Prototype:

Color(const BMM_Color_32& c);

Remarks:

This method is available in release 4.0 and later only.

Constructor. Initializes this Color from the 32 bit color value passed.

Parameters:

const BMM_Color_32& c

The 32 bit color to initialize from.

Prototype:

Color(const BMM_Color_48& c);

Remarks:

This method is available in release 4.0 and later only.

Constructor. Initializes this Color from the 48 bit color value passed.

Parameters:

const BMM_Color_48& c

The 48 bit color to initialize from.

Prototype:

Color(const BMM_Color_64& c);

Remarks:

This method is available in release 4.0 and later only.

Constructor. Initializes this Color from the 64 bit color value passed.

Parameters:

const BMM_Color_64& c

The 64 bit color to initialize from.

Prototype:

Color(const BMM_Color_fl& c);

Remarks:

This method is available in release 4.0 and later only.

Constructor. Initializes this Color from the floating point color passed.

Parameters:

const BMM_Color_fl& c

The floating point color to initialize from. No conversion or scaling is done.

Prototype:

Color(RealPixel rp);

Remarks:

Constructor. Initializes the color to the RealPixel structure passed.

Parameters:

RealPixel rp

Specifies the RealPixel format to convert.

Prototype:

void Black()

Remarks:

Sets the Color to black. r = g = b = 0.0f

Prototype:

void White()

Remarks:

Sets the Color to white. r = g = b = 1.0f

Prototype:

void ClampMax()

Remarks:

Makes all the components of the Color <= 1.0

Prototype:

void ClampMin()

Remarks:

Makes all the components of the Color >= 0.0

Prototype:

void ClampMinMax()

Remarks:

Makes all the components fall in the range [0,1]

Prototype:

int MaxComponent(const Color&)

Remarks:

Returns the index of the component with the maximum absolute value.

Parameters:

const Color&

The color to check.

Return Value:

The index of the component with the maximum absolute value. r=0, g=1, b=2.

Prototype:

int MinComponent(const Color&)

Remarks:

Returns the index of the component with the minimum absolute value

Parameters:

const Color&

The color to check.

Return Value:

The index of the component with the minimum absolute value. r=0, g=1, b=2.

Prototype:

float MaxVal(const Color&)

Remarks:

Returns the value of the component with the maximum absolute value.

Parameters:

const Color&

The color to check.

Return Value:

The value of the component with the maximum absolute value.

Prototype:

float MinVal(const Color&)

Remarks:

The value of the component with the minimum absolute value.

Parameters:

const Color&

The color to check.

Return Value:

Prototype:

inline float Length(const Color& v)

Remarks:

Returns the 'length' of the color, i.e.

 return (float)sqrt(v.r*v.r+v.g*v.g+v.b*v.b);

Parameters:

const Color& v

The color to return the length of.

Return Value:

The length of the color.

Operators:

Prototype:

float& operator[](int i)

Remarks:

Access operator.

Parameters:

int i

The index of the component to return.

Return Value:

0=r, 1=g, 2=b.

Prototype:

const float& operator[](int i) const

Remarks:

Access operator.

Parameters:

int i

The index of the component to return.

Return Value:

0=r, 1=g, 2=b.

Prototype:

operator float*()

Remarks:

Returns a pointer to the red component of the color. This may be used to treat the Color as an array of three floats.

Prototype:

operator DWORD()

Remarks:

Convert the Color to a Windows RGB color. See COLORREF.

Prototype:

operator Point3()

Remarks:

Convert the Color to a Point3. x=r, y=g, z=b.

Prototype:

operator RealPixel()

Remarks:

Convert the Color to the RealPixel format.

Prototype:

operator BMM_Color_24();

Remarks:

This method is available in release 4.0 and later only.

Converts this Color to the BMM_Color_24 format.

 

Prototype:

operator BMM_Color_32();

Remarks:

This method is available in release 4.0 and later only.

Converts this Color to the BMM_Color_32 format.

Prototype:

operator BMM_Color_48();

Remarks:

This method is available in release 4.0 and later only.

Converts this Color to the BMM_Color_48 format.

Prototype:

operator BMM_Color_64();

Remarks:

This method is available in release 4.0 and later only.

Converts this Color to the BMM_Color_64 format.

Prototype:

operator BMM_Color_fl();

Remarks:

This method is available in release 4.0 and later only.

Converts this Color to the BMM_Color_fl format.

Prototype:

Color operator-() const

Remarks:

Unary - operator.

Return Value:

The Color with the components negated, i.e.

{ return(Color(-r,-g,-b)); }

Prototype:

Color operator+() const

Remarks:

Unary + operator.

Return Value:

The Color itself.

Assignment operators.

Prototype:

inline Color& operator-=(const Color&);

Remarks:

Subtracts a Color from this Color.

Return Value:

A Color that is the difference between two Colors.

Prototype:

inline Color& operator+=(const Color&);

Remarks:

Adds a Color to this Color.

Return Value:

A Color that is the sum of two Colors.

Prototype:

inline Color& operator*=(float);

Remarks:

Multiplies the components of this Color by a float.

Return Value:

A Color multiplied by a float.

Prototype:

inline Color& operator/=(float);

Remarks:

Divides the components of a Color by a float.

Return Value:

A Color divided by a float.

Prototype:

inline Color& operator*=(const Color&);

Remarks:

Performs element-by-element multiplying between two Colors.

Return Value:

A Color element-by-element multiplied by another Color.

Prototype:

int operator==(const Color& p) const

Remarks:

Test for equality between two Colors.

Return Value:

Nonzero if the Colors are equal; otherwise 0.

Prototype:

int operator!=(const Color& p) const

Remarks:

Tests for inequality between two Colors.

Return Value:

Nonzero if the Colors are not equal; otherwise 0.

Prototype:

inline Color operator-(const Color&) const;

Remarks:

Subtracts a Color from a Color.

Return Value:

A Color that is the difference between two Colors.

Prototype:

inline Color operator+(const Color&) const;

Remarks:

Adds a Color to a Color.

Return Value:

A Color that is the difference between two Colors.

Prototype:

inline Color operator/(const Color&) const;

Remarks:

Divides a Color by a Color.

Return Value:

A Color divided by a Color. r/r, g/g, b/b.

Prototype:

inline Color operator*(const Color&) const;

Remarks:

Multiplies a Color by a Color.

Return Value:

A Color multiplied by a Color. r*r, g*g, b*b.