CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class 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_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, iMeshObjectType* type)          \
00036     : csMeshFactory (e, reg, type) {}                                       \
00037     virtual csPtr<iMeshObject> NewInstance ()                               \
00038     { return new meshclass (Engine, this); }                                \
00039     virtual csPtr<iMeshObjectFactory> Clone () { return 0; }                \
00040   };
00041 
00043 #define CS_DECLARE_SIMPLE_MESH_PLUGIN(name,factclass)                       \
00044   class name : public csMeshType {                                          \
00045   public:                                                                   \
00046     name (iBase *p) : csMeshType (p) {}                                     \
00047     virtual csPtr<iMeshObjectFactory> NewFactory ()                         \
00048     { return new factclass (Engine, object_reg, this); }                    \
00049   };
00050 
00064 class CS_CSTOOL_EXPORT csMeshObject : public iMeshObject
00065 {
00066 protected:
00068   csRef<iMeshObjectDrawCallback> VisCallback;
00069 
00071   iBase *LogParent;
00072 
00074   iEngine *Engine;
00075 
00077   void WantToDie ();
00078 
00080   csFlags flags;
00081 
00083   csBox3 boundingbox;
00084 
00085 public:
00086   SCF_DECLARE_IBASE;
00087 
00089   csMeshObject (iEngine *engine);
00090 
00092   virtual ~csMeshObject ();
00093 
00098   virtual iMeshObjectFactory* GetFactory () const = 0;
00099 
00104   virtual csPtr<iMeshObject> Clone () { return 0; }
00105   
00109   virtual csFlags& GetFlags () { return flags; }
00110 
00117   virtual csRenderMesh** GetRenderMeshes (int& num, iRenderView*, iMovable*,
00118         uint32)
00119   {
00120     num = 0;
00121     return 0;
00122   }
00123 
00129   virtual void SetVisibleCallback (iMeshObjectDrawCallback* cb);
00130 
00135   virtual iMeshObjectDrawCallback* GetVisibleCallback () const;
00136 
00141   virtual void NextFrame (csTicks current_time,const csVector3& pos);
00142 
00147   virtual void HardTransform (const csReversibleTransform& t);
00148 
00153   virtual bool SupportsHardTransform () const;
00154 
00159   virtual bool HitBeamOutline (const csVector3& start,
00160         const csVector3& end, csVector3& isect, float* pr);
00161 
00166   virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00167         csVector3& isect, float* pr, int* polygon_idx = 0);
00168 
00173   virtual void SetLogicalParent (iBase* logparent);
00174 
00179   virtual iBase* GetLogicalParent () const;
00180 
00184   virtual iObjectModel* GetObjectModel () { return &scfiObjectModel; }
00185 
00190   virtual bool SetColor (const csColor& color);
00191 
00196   virtual bool GetColor (csColor& color) const;
00197 
00202   virtual bool SetMaterialWrapper (iMaterialWrapper* material);
00203 
00208   virtual iMaterialWrapper* GetMaterialWrapper () const;
00209 
00214   virtual void InvalidateMaterialHandles () { }
00215 
00220   virtual void PositionChild (iMeshObject* child,csTicks current_time) { }
00221 
00226   virtual void GetObjectBoundingBox (csBox3& bbox);
00227 
00232   virtual void SetObjectBoundingBox (const csBox3& bbox);
00233 
00238   virtual void GetRadius (csVector3& radius, csVector3& center);
00239 
00240   // implementation of iObjectModel
00241   struct CS_CSTOOL_EXPORT eiObjectModel : public csObjectModel
00242   {
00243     SCF_DECLARE_EMBEDDED_IBASE (csMeshObject);
00244     virtual void GetObjectBoundingBox (csBox3& bbox)
00245     {
00246       scfParent->GetObjectBoundingBox (bbox);
00247     }
00248     virtual void SetObjectBoundingBox (const csBox3& bbox)
00249     {
00250       scfParent->SetObjectBoundingBox (bbox);
00251     }
00252     virtual void GetRadius (csVector3& radius, csVector3& center)
00253     {
00254       scfParent->GetRadius (radius, center);
00255     }
00256   } scfiObjectModel;
00257   friend struct eiObjectModel;
00258 };
00259 
00264 class CS_CSTOOL_EXPORT csMeshFactory : public iMeshObjectFactory
00265 {
00266 protected:
00268   iBase *LogParent;
00269 
00271   iMeshObjectType* mesh_type;
00272 
00274   iEngine *Engine;
00275 
00277   iObjectRegistry* object_reg;
00278 
00280   csFlags flags;
00281 
00282 public:
00283   SCF_DECLARE_IBASE;
00284 
00286   csMeshFactory (iEngine *engine, iObjectRegistry* object_reg,
00287     iMeshObjectType* parent);
00288 
00290   iObjectRegistry* GetObjectRegistry () { return object_reg; }
00291 
00293   virtual ~csMeshFactory ();
00294 
00298   virtual csFlags& GetFlags () { return flags; }
00299 
00304   virtual csPtr<iMeshObject> NewInstance () = 0;
00305 
00310   virtual void HardTransform (const csReversibleTransform& t);
00311 
00316   virtual bool SupportsHardTransform () const;
00317 
00322   virtual void SetLogicalParent (iBase* logparent);
00323 
00328   virtual iBase* GetLogicalParent () const;
00329 
00333   virtual iMeshObjectType* GetMeshObjectType () const;
00334 
00338   virtual iObjectModel* GetObjectModel () { return 0; }
00339 
00340 };
00341 
00345 class CS_CSTOOL_EXPORT csMeshType : public iMeshObjectType
00346 {
00347 protected:
00349   iEngine *Engine;
00350 
00352   iObjectRegistry* object_reg;
00353 
00354 public:
00355   SCF_DECLARE_IBASE;
00356 
00358   csMeshType (iBase *p);
00359 
00361   virtual ~csMeshType ();
00362 
00366   bool Initialize (iObjectRegistry* reg);
00367 
00372   virtual csPtr<iMeshObjectFactory> NewFactory () = 0;
00373 
00377   struct CS_CSTOOL_EXPORT eiComponent : public iComponent
00378   {
00379     SCF_DECLARE_EMBEDDED_IBASE (csMeshType);
00380     virtual bool Initialize (iObjectRegistry* p)
00381     { return scfParent->Initialize (p); }
00382   } scfiComponent;
00383 };
00384 
00385 #endif // __CS_MESHOBJTMPL_H__

Generated for Crystal Space by doxygen 1.3.9.1