0001: //--------------------------------------------------------------------------------------
0002: // File: color.h
0003: //
0004: // 色を扱うためのクラス
0005: //
0006: // Copyright (c) Takashi Imagire. All rights reserved.
0007: //--------------------------------------------------------------------------------------
0008: #ifndef __CCOLOR_H_
0009: #define __CCOLOR_H_
0010: 
0011: #include <assert.h>
0012: #include <iostream>
0013: #include "common\my_types.h"
0014: 
0015: 
0016: class CColor
0017: {
0018: private:
0019: public:
0020:     float r,g,b,a;
0021:     
0022:     CColor() {}
0023:     CColor(float fr, float fg, float fb) { r = fr; g = fg; b = fb; a = 0.0f;}
0024:     CColor(const CColor &c) { r = c.r; g = c.g; b = c.b; a = c.b; }
0025: 
0026:     CColor operator+() const { return CColor( r, g, b); }
0027:     CColor operator-() const { return CColor(-r,-g,-b); }
0028: 
0029:     CColor& operator+=(const CColor &c) { r += c.r; g += c.g; b += c.b; a += c.a; return *this; } 
0030:     CColor& operator-=(const CColor &c) { r -= c.r; g -= c.g; b -= c.b; a -= c.a; return *this; } 
0031:     CColor& operator*=(const CColor &c) { r *= c.r; g *= c.g; b *= c.b; a *= c.a; return *this; } 
0032:     CColor& operator/=(const CColor &c) { r /= c.r; g /= c.g; b /= c.b; a /= c.a; return *this; } 
0033:     CColor& operator*=(float f) { r *= f; g *= f; b *= f; a *= f; return *this; } 
0034:     CColor& operator/=(float f) { r /= f; g /= f; b /= f; a /= f; return *this; } 
0035: 
0036: };
0037: 
0038: inline float dot( const CColor &c1, const CColor &c2 )
0039: {
0040:     return c1.r*c2.r + c1.g*c2.g + c1.b*c2.b;
0041: }
0042: 
0043: 
0044: // ---------------------------------------------------------------------------
0045: inline bool operator==(CColor c1, CColor c2)
0046: {
0047:     return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
0048: }
0049: // ---------------------------------------------------------------------------
0050: inline bool operator!=(CColor c1, CColor c2)
0051: {
0052:     return (c1.r != c2.r || c1.g != c2.g || c1.b != c2.b);
0053: }
0054: 
0055: // ---------------------------------------------------------------------------
0056: inline CColor operator+(CColor c1, CColor c2)
0057: {
0058:     return CColor(c1.r+c2.r, c1.g+c2.g, c1.b+c2.b);
0059: }
0060: // ---------------------------------------------------------------------------
0061: inline CColor operator-(CColor c1, CColor c2)
0062: {
0063:     return CColor(c1.r-c2.r, c1.g-c2.g, c1.b-c2.b);
0064: }
0065: // ---------------------------------------------------------------------------
0066: inline CColor operator*(CColor c1, CColor c2)
0067: {
0068:     return CColor(c1.r*c2.r, c1.g*c2.g, c1.b*c2.b);
0069: }
0070: // ---------------------------------------------------------------------------
0071: inline CColor operator/(CColor c1, CColor c2)
0072: {
0073:     return CColor(c1.r/c2.r, c1.g/c2.g, c1.b/c2.b);
0074: }
0075: // ---------------------------------------------------------------------------
0076: inline CColor operator*(CColor c, float f)
0077: {
0078:     return CColor(f*c.r, f*c.g, f*c.b);
0079: }
0080: // ---------------------------------------------------------------------------
0081: inline CColor operator*(float f, CColor c)
0082: {
0083:     return CColor(c.r*f, c.g*f, c.b*f);
0084: }
0085: // ---------------------------------------------------------------------------
0086: inline CColor operator/(CColor c, float f)
0087: {
0088:     return CColor(c.r/f, c.g/f, c.b/f);
0089: }
0090: 
0091: 
0092: #endif // !__CCOLOR_H_
0093: