CrystalSpace

Public API Reference

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

meshobjtmpl.h

00001 /*
00002     Copyright (C) 2003 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_MESHOBJ_H__
00020 #define __CS_MESHOBJ_H__
00021 
00022 #include "csutil/refarr.h"
00023 #include "iengine/material.h"
00024 #include "iengine/engine.h"
00025 #include "iengine/mesh.h"
00026 #include "imesh/object.h"
00027 #include "csgeom/objmodel.h"
00028 
00030 #define CS_DECLARE_SIMPLE_MESH_FACTORY(name,meshclass)                      \
00031   class name : public csMeshFactory {                                       \
00032   public:                                                                   \
00033     name (iEngine *e, iObjectRegistry* reg) : csMeshFactory (e, reg) {}     \
00034     virtual csPtr<iMeshObject> NewInstance ()                               \
00035     { return new meshclass (Engine, this); }                                \
00036   };
00037 
00039 #define CS_DECLARE_SIMPLE_MESH_PLUGIN(name,factclass)                       \
00040   class name : public csMeshType {                                          \
00041   public:                                                                   \
00042     name (iBase *p) : csMeshType (p) {}                                     \
00043     virtual csPtr<iMeshObjectFactory> NewFactory ()                         \
00044     { return new factclass (Engine, object_reg); }                          \
00045   };
00046 
00060 class csMeshObject : public iMeshObject
00061 {
00062 protected:
00064   csRef<iMeshObjectDrawCallback> VisCallback;
00065 
00067   iBase *LogParent;
00068 
00070   iEngine *Engine;
00071 
00073   void WantToDie ();
00074 
00075 public:
00076   SCF_DECLARE_IBASE;
00077 
00079   csMeshObject (iEngine *engine);
00080 
00082   virtual ~csMeshObject ();
00083 
00088   virtual iMeshObjectFactory* GetFactory () const = 0;
00089 
00094   virtual bool DrawTest (iRenderView* rview, iMovable* movable);
00095 
00102   virtual csRenderMesh** GetRenderMeshes (int& num)
00103   {
00104     return 0;
00105   }
00106 
00111   virtual void UpdateLighting (iLight** lights, int num_lights,
00112         iMovable* movable);
00113 
00118   virtual bool Draw (iRenderView* rview, iMovable* movable,
00119         csZBufMode zbufMode) = 0;
00120 
00126   virtual void SetVisibleCallback (iMeshObjectDrawCallback* cb);
00127 
00132   virtual iMeshObjectDrawCallback* GetVisibleCallback () const;
00133 
00138   virtual void NextFrame (csTicks current_time,const csVector3& pos);
00139 
00144   virtual void HardTransform (const csReversibleTransform& t);
00145 
00150   virtual bool SupportsHardTransform () const;
00151 
00156   virtual bool HitBeamOutline (const csVector3& start,
00157         const csVector3& end, csVector3& isect, float* pr);
00158 
00163   virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00164         csVector3& isect, float* pr);
00165 
00170   virtual void SetLogicalParent (iBase* logparent);
00171 
00176   virtual iBase* GetLogicalParent () const;
00177 
00181   virtual iObjectModel* GetObjectModel () { return &scfiObjectModel; }
00182 
00187   virtual bool SetColor (const csColor& color);
00188 
00193   virtual bool GetColor (csColor& color) const;
00194 
00199   virtual bool SetMaterialWrapper (iMaterialWrapper* material);
00200 
00205   virtual iMaterialWrapper* GetMaterialWrapper () const;
00206 
00211   virtual void InvalidateMaterialHandles () { }
00212 
00217   virtual int GetPortalCount () const { return 0; }
00218 
00223   virtual iPortal* GetPortal (int) const { return 0; }
00224 
00229   virtual void GetObjectBoundingBox (csBox3& bbox, int type);
00230 
00235   virtual void GetRadius (csVector3& radius, csVector3& center);
00236 
00237   // implementation of iObjectModel
00238   struct eiObjectModel : public csObjectModel
00239   {
00240     SCF_DECLARE_EMBEDDED_IBASE (csMeshObject);
00241     virtual void GetObjectBoundingBox (csBox3& bbox, int type)
00242     {
00243       scfParent->GetObjectBoundingBox (bbox, type);
00244     }
00245     virtual void GetRadius (csVector3& radius, csVector3& center)
00246     {
00247       scfParent->GetRadius (radius, center);
00248     }
00249   } scfiObjectModel;
00250   friend struct eiObjectModel;
00251 };
00252 
00257 class csMeshFactory : public iMeshObjectFactory
00258 {
00259 protected:
00261   iBase *LogParent;
00262 
00264   iEngine *Engine;
00265 
00267   iObjectRegistry* object_reg;
00268 
00269 public:
00270   SCF_DECLARE_IBASE;
00271 
00273   csMeshFactory (iEngine *engine, iObjectRegistry* object_reg);
00274 
00276   virtual ~csMeshFactory ();
00277 
00282   virtual csPtr<iMeshObject> NewInstance () = 0;
00283 
00288   virtual void HardTransform (const csReversibleTransform& t);
00289 
00294   virtual bool SupportsHardTransform () const;
00295 
00300   virtual void SetLogicalParent (iBase* logparent);
00301 
00306   virtual iBase* GetLogicalParent () const;
00307 
00311   virtual iObjectModel* GetObjectModel () { return 0; }
00312 
00313 };
00314 
00318 class csMeshType : public iMeshObjectType
00319 {
00320 protected:
00322   iEngine *Engine;
00323 
00325   iObjectRegistry* object_reg;
00326 
00327 public:
00328   SCF_DECLARE_IBASE;
00329 
00331   csMeshType (iBase *p);
00332 
00334   virtual ~csMeshType ();
00335 
00339   bool Initialize (iObjectRegistry* reg);
00340 
00345   virtual csPtr<iMeshObjectFactory> NewFactory () = 0;
00346 
00350   struct eiComponent : public iComponent
00351   {
00352     SCF_DECLARE_EMBEDDED_IBASE (csMeshType);
00353     virtual bool Initialize (iObjectRegistry* p)
00354     { return scfParent->Initialize (p); }
00355   } scfiComponent;
00356 };
00357 
00358 #endif // __CS_MESHOBJ_H__

Generated for Crystal Space by doxygen 1.2.14