CrystalSpace

Public API Reference

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

cstool/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_MESHOBJTMPL_H__
00020 #define __CS_MESHOBJTMPL_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     num = 0;
00105     return 0;
00106   }
00107 
00112   virtual bool Draw (iRenderView* rview, iMovable* movable,
00113         csZBufMode zbufMode) = 0;
00114 
00120   virtual void SetVisibleCallback (iMeshObjectDrawCallback* cb);
00121 
00126   virtual iMeshObjectDrawCallback* GetVisibleCallback () const;
00127 
00132   virtual void NextFrame (csTicks current_time,const csVector3& pos);
00133 
00138   virtual void HardTransform (const csReversibleTransform& t);
00139 
00144   virtual bool SupportsHardTransform () const;
00145 
00150   virtual bool HitBeamOutline (const csVector3& start,
00151         const csVector3& end, csVector3& isect, float* pr);
00152 
00157   virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00158         csVector3& isect, float* pr, int* polygon_idx = 0);
00159 
00164   virtual void SetLogicalParent (iBase* logparent);
00165 
00170   virtual iBase* GetLogicalParent () const;
00171 
00175   virtual iObjectModel* GetObjectModel () { return &scfiObjectModel; }
00176 
00181   virtual bool SetColor (const csColor& color);
00182 
00187   virtual bool GetColor (csColor& color) const;
00188 
00193   virtual bool SetMaterialWrapper (iMaterialWrapper* material);
00194 
00199   virtual iMaterialWrapper* GetMaterialWrapper () const;
00200 
00205   virtual void InvalidateMaterialHandles () { }
00206 
00211   virtual void PositionChild (iMeshObject* child,csTicks current_time) { }
00212 
00213 
00218   virtual void GetObjectBoundingBox (csBox3& bbox, int type);
00219 
00224   virtual void GetRadius (csVector3& radius, csVector3& center);
00225 
00226   // implementation of iObjectModel
00227   struct eiObjectModel : public csObjectModel
00228   {
00229     SCF_DECLARE_EMBEDDED_IBASE (csMeshObject);
00230     virtual void GetObjectBoundingBox (csBox3& bbox, int type)
00231     {
00232       scfParent->GetObjectBoundingBox (bbox, type);
00233     }
00234     virtual void GetRadius (csVector3& radius, csVector3& center)
00235     {
00236       scfParent->GetRadius (radius, center);
00237     }
00238   } scfiObjectModel;
00239   friend struct eiObjectModel;
00240 };
00241 
00246 class csMeshFactory : public iMeshObjectFactory
00247 {
00248 protected:
00250   iBase *LogParent;
00251 
00253   iEngine *Engine;
00254 
00256   iObjectRegistry* object_reg;
00257 
00258 public:
00259   SCF_DECLARE_IBASE;
00260 
00262   csMeshFactory (iEngine *engine, iObjectRegistry* object_reg);
00263 
00265   iObjectRegistry* GetObjectRegistry () { return object_reg; }
00266 
00268   virtual ~csMeshFactory ();
00269 
00274   virtual csPtr<iMeshObject> NewInstance () = 0;
00275 
00280   virtual void HardTransform (const csReversibleTransform& t);
00281 
00286   virtual bool SupportsHardTransform () const;
00287 
00292   virtual void SetLogicalParent (iBase* logparent);
00293 
00298   virtual iBase* GetLogicalParent () const;
00299 
00303   virtual iObjectModel* GetObjectModel () { return 0; }
00304 
00305 };
00306 
00310 class csMeshType : public iMeshObjectType
00311 {
00312 protected:
00314   iEngine *Engine;
00315 
00317   iObjectRegistry* object_reg;
00318 
00319 public:
00320   SCF_DECLARE_IBASE;
00321 
00323   csMeshType (iBase *p);
00324 
00326   virtual ~csMeshType ();
00327 
00331   bool Initialize (iObjectRegistry* reg);
00332 
00337   virtual csPtr<iMeshObjectFactory> NewFactory () = 0;
00338 
00342   struct eiComponent : public iComponent
00343   {
00344     SCF_DECLARE_EMBEDDED_IBASE (csMeshType);
00345     virtual bool Initialize (iObjectRegistry* p)
00346     { return scfParent->Initialize (p); }
00347   } scfiComponent;
00348 };
00349 
00350 #endif // __CS_MESHOBJTMPL_H__

Generated for Crystal Space by doxygen 1.2.18