Google

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);
00150   csMaterialWrapper (csMaterialWrapper &);
00151 
00156   void SetMaterialHandle (iMaterialHandle *mat);
00158   iMaterialHandle* GetMaterialHandle () { return handle; }
00159 
00164   void SetMaterial (iMaterial* material);
00166   iMaterial* GetMaterial () { return material; }
00167 
00169   void Register (iTextureManager *txtmng);
00170 
00176   void Visit ();
00177 
00178   SCF_DECLARE_IBASE_EXT (csObject);
00179 
00180   //------------------- iMaterialWrapper implementation -----------------------
00181   struct MaterialWrapper : public iMaterialWrapper
00182   {
00183     SCF_DECLARE_EMBEDDED_IBASE (csMaterialWrapper);
00184     virtual csMaterialWrapper* GetPrivateObject ()
00185     { return (csMaterialWrapper*)scfParent; }
00186     virtual iObject *QueryObject()
00187     { return scfParent; }
00188     virtual iMaterialWrapper *Clone () const
00189     { return &(new csMaterialWrapper (*scfParent))->scfiMaterialWrapper; }
00190     virtual void SetMaterialHandle (iMaterialHandle *mat)
00191     { scfParent->SetMaterialHandle (mat); }
00192     virtual iMaterialHandle* GetMaterialHandle ()
00193     { return scfParent->GetMaterialHandle (); }
00194     virtual void SetMaterial (iMaterial* material)
00195     { scfParent->SetMaterial (material); }
00196     virtual iMaterial* GetMaterial ()
00197     { return scfParent->GetMaterial (); }
00198     virtual void Register (iTextureManager *txtmng)
00199     { scfParent->Register (txtmng); }
00200     virtual void Visit ()
00201     { scfParent->Visit (); }
00202   } scfiMaterialWrapper;
00203   friend struct MaterialWrapper;
00204 };
00205 
00206 CS_DECLARE_OBJECT_VECTOR (csMaterialListHelper, iMaterialWrapper);
00207 
00211 class csMaterialList : public csMaterialListHelper
00212 {
00213 public:
00215   csMaterialList ();
00216 
00218   iMaterialWrapper* NewMaterial (iMaterial* material);
00219 
00224   iMaterialWrapper* NewMaterial (iMaterialHandle *ith);
00225 
00226   SCF_DECLARE_IBASE;
00227 
00228   //------------------- iMaterialList implementation -----------------------
00229   class MaterialList : public iMaterialList
00230   {
00231   public:
00232     SCF_DECLARE_EMBEDDED_IBASE (csMaterialList);
00233 
00234     virtual iMaterialWrapper* NewMaterial (iMaterial* material);
00235     virtual iMaterialWrapper* NewMaterial (iMaterialHandle *ith);
00236     virtual int GetCount () const;
00237     virtual iMaterialWrapper *Get (int n) const;
00238     virtual int Add (iMaterialWrapper *obj);
00239     virtual bool Remove (iMaterialWrapper *obj);
00240     virtual bool Remove (int n);
00241     virtual void RemoveAll ();
00242     virtual int Find (iMaterialWrapper *obj) const;
00243     virtual iMaterialWrapper *FindByName (const char *Name) const;
00244   } scfiMaterialList;
00245 };
00246 
00247 #endif // __CS_MATERIAL_H__

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