CrystalSpace

Public API Reference

imesh/terrain2.h

00001 /*
00002   Copyright (C) 2006 by Kapoulkine Arseny
00003                 2007 by Marten Svanfeldt
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014 
00015   You should have received a copy of the GNU Library General Public
00016   License along with this library; if not, write to the Free
00017   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_IMESH_TERRAIN2_H__
00021 #define __CS_IMESH_TERRAIN2_H__
00022 
00023 #include "csutil/scf_interface.h"
00024 #include "iutil/array.h"
00025 #include "ivideo/shader/shader.h"
00026 
00027 class csVector3;
00028 struct csCollisionPair;
00029 struct iCollider;
00030 struct iTerrainCell;
00031 struct iRenderView;
00032 struct iTerrainSystem;
00033 struct iMovable;
00034 
00044 struct csLockedHeightData
00045 {
00047   float* data;
00048 
00050   size_t pitch;     
00051 };
00052 
00062 struct csLockedMaterialMap
00063 {
00065   unsigned char* data;  
00066 
00068   size_t pitch; 
00069 };
00070 
00072 struct iTerrainVector3Array : public iArrayChangeAll<csVector3>
00073 {
00074   SCF_IARRAYCHANGEALL_INTERFACE(iTerrainVector3Array);
00075 };
00076 
00078 struct iTerrainCollisionPairArray : public iArrayChangeAll<csCollisionPair>
00079 {
00080   SCF_IARRAYCHANGEALL_INTERFACE(iTerrainCollisionPairArray);
00081 };
00082 
00084 typedef csRefArray<iMaterialWrapper> csTerrainMaterialPalette;
00085 
00086 
00092 struct iTerrainCellCollisionProperties : public virtual iBase
00093 {
00094   SCF_INTERFACE (iTerrainCellCollisionProperties, 2, 0, 0);
00095 
00102   virtual bool GetCollidable () const = 0;
00103   
00109   virtual void SetCollidable (bool value) = 0;
00110 
00117   virtual void SetParameter(const char* param, const char* value) = 0;
00118 
00122   virtual csPtr<iTerrainCellCollisionProperties> Clone () = 0;
00123 };
00124 
00131 struct iTerrainCellRenderProperties : public virtual iShaderVariableContext
00132 {
00133   SCF_INTERFACE (iTerrainCellRenderProperties, 2, 0, 0);
00134 
00140   virtual bool GetVisible () const = 0;
00141   
00147   virtual void SetVisible (bool value) = 0;
00148   
00155   virtual void SetParameter (const char* param, const char* value) = 0;
00156 
00160   virtual csPtr<iTerrainCellRenderProperties> Clone () = 0;
00161 };
00162 
00166 struct iTerrainCellFeederProperties : public virtual iBase
00167 {
00168   SCF_INTERFACE (iTerrainCellFeederProperties, 2, 0, 0);
00169   
00173   virtual void SetHeightmapSource (const char* source) = 0;
00174 
00181   virtual void SetParameter (const char* param, const char* value) = 0;
00182 
00186   virtual csPtr<iTerrainCellFeederProperties> Clone () = 0;
00187 };
00188 
00192 struct iTerrainDataFeeder : public virtual iBase
00193 {
00194   SCF_INTERFACE (iTerrainDataFeeder, 2, 0, 0);
00195 
00203   virtual csPtr<iTerrainCellFeederProperties> CreateProperties () = 0;
00204 
00214   virtual bool PreLoad (iTerrainCell* cell) = 0;
00215   
00224   virtual bool Load (iTerrainCell* cell) = 0;
00225 
00232   virtual void SetParameter (const char* param, const char* value) = 0;
00233 };
00234 
00238 struct csTerrainColliderCollideSegmentResult
00239 {
00241   bool hit;
00242 
00244   csVector3 isect;
00245 
00247 
00248   csVector3 a, b, c;    
00250 };
00251 
00253 struct iTerrainCollider : public virtual iBase
00254 {
00255   SCF_INTERFACE (iTerrainCollider, 2, 0, 1);
00256 
00264   virtual csPtr<iTerrainCellCollisionProperties> CreateProperties () = 0;
00265   
00279   virtual bool CollideSegment (iTerrainCell* cell, const csVector3& start,
00280                                const csVector3& end, bool oneHit, 
00281                                iTerrainVector3Array* points) = 0;
00282 
00293   virtual csTerrainColliderCollideSegmentResult CollideSegment (
00294       iTerrainCell* cell, const csVector3& start, const csVector3& end) = 0;
00295 
00313   virtual bool CollideTriangles (iTerrainCell* cell, const csVector3* vertices,
00314                                  size_t tri_count,
00315                                  const unsigned int* indices, float radius,
00316                                  const csReversibleTransform& trans,
00317                                  bool oneHit, iTerrainCollisionPairArray* pairs) = 0;
00318 
00334   virtual bool Collide (iTerrainCell* cell, iCollider* collider,
00335                        float radius, const csReversibleTransform& trans,
00336                        bool oneHit, iTerrainCollisionPairArray* pairs) = 0;
00337 };
00338 
00339 
00341 struct iTerrainRenderer : public virtual iBase
00342 {
00343   SCF_INTERFACE (iTerrainRenderer, 2, 0, 0);
00344 
00352   virtual csPtr<iTerrainCellRenderProperties> CreateProperties () = 0;
00353 
00358   virtual void ConnectTerrain (iTerrainSystem* system) = 0;
00359 
00363   virtual void DisconnectTerrain (iTerrainSystem* system) = 0;
00364 
00365 
00379   virtual csRenderMesh** GetRenderMeshes (int& n, iRenderView* rview,
00380                                    iMovable* movable, uint32 frustum_mask,
00381                                    const csArray<iTerrainCell*> cells) = 0;
00382 
00383   
00390   virtual void OnMaterialPaletteUpdate (const csTerrainMaterialPalette&
00391                                         material_palette) = 0;
00392 
00406   virtual void OnMaterialMaskUpdate (iTerrainCell* cell, size_t material,
00407                                const csRect& rectangle, 
00408                                const unsigned char* data, size_t pitch) = 0; 
00409 };
00410 
00412 struct iTerrainCellHeightDataCallback : public virtual iBase
00413 {
00414   SCF_INTERFACE (iTerrainCellHeightDataCallback, 1, 0, 0);
00415 
00422   virtual void OnHeightUpdate (iTerrainCell* cell, const csRect& rectangle) = 0;
00423 };
00424 
00426 struct iTerrainCellLoadCallback : public virtual iBase
00427 {
00428   SCF_INTERFACE (iTerrainCellLoadCallback, 1, 0, 0);
00429 
00435   virtual void OnCellLoad (iTerrainCell* cell) = 0;
00436 
00442   virtual void OnCellPreLoad (iTerrainCell* cell) = 0;
00443 
00449   virtual void OnCellUnload (iTerrainCell* cell) = 0;
00450 };
00451 
00458 struct iTerrainSystem : public virtual iBase
00459 {
00460   SCF_INTERFACE (iTerrainSystem, 2, 0, 0);
00461 
00470   virtual iTerrainCell* GetCell (const char* name, bool loadData = false) = 0;
00471 
00483   virtual iTerrainCell* GetCell (const csVector2& pos, bool loadData = false) = 0;
00484 
00491   virtual iTerrainCell* GetCell (size_t index, bool loadData = false) = 0;
00492 
00496   virtual size_t GetCellCount () const = 0;
00497 
00503   virtual const csTerrainMaterialPalette& GetMaterialPalette () const = 0;
00504   
00510   virtual void SetMaterialPalette (const csTerrainMaterialPalette& array) = 0;
00511 
00530   virtual bool CollideSegment (const csVector3& start, const csVector3& end,
00531                            bool oneHit, iTerrainVector3Array* points) = 0;
00532 
00549   virtual csTerrainColliderCollideSegmentResult CollideSegment (
00550       const csVector3& start, const csVector3& end,
00551       bool use_ray = false) = 0;
00552 
00575   virtual bool CollideTriangles (const csVector3* vertices,
00576                        size_t tri_count,
00577                        const unsigned int* indices, float radius,
00578                        const csReversibleTransform& trans,
00579                        bool oneHit, iTerrainCollisionPairArray* pairs) = 0;
00580 
00601   virtual bool Collide (iCollider* collider, float radius,
00602                        const csReversibleTransform& trans, bool oneHit,
00603                        iTerrainCollisionPairArray* pairs) = 0;
00604 
00611   virtual float GetVirtualViewDistance () const = 0;
00612   
00619   virtual void SetVirtualViewDistance (float distance) = 0;
00620 
00628   virtual bool GetAutoPreLoad () const = 0;
00629   
00635   virtual void SetAutoPreLoad (bool mode) = 0;
00636 
00649   virtual void PreLoadCells (iRenderView* rview, iMovable* movable) = 0;
00650   
00662   virtual float GetHeight (const csVector2& pos) = 0;
00663   
00674   virtual csVector3 GetTangent (const csVector2& pos) = 0;
00675   
00686   virtual csVector3 GetBinormal (const csVector2& pos) = 0;
00687 
00698   virtual csVector3 GetNormal (const csVector2& pos) = 0;
00699 
00705   virtual size_t GetMaxLoadedCells () const = 0;
00706 
00714   virtual void SetMaxLoadedCells (size_t value) = 0;
00715 
00719   virtual void UnloadOldCells () = 0;
00720 
00724   virtual void AddCellLoadListener (iTerrainCellLoadCallback* cb) = 0;
00725 
00729   virtual void RemoveCellLoadListener (iTerrainCellLoadCallback* cb) = 0;
00730   
00734   virtual void AddCellHeightUpdateListener (iTerrainCellHeightDataCallback* cb) = 0;
00735 
00739   virtual void RemoveCellHeightUpdateListener (iTerrainCellHeightDataCallback* cb) = 0;  
00740 };
00741 
00750 struct iTerrainCell : public virtual iBase
00751 {
00752   SCF_INTERFACE (iTerrainCell, 2, 0, 0);
00753 
00755   enum LoadState
00756   {
00757     NotLoaded,    
00759     PreLoaded,    
00761     Loaded        
00762   };
00763 
00769   virtual LoadState GetLoadState () const = 0;
00770 
00786   virtual void SetLoadState (LoadState state) = 0;
00787 
00793   virtual iTerrainSystem* GetTerrain () = 0;
00794 
00802   virtual const char* GetName () const = 0;
00803 
00810   virtual iTerrainCellRenderProperties* GetRenderProperties () const = 0;
00811   
00818   virtual iTerrainCellCollisionProperties* GetCollisionProperties () const = 0;
00819 
00826   virtual iTerrainCellFeederProperties* GetFeederProperties () const = 0;
00827 
00834   virtual int GetGridWidth () const = 0;
00835   
00842   virtual int GetGridHeight () const = 0;
00843 
00850   virtual csLockedHeightData GetHeightData () = 0;
00851   
00865   virtual csLockedHeightData LockHeightData (const csRect& rectangle) = 0;
00866   
00872   virtual void UnlockHeightData () = 0;
00873 
00880   virtual const csVector2& GetPosition () const = 0;
00881   
00890   virtual const csVector3& GetSize () const = 0;
00891 
00898   virtual int GetMaterialMapWidth () const = 0;
00899   
00906   virtual int GetMaterialMapHeight () const = 0;
00907 
00913   virtual bool GetMaterialPersistent() const = 0;
00914 
00933   virtual csLockedMaterialMap LockMaterialMap (const csRect& rectangle) = 0;
00934 
00943   virtual void UnlockMaterialMap() = 0;
00944 
00954   virtual void SetMaterialMask (unsigned int material, iImage* image) = 0;
00955   
00967   virtual void SetMaterialMask (unsigned int material, const unsigned char*
00968                           data, unsigned int width, unsigned int height) = 0;
00969   
00975   virtual void SetBaseMaterial (iMaterialWrapper* material) = 0;
00976 
00980   virtual iMaterialWrapper* GetBaseMaterial () const = 0;
00981 
00994   virtual bool CollideSegment (const csVector3& start, const csVector3& end,
00995                            bool oneHit, iTerrainVector3Array* points) = 0;
00996 
01013   virtual bool CollideTriangles (const csVector3* vertices,
01014                        size_t tri_count,
01015                        const unsigned int* indices, float radius,
01016                        const csReversibleTransform& trans,
01017                        bool oneHit, iTerrainCollisionPairArray* pairs) = 0;
01018 
01033   virtual bool Collide (iCollider* collider, float radius,
01034                        const csReversibleTransform& trans, bool oneHit,
01035                        iTerrainCollisionPairArray* pairs) = 0;
01036 
01046   virtual float GetHeight (int x, int y) const = 0;
01047 
01056   virtual float GetHeight (const csVector2& pos) const = 0;
01057   
01066   virtual csVector3 GetTangent (int x, int y) const = 0;
01067   
01075   virtual csVector3 GetTangent (const csVector2& pos) const = 0;
01076 
01085   virtual csVector3 GetBinormal (int x, int y) const = 0;
01086   
01094   virtual csVector3 GetBinormal (const csVector2& pos) const = 0;
01095 
01104   virtual csVector3 GetNormal (int x, int y) const = 0;
01105   
01113   virtual csVector3 GetNormal (const csVector2& pos) const = 0;
01114 
01116   virtual csRefCount* GetRenderData () const = 0;
01117 
01119   virtual void SetRenderData (csRefCount* data) = 0;
01120 
01122   virtual csRefCount* GetCollisionData () const = 0;
01123 
01125   virtual void SetCollisionData (csRefCount* data) = 0;
01126 
01128   virtual csRefCount* GetFeederData () const = 0;
01129 
01131   virtual void SetFeederData (csRefCount* data) = 0;
01132 };
01133 
01135 struct iTerrainFactoryCell : public virtual iBase
01136 {
01137   SCF_INTERFACE (iTerrainFactoryCell, 1, 0 ,0);
01138 
01145   virtual iTerrainCellRenderProperties* GetRenderProperties () const = 0;
01146   
01153   virtual iTerrainCellCollisionProperties* GetCollisionProperties () const = 0;
01154 
01161   virtual iTerrainCellFeederProperties* GetFeederProperties () const = 0;
01162 
01168   virtual void SetBaseMaterial (iMaterialWrapper* material) = 0;
01169 };
01170 
01172 struct iTerrainFactory : public virtual iBase
01173 {
01174   SCF_INTERFACE (iTerrainFactory, 2, 0, 0);
01175 
01181   virtual void SetRenderer (iTerrainRenderer* renderer) = 0;
01182   
01188   virtual void SetCollider (iTerrainCollider* collider) = 0;
01189 
01195   virtual void SetFeeder (iTerrainDataFeeder* feeder) = 0;
01196   
01217   virtual iTerrainFactoryCell* AddCell (const char* name, 
01218     int gridWidth, int gridHeight, int materialMapWidth,
01219     int materialMapHeight, bool materiaMapPersistent,
01220     const csVector2& position, const csVector3& size) = 0;
01221   
01227   virtual void SetMaxLoadedCells (size_t number) = 0;
01228   
01235   virtual void SetVirtualViewDistance (float distance) = 0;
01236   
01242   virtual void SetAutoPreLoad (bool mode) = 0;
01243 };
01244 
01245 
01246 #endif

Generated for Crystal Space 1.2.1 by doxygen 1.5.3