00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_MATERIAL_H__
00021 #define __CS_MATERIAL_H__
00022
00023 #include "csgfx/rgbpixel.h"
00024 #include "csutil/csobject.h"
00025 #include "csutil/nobjvec.h"
00026 #include "ivideo/material.h"
00027 #include "iengine/material.h"
00028
00029 struct iTextureWrapper;
00030 struct iTextureManager;
00031
00032
00033 SCF_VERSION (csMaterialWrapper, 0, 0, 1);
00034
00038 class csMaterial : public iMaterial
00039 {
00040 private:
00042 csRGBcolor flat_color;
00044 iTextureWrapper *texture;
00046 int num_texture_layers;
00048 csTextureLayer texture_layers[4];
00050 iTextureWrapper* texture_layer_wrappers[4];
00051
00053 float diffuse;
00055 float ambient;
00057 float reflection;
00058
00059 public:
00063 csMaterial ();
00067 csMaterial (iTextureWrapper *txt);
00068
00072 virtual ~csMaterial ();
00073
00075 csRGBcolor& GetFlatColor () { return flat_color; }
00076
00078 float GetDiffuse () const { return diffuse; }
00080 void SetDiffuse (float val) { diffuse = val; }
00081
00083 float GetAmbient () const { return ambient; }
00085 void SetAmbient (float val) { ambient = val; }
00086
00088 float GetReflection () const { return reflection; }
00090 void SetReflection (float val) { reflection = val; }
00091
00093 iTextureWrapper *GetTextureWrapper () const { return texture; }
00095 void SetTextureWrapper (iTextureWrapper *tex);
00096
00098 void AddTextureLayer (iTextureWrapper* txtwrap, UInt mode,
00099 float uscale, float vscale, float ushift, float vshift);
00100
00101
00102
00104 virtual iTextureHandle* GetTexture ();
00106 virtual int GetTextureLayerCount ();
00108 virtual csTextureLayer* GetTextureLayer (int idx);
00110 virtual void GetFlatColor (csRGBpixel &oColor);
00112 virtual void SetFlatColor (const csRGBcolor& col) { flat_color = col; }
00114 virtual void GetReflection (float &oDiffuse, float &oAmbient,
00115 float &oReflection);
00117 virtual void SetReflection (float oDiffuse, float oAmbient,
00118 float oReflection)
00119 {
00120 diffuse = oDiffuse;
00121 ambient = oAmbient;
00122 reflection = oReflection;
00123 }
00124
00125 SCF_DECLARE_IBASE;
00126 };
00127
00132 class csMaterialWrapper : public csObject
00133 {
00134 private:
00136 iMaterial* material;
00138 iMaterialHandle* handle;
00139
00140 private:
00142 virtual ~csMaterialWrapper ();
00143
00144 public:
00146 csMaterialWrapper (iMaterial* Image);
00148 csMaterialWrapper (iMaterialHandle *ith);
00149
00154 void SetMaterialHandle (iMaterialHandle *mat);
00156 iMaterialHandle* GetMaterialHandle () { return handle; }
00157
00162 void SetMaterial (iMaterial* material);
00164 iMaterial* GetMaterial () { return material; }
00165
00167 void Register (iTextureManager *txtmng);
00168
00174 void Visit ();
00175
00176 SCF_DECLARE_IBASE_EXT (csObject);
00177
00178
00179 struct MaterialWrapper : public iMaterialWrapper
00180 {
00181 SCF_DECLARE_EMBEDDED_IBASE (csMaterialWrapper);
00182 virtual csMaterialWrapper* GetPrivateObject ()
00183 { return (csMaterialWrapper*)scfParent; }
00184 virtual iObject *QueryObject()
00185 { return scfParent; }
00186 virtual void SetMaterialHandle (iMaterialHandle *mat)
00187 { scfParent->SetMaterialHandle (mat); }
00188 virtual iMaterialHandle* GetMaterialHandle ()
00189 { return scfParent->GetMaterialHandle (); }
00190 virtual void SetMaterial (iMaterial* material)
00191 { scfParent->SetMaterial (material); }
00192 virtual iMaterial* GetMaterial ()
00193 { return scfParent->GetMaterial (); }
00194 virtual void Register (iTextureManager *txtmng)
00195 { scfParent->Register (txtmng); }
00196 virtual void Visit ()
00197 { scfParent->Visit (); }
00198 } scfiMaterialWrapper;
00199 friend struct MaterialWrapper;
00200 };
00201
00202 CS_DECLARE_OBJECT_VECTOR (csMaterialListHelper, iMaterialWrapper);
00203
00207 class csMaterialList : public csMaterialListHelper
00208 {
00209 public:
00211 csMaterialList ();
00212
00214 iMaterialWrapper* NewMaterial (iMaterial* material);
00215
00220 iMaterialWrapper* NewMaterial (iMaterialHandle *ith);
00221
00222 SCF_DECLARE_IBASE;
00223
00224
00225 class MaterialList : public iMaterialList
00226 {
00227 public:
00228 SCF_DECLARE_EMBEDDED_IBASE (csMaterialList);
00229
00230 virtual iMaterialWrapper* NewMaterial (iMaterial* material);
00231 virtual iMaterialWrapper* NewMaterial (iMaterialHandle *ith);
00232 virtual int GetCount () const;
00233 virtual iMaterialWrapper *Get (int n) const;
00234 virtual int Add (iMaterialWrapper *obj);
00235 virtual bool Remove (iMaterialWrapper *obj);
00236 virtual bool Remove (int n);
00237 virtual void RemoveAll ();
00238 virtual int Find (iMaterialWrapper *obj) const;
00239 virtual iMaterialWrapper *FindByName (const char *Name) const;
00240 } scfiMaterialList;
00241 };
00242
00243 #endif // __CS_MATERIAL_H__