|
mdldata.h00001 /* 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 __MDLDATA_H__ 00020 #define __MDLDATA_H__ 00021 00022 #include "imesh/mdldata.h" 00023 #include "csutil/garray.h" 00024 #include "csutil/csobject.h" 00025 #include "csutil/typedvec.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 CS_DECLARE_TYPED_IBASE_VECTOR (csObjectVector, iObject); 00069 00070 class csIntArray; 00071 00072 //---------------------------------------------------------------------------- 00073 00074 class csModelDataTexture : public iModelDataTexture 00075 { 00076 private: 00077 char *FileName; 00078 iImage *Image; 00079 iTextureWrapper *TextureWrapper; 00080 public: 00081 SCF_DECLARE_IBASE; 00082 CS_DECLARE_OBJECT_INTERFACE; 00083 00085 csModelDataTexture (); 00087 virtual ~csModelDataTexture (); 00088 00090 void SetFileName (const char *fn); 00092 const char *GetFileName () const; 00093 00094 CS_DECLARE_ACCESSOR_METHODS (iImage*, Image); 00095 CS_DECLARE_ACCESSOR_METHODS (iTextureWrapper*, TextureWrapper); 00096 00102 void LoadImage (iVFS *VFS, iImageIO *ImageIO, int Format); 00103 00105 void Register (iTextureList *tl); 00106 00107 iModelDataTexture *Clone () const; 00108 }; 00109 00110 class csModelDataMaterial : public iModelDataMaterial 00111 { 00112 private: 00113 iMaterial *BaseMaterial; 00114 iMaterialWrapper *MaterialWrapper; 00115 public: 00116 SCF_DECLARE_IBASE; 00117 CS_DECLARE_OBJECT_INTERFACE; 00118 00120 csModelDataMaterial (); 00122 virtual ~csModelDataMaterial (); 00123 00124 CS_DECLARE_ACCESSOR_METHODS (iMaterial*, BaseMaterial); 00125 CS_DECLARE_ACCESSOR_METHODS (iMaterialWrapper*, MaterialWrapper); 00126 00128 void Register (iMaterialList *ml); 00129 00130 iModelDataMaterial *Clone () const; 00131 }; 00132 00133 class csModelDataVertices : public iModelDataVertices 00134 { 00135 private: 00136 CS_DECLARE_GROWING_ARRAY (Vertices, csVector3); 00137 CS_DECLARE_GROWING_ARRAY (Normals, csVector3); 00138 CS_DECLARE_GROWING_ARRAY (Colors, csColor); 00139 CS_DECLARE_GROWING_ARRAY (Texels, csVector2); 00140 00141 public: 00142 SCF_DECLARE_IBASE; 00143 CS_DECLARE_OBJECT_INTERFACE; 00144 00146 csModelDataVertices (); 00148 csModelDataVertices (const iModelDataVertices *orig1, 00149 const iModelDataVertices *orig2); 00151 virtual ~csModelDataVertices() {} 00152 00154 void CopyFrom (const iModelDataVertices *Other); 00155 00156 CS_DECLARE_ARRAY_INTERFACE (const csVector3 &, Vertex); 00157 CS_DECLARE_ARRAY_INTERFACE (const csVector3 &, Normal); 00158 CS_DECLARE_ARRAY_INTERFACE (const csColor &, Color); 00159 CS_DECLARE_ARRAY_INTERFACE (const csVector2 &, Texel); 00160 virtual int FindVertex (const csVector3 &v) const; 00161 virtual int FindNormal (const csVector3 &v) const; 00162 virtual int FindColor (const csColor &v) const; 00163 virtual int FindTexel (const csVector2 &v) const; 00164 00165 iModelDataVertices *Clone () const; 00166 }; 00167 00168 class csModelDataAction : public iModelDataAction 00169 { 00170 private: 00171 CS_DECLARE_GROWING_ARRAY (Times, float); 00172 csObjectVector States; 00173 00174 public: 00175 SCF_DECLARE_IBASE; 00176 CS_DECLARE_OBJECT_INTERFACE; 00177 00179 csModelDataAction (); 00181 virtual ~csModelDataAction () { } 00182 00184 virtual int GetFrameCount () const; 00186 virtual float GetTime (int Frame) const; 00188 virtual iObject *GetState (int Frame) const; 00190 virtual void SetTime (int Frame, float NewTime); 00192 virtual void SetState (int Frame, iObject *State); 00194 virtual void AddFrame (float Time, iObject *State); 00196 virtual void DeleteFrame (int Frame); 00198 virtual float GetTotalTime () const; 00199 }; 00200 00201 class csModelDataPolygon : public iModelDataPolygon 00202 { 00203 private: 00204 CS_DECLARE_GROWING_ARRAY (Vertices, int); 00205 CS_DECLARE_GROWING_ARRAY (Normals, int); 00206 CS_DECLARE_GROWING_ARRAY (Colors, int); 00207 CS_DECLARE_GROWING_ARRAY (Texels, int); 00208 iModelDataMaterial *Material; 00209 00210 public: 00211 SCF_DECLARE_IBASE; 00212 CS_DECLARE_OBJECT_INTERFACE; 00213 00215 csModelDataPolygon (); 00217 virtual ~csModelDataPolygon (); 00218 00220 int AddVertex (int ver, int nrm, int col, int tex); 00222 int GetVertexCount () const; 00224 void DeleteVertex (int n); 00225 00226 CS_DECLARE_ARRAY_INTERFACE_NONUM (int, Vertex); 00227 CS_DECLARE_ARRAY_INTERFACE_NONUM (int, Normal); 00228 CS_DECLARE_ARRAY_INTERFACE_NONUM (int, Color); 00229 CS_DECLARE_ARRAY_INTERFACE_NONUM (int, Texel); 00230 CS_DECLARE_ACCESSOR_METHODS (iModelDataMaterial*, Material); 00231 00232 iModelDataPolygon *Clone () const; 00233 }; 00234 00235 class csModelDataObject : public iModelDataObject 00236 { 00237 private: 00238 iModelDataVertices *DefaultVertices; 00239 00240 public: 00241 SCF_DECLARE_IBASE; 00242 CS_DECLARE_OBJECT_INTERFACE; 00243 00245 csModelDataObject (); 00247 virtual ~csModelDataObject(); 00248 00249 CS_DECLARE_ACCESSOR_METHODS (iModelDataVertices*, DefaultVertices); 00250 }; 00251 00252 class csModelDataCamera : public iModelDataCamera 00253 { 00254 private: 00255 csVector3 Position, UpVector, FrontVector, RightVector; 00256 00257 public: 00258 SCF_DECLARE_IBASE; 00259 CS_DECLARE_OBJECT_INTERFACE; 00260 00262 csModelDataCamera (); 00263 // Destructor 00264 virtual ~csModelDataCamera () {} 00265 00266 CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, Position); 00267 CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, UpVector); 00268 CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, FrontVector); 00269 CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, RightVector); 00270 00272 void ComputeUpVector (); 00274 void ComputeFrontVector (); 00276 void ComputeRightVector (); 00277 00279 void Normalize (); 00281 bool CheckOrthogonality () const; 00282 00283 iModelDataCamera *Clone () const; 00284 }; 00285 00286 class csModelDataLight : public iModelDataLight 00287 { 00288 private: 00289 float Radius; 00290 csColor Color; 00291 csVector3 Position; 00292 00293 public: 00294 SCF_DECLARE_IBASE; 00295 CS_DECLARE_OBJECT_INTERFACE; 00296 00298 csModelDataLight (); 00299 // Destructor 00300 virtual ~csModelDataLight () {} 00301 00302 CS_DECLARE_ACCESSOR_METHODS (float, Radius); 00303 CS_DECLARE_ACCESSOR_METHODS (const csVector3 &, Position); 00304 CS_DECLARE_ACCESSOR_METHODS (const csColor &, Color); 00305 iModelDataLight *Clone () const; 00306 }; 00307 00308 class csModelData : public iModelData 00309 { 00310 public: 00311 SCF_DECLARE_IBASE; 00312 CS_DECLARE_OBJECT_INTERFACE; 00313 00315 csModelData (); 00317 virtual ~csModelData () {} 00318 00320 void LoadImages (iVFS *VFS, iImageIO *il, int Format); 00322 void RegisterTextures (iTextureList *tl); 00324 void RegisterMaterials (iMaterialList *ml); 00325 }; 00326 00327 #endif // __MDLDATA_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |