CrystalSpace

Public API Reference

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

mdldata.h

00001 /*
00002     Copyright (C) 2001 by Martin Geisse <mgeisse@gmx.net>
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_MDLDATA_H__
00020 #define __CS_MDLDATA_H__
00021 
00022 #include "imesh/mdldata.h"
00023 #include "csutil/garray.h"
00024 #include "csutil/csobject.h"
00025 #include "csutil/refarr.h"
00026 
00027 #define CS_DECLARE_ACCESSOR_METHODS(type,name)                          \
00028   type Get##name () const;                                              \
00029   void Set##name (type);
00030 
00031 #define CS_DECLARE_ARRAY_INTERFACE_NONUM(type,sing_name)                \
00032   type Get##sing_name (int n) const;                                    \
00033   void Set##sing_name (int n, type);
00034 
00035 #define CS_DECLARE_ARRAY_INTERFACE(type,sing_name)                      \
00036   CS_DECLARE_ARRAY_INTERFACE_NONUM (type, sing_name)                    \
00037   int Get##sing_name##Count () const;                                   \
00038   int Add##sing_name (type obj);                                        \
00039   void Delete##sing_name (int n);
00040 
00041 #define CS_DECLARE_OBJECT_INTERFACE                                     \
00042   CS_DECLARE_EMBEDDED_OBJECT (csObject, iObject);                       \
00043   iObject *QueryObject ();
00044 
00049 #define CS_DECLARE_EMBEDDED_OBJECT(clname,itf)                          \
00050   struct Embedded_##clname : public clname {                            \
00051     typedef clname __scf_superclass__;                                  \
00052     SCF_DECLARE_EMBEDDED_IBASE (iBase);                                 \
00053   } scf##itf;
00054 
00059 #define CS_IMPLEMENT_EMBEDDED_OBJECT(Class)                             \
00060   SCF_IMPLEMENT_EMBEDDED_IBASE_INCREF (Class);                          \
00061   SCF_IMPLEMENT_EMBEDDED_IBASE_DECREF (Class);                          \
00062   SCF_IMPLEMENT_EMBEDDED_IBASE_GETREFCOUNT (Class);                     \
00063   SCF_IMPLEMENT_EMBEDDED_IBASE_QUERY (Class);                           \
00064     void *o = __scf_superclass__::QueryInterface (iInterfaceID, iVersion); \
00065     if (o) return o;                                                    \
00066   SCF_IMPLEMENT_EMBEDDED_IBASE_QUERY_END;
00067 
00068 typedef csRefArray<iObject> csObjectVector;
00069 
00070 class csIntArray;
00071 
00072 //----------------------------------------------------------------------------
00073 
00075 class csModelDataTexture : public iModelDataTexture
00076 {
00077 private:
00078   char *FileName;
00079   csRef<iImage> Image;
00080   csRef<iTextureWrapper> TextureWrapper;
00081 
00082 public:
00083   SCF_DECLARE_IBASE;
00084   CS_DECLARE_OBJECT_INTERFACE;
00085 
00087   csModelDataTexture ();
00089   virtual ~csModelDataTexture ();
00090 
00092   void SetFileName (const char *fn);
00094   const char *GetFileName () const;
00095 
00096   CS_DECLARE_ACCESSOR_METHODS (iImage*, Image);
00097   CS_DECLARE_ACCESSOR_METHODS (iTextureWrapper*, TextureWrapper);
00098 
00104   void LoadImage (iVFS *VFS, iImageIO *ImageIO, int Format);
00105 
00107   void Register (iTextureList *tl);
00108 
00109   iModelDataTexture *Clone () const;
00110 };
00111 
00113 class csModelDataMaterial : public iModelDataMaterial
00114 {
00115 private:
00116   iMaterial *BaseMaterial;
00117   iMaterialWrapper *MaterialWrapper;
00118 
00119 public:
00120   SCF_DECLARE_IBASE;
00121   CS_DECLARE_OBJECT_INTERFACE;
00122 
00124   csModelDataMaterial ();
00126   virtual ~csModelDataMaterial ();
00127 
00128   CS_DECLARE_ACCESSOR_METHODS (iMaterial*, BaseMaterial);
00129   CS_DECLARE_ACCESSOR_METHODS (iMaterialWrapper*, MaterialWrapper);
00130 
00132   void Register (iMaterialList *ml);
00133 
00134   iModelDataMaterial *Clone () const;
00135 };
00136 
00138 class csModelDataVertices : public iModelDataVertices
00139 {
00140 private:
00141   csDirtyAccessArray<csVector3> Vertices;
00142   csDirtyAccessArray<csVector3> Normals;
00143   csDirtyAccessArray<csColor> Colors;
00144   csDirtyAccessArray<csVector2> Texels;
00145 
00146 public:
00147   SCF_DECLARE_IBASE;
00148   CS_DECLARE_OBJECT_INTERFACE;
00149 
00151   csModelDataVertices ();
00153   csModelDataVertices (const iModelDataVertices *orig1,
00154     const iModelDataVertices *orig2);
00156   virtual ~csModelDataVertices() {}
00157 
00159   void CopyFrom (const iModelDataVertices *Other);
00160 
00161   CS_DECLARE_ARRAY_INTERFACE (const csVector3 &, Vertex);
00162   CS_DECLARE_ARRAY_INTERFACE (const csVector3 &, Normal);
00163   CS_DECLARE_ARRAY_INTERFACE (const csColor &, Color);
00164   CS_DECLARE_ARRAY_INTERFACE (const csVector2 &, Texel);
00165   virtual int FindVertex (const csVector3 &v) const;
00166   virtual int FindNormal (const csVector3 &v) const;
00167   virtual int FindColor (const csColor &v) const;
00168   virtual int FindTexel (const csVector2 &v) const;
00169 
00170   iModelDataVertices *Clone () const;
00171 };
00172 
00174 class csModelDataAction : public iModelDataAction
00175 {
00176 private:
00177   csDirtyAccessArray<float> Times;
00178   csObjectVector States;
00179 
00180 public:
00181   SCF_DECLARE_IBASE;
00182   CS_DECLARE_OBJECT_INTERFACE;
00183 
00185   csModelDataAction ();
00187   virtual ~csModelDataAction () { }
00188 
00190   virtual int GetFrameCount () const;
00192   virtual float GetTime (int Frame) const;
00194   virtual iObject *GetState (int Frame) const;
00196   virtual void SetTime (int Frame, float NewTime);
00198   virtual void SetState (int Frame, iObject *State);
00200   virtual void AddFrame (float Time, iObject *State);
00202   virtual void DeleteFrame (int Frame);
00204   virtual float GetTotalTime () const;
00205 };
00206 
00208 class csModelDataPolygon : public iModelDataPolygon
00209 {
00210 private:
00211   csDirtyAccessArray<int> Vertices;
00212   csDirtyAccessArray<int> Normals;
00213   csDirtyAccessArray<int> Colors;
00214   csDirtyAccessArray<int> Texels;
00215   iModelDataMaterial *Material;
00216 
00217 public:
00218   SCF_DECLARE_IBASE;
00219   CS_DECLARE_OBJECT_INTERFACE;
00220 
00222   csModelDataPolygon ();
00224   virtual ~csModelDataPolygon ();
00225 
00227   int AddVertex (int ver, int nrm, int col, int tex);
00229   int GetVertexCount () const;
00231   void DeleteVertex (int n);
00232 
00233   CS_DECLARE_ARRAY_INTERFACE_NONUM (int, Vertex);
00234   CS_DECLARE_ARRAY_INTERFACE_NONUM (int, Normal);
00235   CS_DECLARE_ARRAY_INTERFACE_NONUM (int, Color);
00236   CS_DECLARE_ARRAY_INTERFACE_NONUM (int, Texel);
00237   CS_DECLARE_ACCESSOR_METHODS (iModelDataMaterial*, Material);
00238 
00239   iModelDataPolygon *Clone () const;
00240 };
00241 
00243 class csModelDataObject : public iModelDataObject
00244 {
00245 private:
00246   iModelDataVertices *DefaultVertices;
00247 
00248 public:
00249   SCF_DECLARE_IBASE;
00250   CS_DECLARE_OBJECT_INTERFACE;
00251 
00253   csModelDataObject ();
00255   virtual ~csModelDataObject();
00256 
00257   CS_DECLARE_ACCESSOR_METHODS (iModelDataVertices*, DefaultVertices);
00258 };
00259 
00261 class csModelDataCamera : public iModelDataCamera
00262 {
00263 private:
00264   csVector3 Position, UpVector, FrontVector, RightVector;
00265 
00266 public:
00267   SCF_DECLARE_IBASE;
00268   CS_DECLARE_OBJECT_INTERFACE;
00269 
00271   csModelDataCamera ();
00272   // Destructor
00273   virtual ~csModelDataCamera () {}
00274 
00275   CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, Position);
00276   CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, UpVector);
00277   CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, FrontVector);
00278   CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, RightVector);
00279 
00281   void ComputeUpVector ();
00283   void ComputeFrontVector ();
00285   void ComputeRightVector ();
00286 
00288   void Normalize ();
00290   bool CheckOrthogonality () const;
00291 
00292   iModelDataCamera *Clone () const;
00293 };
00294 
00296 class csModelDataLight : public iModelDataLight
00297 {
00298 private:
00299   float Radius;
00300   csColor Color;
00301   csVector3 Position;
00302 
00303 public:
00304   SCF_DECLARE_IBASE;
00305   CS_DECLARE_OBJECT_INTERFACE;
00306 
00308   csModelDataLight ();
00309   // Destructor
00310   virtual ~csModelDataLight () {}
00311 
00312   CS_DECLARE_ACCESSOR_METHODS (float, Radius);
00313   CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, Position);
00314   CS_DECLARE_ACCESSOR_METHODS (const csColor &, Color);
00315   iModelDataLight *Clone () const;
00316 };
00317 
00318 class csModelData : public iModelData
00319 {
00320 public:
00321   SCF_DECLARE_IBASE;
00322   CS_DECLARE_OBJECT_INTERFACE;
00323 
00325   csModelData ();
00327   virtual ~csModelData () {}
00328 
00330   void LoadImages (iVFS *VFS, iImageIO *il, int Format);
00332   void RegisterTextures (iTextureList *tl);
00334   void RegisterMaterials (iMaterialList *ml);
00335 };
00336 
00337 #endif // __CS_MDLDATA_H__

Generated for Crystal Space by doxygen 1.2.14