Main Page   Class Hierarchy   Compound List   File List   Compound Members  

material.h

00001 /*
00002     Copyright (C) 2001 by Jorrit Tyberghein
00003     Copyright (C) 2000 by W.C.A. Wijngaards
00004   
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009   
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014   
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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   //--------------------- iMaterial implementation ---------------------
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   //------------------- iMaterialWrapper implementation -----------------------
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   //------------------- iMaterialList implementation -----------------------
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__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000