CMaterial.h Source File

Chapitre 2

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CMaterial.h

00001 
00007 #ifndef __CMATERIAL_H__
00008 #define __CMATERIAL_H__
00009 
00010 #include "utilitylib.h"
00011 
00012 class CMaterial
00013 {
00014         private:
00015                 char*   mName;
00016                 CColor  mSpecularColor;
00017                 CColor  mDiffuseColor;
00018                 CColor  mAmbientColor;
00019                 CColor  mSelfIllumColor;
00020                 float   mShininess;
00021                 float   mShinestrength;
00022                 float   mTransmittivity;
00023                 float   mReflectivity;
00024                 bool    mPermanent;
00025 
00026         public:
00027                 // constructor and destructor
00028                 CMaterial() {   mName = "EMPTY MAT"; mSpecularColor = CColor(0.0f, 0.0f, 0.0f); mDiffuseColor = CColor(0.0f, 0.0f, 0.0f); 
00029                                                 mAmbientColor = CColor(0.0f, 0.0f, 0.0f); mSelfIllumColor = CColor(0.0f, 0.0f, 0.0f);
00030                                                 mShininess = 0.0f; mShinestrength = 0.0f; mTransmittivity = 0.0f; mReflectivity = 0.0f; mPermanent = true;}
00031                 CMaterial(char* name, CColor specular, CColor diffuse, CColor ambient, CColor selfillum, float transmittivity, float reflectivity, float shininess=20.0f, float shinestrength=1.0f, bool permanent=true)
00032                         : mName(name), mSpecularColor(specular), mDiffuseColor(diffuse), mAmbientColor(ambient), mSelfIllumColor(selfillum), mShininess(shininess), 
00033                         mShinestrength(shinestrength), mTransmittivity(transmittivity), mReflectivity(reflectivity), mPermanent(permanent) {};
00034                 virtual ~CMaterial() { }
00035 
00036                 // get
00037                 __forceinline const char*       GetName() const                         { return mName; }
00038                 __forceinline const CColor& GetDiffuse() const                  { return mDiffuseColor; }
00039                 __forceinline const CColor& GetSpecular() const                 { return mSpecularColor; }
00040                 __forceinline const CColor& GetAmbient() const                  { return mAmbientColor; }
00041                 __forceinline const CColor& GetSelfIllum() const                { return mSelfIllumColor; }
00042                 __forceinline const float       GetShininess() const            { return mShininess; }
00043                 __forceinline const float       GetShinestStrength() const      { return mShinestrength; }
00044                 __forceinline const float       GetTransmittivity() const       { return mTransmittivity; }
00045                 __forceinline const float       GetReflectivity() const         { return mReflectivity; }
00046                 __forceinline bool                      GetPermanency() const           { return mPermanent; }
00047 
00048                 // set
00049                 __forceinline void SetName(char* name)                                                  { mName = name; }
00050                 __forceinline void SetSpecular(const CColor& specular)                  { mSpecularColor = specular; }
00051                 __forceinline void SetDiffuse(const CColor& diffuse)                    { mDiffuseColor = diffuse; }
00052                 __forceinline void SetAmbient(const CColor& ambient)                    { mAmbientColor = ambient; }
00053                 __forceinline void SetSelfIllum(const CColor& selfIllum)                { mSelfIllumColor = selfIllum; }
00054                 __forceinline void SetShininess(const float shininess)                  { mShininess = shininess; }
00055                 __forceinline void SetShinesStrenght(const float sStrength)             { mShinestrength = sStrength; }
00056                 __forceinline void SetTransparency(const float transmittivity)  { mTransmittivity = transmittivity; } 
00057                 __forceinline void SetReflectivity(const float reflectivity)    { mReflectivity = reflectivity; }
00058                 __forceinline void SetPermanency(const bool permanent)                  { mPermanent = permanent; }
00059 
00060                 // operators
00061                 __forceinline friend CMaterial operator* (const CMaterial& mat, const float multiple)
00062                 { return CMaterial( "COMPOSITE MATERIAL",
00063                                                         mat.mSpecularColor*multiple,
00064                                                         mat.mDiffuseColor*multiple,
00065                                                         mat.mAmbientColor*multiple,
00066                                                         mat.mSelfIllumColor*multiple,
00067                                                         mat.mTransmittivity*multiple,
00068                                                         mat.mReflectivity*multiple,
00069                                                         mat.mShininess*multiple,
00070                                                         mat.mShinestrength*multiple ); }
00071 
00072                 __forceinline friend CMaterial operator+ (const CMaterial& mat1, const CMaterial& mat2)
00073                 { return CMaterial( "COMPOSITE MATERIAL",
00074                                                         mat1.mSpecularColor+mat2.mSpecularColor,
00075                                                         mat1.mDiffuseColor+mat2.mDiffuseColor,
00076                                                         mat1.mAmbientColor+mat2.mAmbientColor,
00077                                                         mat1.mSelfIllumColor+mat2.mSelfIllumColor,
00078                                                         mat1.mTransmittivity+mat2.mTransmittivity,
00079                                                         mat1.mReflectivity+mat2.mReflectivity,
00080                                                         mat1.mShininess+mat2.mShininess,
00081                                                         mat1.mShinestrength+mat2.mShinestrength ); }
00082 
00083                 __forceinline friend void operator+= (CMaterial& mat1, const CMaterial& mat2)
00084                 {       mat1.mName = "COMPOSITE MATERIAL";
00085                         mat1.mSpecularColor += mat2.mSpecularColor;
00086                         mat1.mDiffuseColor += mat2.mDiffuseColor;
00087                         mat1.mAmbientColor += mat2.mAmbientColor;
00088                         mat1.mSelfIllumColor += mat2.mSelfIllumColor;
00089                         mat1.mTransmittivity += mat2.mTransmittivity;
00090                         mat1.mReflectivity += mat2.mReflectivity;
00091                         mat1.mShininess += mat2.mShininess;
00092                         mat1.mShinestrength += mat2.mShinestrength;
00093                 }
00094 
00095                 // misc functions
00096                 __forceinline CMaterial InterpolateMaterials(const CMaterial& mat1, const CMaterial& mat2) const
00097                 { return CMaterial(     "COMPOSITE MATERIAL", 
00098                                                         (mat1.mSpecularColor+mat2.mSpecularColor)/2.0f, 
00099                                                         (mat1.mDiffuseColor+mat2.mDiffuseColor)/2.0f, 
00100                                                         (mat1.mAmbientColor+mat2.mAmbientColor)/2.0f, 
00101                                                         (mat1.mSelfIllumColor+mat2.mSelfIllumColor)/2.0f,
00102                                                         (mat1.mTransmittivity+mat2.mTransmittivity)/2.0f,
00103                                                         (mat1.mReflectivity+mat2.mReflectivity)/2.0f,
00104                                                         (mat1.mShininess+mat2.mShininess)/2.0f,
00105                                                         (mat1.mShinestrength+mat2.mShinestrength)/2.0f  ); }
00106 };
00107 
00108 #endif /* #ifndef __CMATERIAL_H__ */

Generated on Fri Apr 19 16:19:34 2002 by doxygen1.2.15