CrystalSpace

Public API Reference

cstool/meshobjtmpl.h

Go to the documentation of this file.
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 
00026 #include "csextern.h"
00027 
00028 #include "csgeom/box.h"
00029 #include "csgeom/objmodel.h"
00030 #include "csutil/flags.h"
00031 #include "csutil/refarr.h"
00032 #include "csutil/scf_implementation.h"
00033 
00034 #include "ivideo/graph3d.h"
00035 #include "imesh/object.h"
00036 #include "iutil/comp.h"
00037 
00038 struct iEngine;
00039 struct iMaterialWrapper;
00040 
00041 //Deprecate these when possible!
00043 #define CS_DECLARE_SIMPLE_MESH_FACTORY(name,meshclass)                      \
00044   class name : public csMeshFactory {                                       \
00045   public:                                                                   \
00046     name (iEngine *e, iObjectRegistry* reg, iMeshObjectType* type)          \
00047     : csMeshFactory (e, reg, type) {}                                       \
00048     virtual csPtr<iMeshObject> NewInstance ()                               \
00049     { return new meshclass (Engine, this); }                                \
00050     virtual csPtr<iMeshObjectFactory> Clone () { return 0; }                \
00051   };
00052 
00054 #define CS_DECLARE_SIMPLE_MESH_PLUGIN(name,factclass)                       \
00055   class name : public csMeshType {                                          \
00056   public:                                                                   \
00057     name (iBase *p) : csMeshType (p) {}                                     \
00058     virtual csPtr<iMeshObjectFactory> NewFactory ()                         \
00059     { return new factclass (Engine, object_reg, this); }                    \
00060   };
00061 
00073 class CS_CRYSTALSPACE_EXPORT csMeshObject : 
00074   public scfImplementationExt1<csMeshObject, csObjectModel, iMeshObject>
00075 {
00076 protected:
00078   csRef<iMeshObjectDrawCallback> VisCallback;
00079 
00081   iMeshWrapper *LogParent;
00082 
00084   iEngine *Engine;
00085 
00087   void WantToDie ();
00088 
00090   csFlags flags;
00091 
00093   csBox3 boundingbox;
00094 
00095 public:
00096 
00098   csMeshObject (iEngine *engine);
00099 
00101   virtual ~csMeshObject ();
00102 
00107   virtual iMeshObjectFactory* GetFactory () const = 0;
00108 
00113   virtual csPtr<iMeshObject> Clone () { return 0; }
00114   
00118   virtual csFlags& GetFlags () { return flags; }
00119 
00124   virtual csRenderMesh** GetRenderMeshes (int& num, iRenderView*, iMovable*,
00125         uint32)
00126   {
00127     num = 0;
00128     return 0;
00129   }
00130 
00136   virtual void SetVisibleCallback (iMeshObjectDrawCallback* cb);
00137 
00142   virtual iMeshObjectDrawCallback* GetVisibleCallback () const;
00143 
00148   virtual void NextFrame (csTicks current_time,const csVector3& pos);
00149 
00154   virtual void HardTransform (const csReversibleTransform& t);
00155 
00160   virtual bool SupportsHardTransform () const;
00161 
00166   virtual bool HitBeamOutline (const csVector3& start,
00167         const csVector3& end, csVector3& isect, float* pr);
00168 
00173   virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00174         csVector3& isect, float* pr, int* polygon_idx = 0,
00175         iMaterialWrapper** = 0);
00176 
00181   virtual void SetMeshWrapper (iMeshWrapper* logparent);
00182 
00187   virtual iMeshWrapper* GetMeshWrapper () const;
00188 
00192   virtual iObjectModel* GetObjectModel () { return this; }
00193 
00198   virtual bool SetColor (const csColor& color);
00199 
00204   virtual bool GetColor (csColor& color) const;
00205 
00210   virtual bool SetMaterialWrapper (iMaterialWrapper* material);
00211 
00216   virtual iMaterialWrapper* GetMaterialWrapper () const;
00217 
00219   virtual void SetMixMode (uint) { }
00221   virtual uint GetMixMode () const { return CS_FX_COPY; }
00222 
00227   virtual void InvalidateMaterialHandles () { }
00228 
00233   virtual void PositionChild (iMeshObject* /*child*/,csTicks /*current_time*/) { }
00234 
00239   virtual void GetObjectBoundingBox (csBox3& bbox);
00240 
00245   virtual void SetObjectBoundingBox (const csBox3& bbox);
00246 
00251   virtual void GetRadius (csVector3& radius, csVector3& center);
00252 
00253 };
00254 
00259 class CS_CRYSTALSPACE_EXPORT csMeshFactory : 
00260   public scfImplementation1<csMeshFactory, iMeshObjectFactory>
00261 {
00262 protected:
00264   iMeshFactoryWrapper *LogParent;
00265 
00267   iMeshObjectType* mesh_type;
00268 
00270   iEngine *Engine;
00271 
00273   iObjectRegistry* object_reg;
00274 
00276   csFlags flags;
00277 
00278 public:
00279 
00281   csMeshFactory (iEngine *engine, iObjectRegistry* object_reg,
00282     iMeshObjectType* parent);
00283 
00285   iObjectRegistry* GetObjectRegistry () { return object_reg; }
00286 
00288   virtual ~csMeshFactory ();
00289 
00293   virtual csFlags& GetFlags () { return flags; }
00294 
00299   virtual csPtr<iMeshObject> NewInstance () = 0;
00300 
00305   virtual void HardTransform (const csReversibleTransform& t);
00306 
00311   virtual bool SupportsHardTransform () const;
00312 
00317   virtual void SetMeshFactoryWrapper (iMeshFactoryWrapper* logparent);
00318 
00323   virtual iMeshFactoryWrapper* GetMeshFactoryWrapper () const;
00324 
00328   virtual iMeshObjectType* GetMeshObjectType () const;
00329 
00333   virtual iObjectModel* GetObjectModel () { return 0; }
00334 
00335 };
00336 
00340 class CS_CRYSTALSPACE_EXPORT csMeshType : 
00341   public scfImplementation2<csMeshType, iMeshObjectType, iComponent>
00342 {
00343 protected:
00345   iEngine *Engine;
00346 
00348   iObjectRegistry* object_reg;
00349 
00350 public:
00351 
00353   csMeshType (iBase *p);
00354 
00356   virtual ~csMeshType ();
00357 
00361   bool Initialize (iObjectRegistry* reg);
00362 
00367   virtual csPtr<iMeshObjectFactory> NewFactory () = 0;
00368 
00369 };
00370 
00371 #endif // __CS_MESHOBJTMPL_H__

Generated for Crystal Space by doxygen 1.4.6