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 "csextern.h"
00023 
00024 #include "csutil/refarr.h"
00025 #include "iengine/material.h"
00026 #include "iengine/engine.h"
00027 #include "iengine/mesh.h"
00028 #include "imesh/object.h"
00029 #include "csgeom/objmodel.h"
00030 
00032 #define CS_DECLARE_SIMPLE_MESH_FACTORY(name,meshclass)                      \
00033   class name : public csMeshFactory {                                       \
00034   public:                                                                   \
00035     name (iEngine *e, iObjectRegistry* reg) : csMeshFactory (e, reg) {}     \
00036     virtual csPtr<iMeshObject> NewInstance ()                               \
00037     { return new meshclass (Engine, this); }                                \
00038     virtual csPtr<iMeshObjectFactory> Clone () { return 0; }                \
00039   };
00040 
00042 #define CS_DECLARE_SIMPLE_MESH_PLUGIN(name,factclass)                       \
00043   class name : public csMeshType {                                          \
00044   public:                                                                   \
00045     name (iBase *p) : csMeshType (p) {}                                     \
00046     virtual csPtr<iMeshObjectFactory> NewFactory ()                         \
00047     { return new factclass (Engine, object_reg); }                          \
00048   };
00049 
00063 class CS_CSTOOL_EXPORT csMeshObject : public iMeshObject
00064 {
00065 protected:
00067   csRef<iMeshObjectDrawCallback> VisCallback;
00068 
00070   iBase *LogParent;
00071 
00073   iEngine *Engine;
00074 
00076   void WantToDie ();
00077 
00079   csFlags flags;
00080 
00081 public:
00082   SCF_DECLARE_IBASE;
00083 
00085   csMeshObject (iEngine *engine);
00086 
00088   virtual ~csMeshObject ();
00089 
00094   virtual iMeshObjectFactory* GetFactory () const = 0;
00095 
00100   virtual csPtr<iMeshObject> Clone () { return 0; }
00101   
00105   virtual csFlags& GetFlags () { return flags; }
00106 
00111   virtual bool DrawTest (iRenderView* rview, iMovable* movable,
00112         uint32 frustum_mask);
00113 
00120   virtual csRenderMesh** GetRenderMeshes (int& num, iRenderView*, iMovable*,
00121         uint32)
00122   {
00123     num = 0;
00124     return 0;
00125   }
00126 
00131   virtual bool Draw (iRenderView* rview, iMovable* movable,
00132         csZBufMode zbufMode) = 0;
00133 
00139   virtual void SetVisibleCallback (iMeshObjectDrawCallback* cb);
00140 
00145   virtual iMeshObjectDrawCallback* GetVisibleCallback () const;
00146 
00151   virtual void NextFrame (csTicks current_time,const csVector3& pos);
00152 
00157   virtual void HardTransform (const csReversibleTransform& t);
00158 
00163   virtual bool SupportsHardTransform () const;
00164 
00169   virtual bool HitBeamOutline (const csVector3& start,
00170         const csVector3& end, csVector3& isect, float* pr);
00171 
00176   virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00177         csVector3& isect, float* pr, int* polygon_idx = 0);
00178 
00183   virtual void SetLogicalParent (iBase* logparent);
00184 
00189   virtual iBase* GetLogicalParent () const;
00190 
00194   virtual iObjectModel* GetObjectModel () { return &scfiObjectModel; }
00195 
00200   virtual bool SetColor (const csColor& color);
00201 
00206   virtual bool GetColor (csColor& color) const;
00207 
00212   virtual bool SetMaterialWrapper (iMaterialWrapper* material);
00213 
00218   virtual iMaterialWrapper* GetMaterialWrapper () const;
00219 
00224   virtual void InvalidateMaterialHandles () { }
00225 
00230   virtual void PositionChild (iMeshObject* child,csTicks current_time) { }
00231 
00232 
00237   virtual void GetObjectBoundingBox (csBox3& bbox, int type);
00238 
00243   virtual void GetRadius (csVector3& radius, csVector3& center);
00244 
00245   // implementation of iObjectModel
00246   struct CS_CSTOOL_EXPORT eiObjectModel : public csObjectModel
00247   {
00248     SCF_DECLARE_EMBEDDED_IBASE (csMeshObject);
00249     virtual void GetObjectBoundingBox (csBox3& bbox, int type)
00250     {
00251       scfParent->GetObjectBoundingBox (bbox, type);
00252     }
00253     virtual void GetRadius (csVector3& radius, csVector3& center)
00254     {
00255       scfParent->GetRadius (radius, center);
00256     }
00257   } scfiObjectModel;
00258   friend struct eiObjectModel;
00259 };
00260 
00265 class CS_CSTOOL_EXPORT csMeshFactory : public iMeshObjectFactory
00266 {
00267 protected:
00269   iBase *LogParent;
00270 
00272   iEngine *Engine;
00273 
00275   iObjectRegistry* object_reg;
00276 
00278   csFlags flags;
00279 
00280 public:
00281   SCF_DECLARE_IBASE;
00282 
00284   csMeshFactory (iEngine *engine, iObjectRegistry* object_reg);
00285 
00287   iObjectRegistry* GetObjectRegistry () { return object_reg; }
00288 
00290   virtual ~csMeshFactory ();
00291 
00295   virtual csFlags& GetFlags () { return flags; }
00296 
00301   virtual csPtr<iMeshObject> NewInstance () = 0;
00302 
00307   virtual void HardTransform (const csReversibleTransform& t);
00308 
00313   virtual bool SupportsHardTransform () const;
00314 
00319   virtual void SetLogicalParent (iBase* logparent);
00320 
00325   virtual iBase* GetLogicalParent () const;
00326 
00330   virtual iObjectModel* GetObjectModel () { return 0; }
00331 
00332 };
00333 
00337 class CS_CSTOOL_EXPORT csMeshType : public iMeshObjectType
00338 {
00339 protected:
00341   iEngine *Engine;
00342 
00344   iObjectRegistry* object_reg;
00345 
00346 public:
00347   SCF_DECLARE_IBASE;
00348 
00350   csMeshType (iBase *p);
00351 
00353   virtual ~csMeshType ();
00354 
00358   bool Initialize (iObjectRegistry* reg);
00359 
00364   virtual csPtr<iMeshObjectFactory> NewFactory () = 0;
00365 
00369   struct CS_CSTOOL_EXPORT eiComponent : public iComponent
00370   {
00371     SCF_DECLARE_EMBEDDED_IBASE (csMeshType);
00372     virtual bool Initialize (iObjectRegistry* p)
00373     { return scfParent->Initialize (p); }
00374   } scfiComponent;
00375 };
00376 
00377 #endif // __CS_MESHOBJTMPL_H__

Generated for Crystal Space by doxygen 1.2.18