CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

meshlod.h

00001 /*
00002     Copyright (C) 2003 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_MESHLOD_H__
00020 #define __CS_MESHLOD_H__
00021 
00022 #include "csutil/scf.h"
00023 #include "csutil/array.h"
00024 #include "csutil/refcount.h"
00025 #include "iengine/lod.h"
00026 #include "iengine/mesh.h"
00027 #include "iengine/sharevar.h"
00028 
00029 struct iMeshWrapper;
00030 struct iMeshFactoryWrapper;
00031 
00035 class csLODListener : public iSharedVariableListener
00036 {
00037 private:
00038   float* variable;
00039 public:
00040   SCF_DECLARE_IBASE;
00041   csLODListener (float* variable)
00042   {
00043     SCF_CONSTRUCT_IBASE (0);
00044     csLODListener::variable = variable;
00045   }
00046 
00047   virtual void VariableChanged (iSharedVariable* var)
00048   {
00049     *variable = var->Get ();
00050   }
00051 };
00052 
00057 class csStaticLODMesh : public iLODControl
00058 {
00059 private:
00061   csArray<csArray<iMeshWrapper*> > meshes_for_lod;
00062 
00064   float lod_m, lod_a;
00066   csRef<iSharedVariable> lod_varm;
00067   csRef<iSharedVariable> lod_vara;
00068   csRef<csLODListener> lod_varm_listener;
00069   csRef<csLODListener> lod_vara_listener;
00070 
00071   void ClearLODListeners ();
00072 
00073 public:
00074   SCF_DECLARE_IBASE;
00075 
00077   csStaticLODMesh ();
00078   virtual ~csStaticLODMesh ();
00079 
00080   virtual void SetLOD (float m, float a);
00081   virtual void GetLOD (float& m, float& a) const;
00082   virtual void SetLOD (iSharedVariable* varm, iSharedVariable* vara);
00083   virtual void GetLOD (iSharedVariable*& varm, iSharedVariable*& vara) const
00084   {
00085     varm = lod_varm;
00086     vara = lod_vara;
00087   }
00088   virtual int GetLODPolygonCount (float lod) const;
00089 
00090   float GetLODValue (float distance) const
00091   {
00092     return lod_m * distance + lod_a;
00093   }
00094 
00096   csArray<iMeshWrapper*>& GetMeshesForLOD (int lod)
00097   {
00098     if (lod >= meshes_for_lod.Length ())
00099     {
00100       meshes_for_lod.SetLength (lod+1);
00101     }
00102     return meshes_for_lod[lod];
00103   }
00104 
00106   csArray<iMeshWrapper*>& GetMeshesForLOD (float lod)
00107   {
00108     int l = meshes_for_lod.Length ();
00109     int idx = int (lod * l);
00110     if (idx < 0) idx = 0;
00111     else if (idx >= l) idx = l-1;
00112     return meshes_for_lod[idx];
00113   }
00114 
00116   int GetLODCount ()
00117   {
00118     return meshes_for_lod.Length ();
00119   }
00120 };
00121 
00127 class csStaticLODFactoryMesh : public iLODControl
00128 {
00129 private:
00131   csArray<csArray<iMeshFactoryWrapper*> > meshes_for_lod;
00132 
00134   float lod_m, lod_a;
00136   csRef<iSharedVariable> lod_varm;
00137   csRef<iSharedVariable> lod_vara;
00138   csRef<csLODListener> lod_varm_listener;
00139   csRef<csLODListener> lod_vara_listener;
00140 
00141 public:
00142   SCF_DECLARE_IBASE;
00143 
00145   csStaticLODFactoryMesh ();
00146   virtual ~csStaticLODFactoryMesh ();
00147 
00148   virtual void SetLOD (float m, float a);
00149   virtual void GetLOD (float& m, float& a) const;
00150   virtual void SetLOD (iSharedVariable* varm, iSharedVariable* vara);
00151   virtual void GetLOD (iSharedVariable*& varm, iSharedVariable*& vara) const
00152   {
00153     varm = lod_varm;
00154     vara = lod_vara;
00155   }
00156   virtual int GetLODPolygonCount (float lod) const { return 0; }
00157 
00159   csArray<iMeshFactoryWrapper*>& GetMeshesForLOD (int lod)
00160   {
00161     if (lod >= meshes_for_lod.Length ())
00162     {
00163       meshes_for_lod.SetLength (lod+1);
00164     }
00165     return meshes_for_lod[lod];
00166   }
00167 
00169   int GetLODCount ()
00170   {
00171     return meshes_for_lod.Length ();
00172   }
00173 };
00174 
00175 #endif // __CS_MESHLOD_H__
00176 

Generated for Crystal Space by doxygen 1.2.14