imesh/terrain2.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

imesh/terrain2.h
Go to the documentation of this file.

    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
    00027 #include "csutil/scf_interface.h"
    00028 #include "iutil/array.h"
    00029 #include "ivideo/shader/shader.h"
    00030 #include "imesh/object.h"
    00031
    00032 class csVector3;
    00033 struct csCollisionPair;
    00034 struct iCollider;
    00035 struct iTerrainCell;
    00036 struct iRenderView;
    00037 struct iTerrainSystem;
    00038 struct iMovable;
    00039
    00049 struct csLockedHeightData
    00050 {
    00052   float* data;
    00053
    00055   size_t pitch;
    00056 };
    00057
    00067 struct csLockedMaterialMap
    00068 {
    00070   unsigned char* data;
    00071
    00073   size_t pitch;
    00074 };
    00075
    00084 struct csLockedNormalData
    00085 {
    00087   csVector3* data;
    00088
    00090   size_t pitch;
    00091 };
    00092
    00094 struct iTerrainVector3Array : public iArrayChangeAll<csVector3>
    00095 {
    00096   SCF_IARRAYCHANGEALL_INTERFACE(iTerrainVector3Array);
    00097 };
    00098
    00100 struct iTerrainCollisionPairArray : public iArrayChangeAll<csCollisionPair>
    00101 {
    00102   SCF_IARRAYCHANGEALL_INTERFACE(iTerrainCollisionPairArray);
    00103 };
    00104
    00106 typedef csRefArray<iMaterialWrapper> csTerrainMaterialPalette;
    00107
    00108
    00114 struct iTerrainCellCollisionProperties : public virtual iBase
    00115 {
    00116   SCF_INTERFACE (iTerrainCellCollisionProperties, 2, 0, 1);
    00117
    00124   virtual bool GetCollidable () const = 0;
    00125
    00131   virtual void SetCollidable (bool value) = 0;
    00132
    00139   virtual void SetParameter(const char* param, const char* value) = 0;
    00140
    00144   virtual csPtr<iTerrainCellCollisionProperties> Clone () = 0;
    00145
    00147   virtual size_t GetParameterCount() = 0;
    00148
    00150   virtual const char* GetParameterName (size_t index) = 0;
    00151
    00153
    00154   virtual const char* GetParameterValue (size_t index) = 0;
    00155   virtual const char* GetParameterValue (const char* name) = 0;
    00157 };
    00158
    00165 struct iTerrainCellRenderProperties : public virtual iShaderVariableContext
    00166 {
    00167   SCF_INTERFACE (iTerrainCellRenderProperties, 2, 0, 1);
    00168
    00174   virtual bool GetVisible () const = 0;
    00175
    00181   virtual void SetVisible (bool value) = 0;
    00182
    00189   virtual void SetParameter (const char* param, const char* value) = 0;
    00190
    00194   virtual csPtr<iTerrainCellRenderProperties> Clone () = 0;
    00195
    00197   virtual size_t GetParameterCount() = 0;
    00198
    00200   virtual const char* GetParameterName (size_t index) = 0;
    00201
    00203
    00204   virtual const char* GetParameterValue (size_t index) = 0;
    00205   virtual const char* GetParameterValue (const char* name) = 0;
    00207 };
    00208
    00212 struct iTerrainCellFeederProperties : public virtual iBase
    00213 {
    00214   SCF_INTERFACE (iTerrainCellFeederProperties, 3, 2, 0);
    00215
    00219   virtual void SetHeightmapSource (const char* source, const char* format) = 0;
    00220
    00224   virtual void SetNormalMapSource (const char* source) = 0;
    00225
    00229   virtual void SetMaterialMapSource (const char* source) = 0;
    00230
    00234   virtual void SetHeightOffset (float offset) = 0;
    00235
    00239   virtual void AddAlphaMap (const char* material, const char* alphaMapSource) = 0;
    00240
    00247   virtual void SetParameter (const char* param, const char* value) = 0;
    00248
    00252   virtual csPtr<iTerrainCellFeederProperties> Clone () = 0;
    00253
    00255   virtual size_t GetParameterCount() = 0;
    00256
    00258   virtual const char* GetParameterName (size_t index) = 0;
    00259
    00261
    00262   virtual const char* GetParameterValue (size_t index) = 0;
    00263   virtual const char* GetParameterValue (const char* name) = 0;
    00265
    00266
    00268   virtual size_t GetAlphaMapCount() = 0;
    00269
    00271   virtual const char* GetAlphaMapMaterial (size_t index) = 0;
    00272
    00274
    00275   virtual const char* GetAlphaMapSource (size_t index) = 0;
    00276   virtual const char* GetAlphaMapSource (const char* material) = 0;
    00278
    00280   virtual void SetHeightmapSmooth (bool doSmooth) = 0;
    00281   virtual bool GetHeightmapSmooth () const = 0;
    00283 };
    00284
    00288 struct iTerrainDataFeeder : public virtual iBase
    00289 {
    00290   SCF_INTERFACE (iTerrainDataFeeder, 2, 0, 0);
    00291
    00299   virtual csPtr<iTerrainCellFeederProperties> CreateProperties () = 0;
    00300
    00310   virtual bool PreLoad (iTerrainCell* cell) = 0;
    00311
    00320   virtual bool Load (iTerrainCell* cell) = 0;
    00321
    00328   virtual void SetParameter (const char* param, const char* value) = 0;
    00329 };
    00330
    00336 struct csTerrainColliderCollideSegmentResult
    00337 {
    00339   bool hit;
    00340
    00342   csVector3 isect;
    00343
    00345
    00346   csVector3 a, b, c;
    00348
    00349   csTerrainColliderCollideSegmentResult()
    00350    : hit (false), isect (0), a (0), b (0), c (0) {}
    00351 };
    00352
    00354 struct iTerrainCollider : public virtual iBase
    00355 {
    00356   SCF_INTERFACE (iTerrainCollider, 3, 0, 0);
    00357
    00365   virtual csPtr<iTerrainCellCollisionProperties> CreateProperties () = 0;
    00366
    00380   virtual bool CollideSegment (iTerrainCell* cell, const csVector3& start,
    00381                                const csVector3& end, bool oneHit,
    00382                                iTerrainVector3Array* points) = 0;
    00383
    00395   virtual bool CollideSegment (iTerrainCell* cell, const csVector3& start,
    00396                                const csVector3& end,
    00397                                csVector3& hitPoint) = 0;
    00398
    00409   virtual csTerrainColliderCollideSegmentResult CollideSegment (
    00410       iTerrainCell* cell, const csVector3& start, const csVector3& end) = 0;
    00411
    00429   virtual bool CollideTriangles (iTerrainCell* cell, const csVector3* vertices,
    00430                                  size_t tri_count,
    00431                                  const unsigned int* indices, float radius,
    00432                                  const csReversibleTransform& trans,
    00433                                  bool oneHit, iTerrainCollisionPairArray* pairs) = 0;
    00434
    00450   virtual bool Collide (iTerrainCell* cell, iCollider* collider,
    00451                        float radius, const csReversibleTransform& trans,
    00452                        bool oneHit, iTerrainCollisionPairArray* pairs) = 0;
    00453 };
    00454
    00455
    00457 struct iTerrainRenderer : public virtual iBase
    00458 {
    00459   SCF_INTERFACE (iTerrainRenderer, 3, 0, 0);
    00460
    00468   virtual csPtr<iTerrainCellRenderProperties> CreateProperties () = 0;
    00469
    00474   virtual void ConnectTerrain (iTerrainSystem* system) = 0;
    00475
    00479   virtual void DisconnectTerrain (iTerrainSystem* system) = 0;
    00480
    00481
    00495   virtual CS::Graphics::RenderMesh** GetRenderMeshes (int& n, iRenderView* rview,
    00496                                    iMovable* movable, uint32 frustum_mask,
    00497                                    const csArray<iTerrainCell*>& cells) = 0;
    00498
    00499
    00506   virtual void OnMaterialPaletteUpdate (const csTerrainMaterialPalette&
    00507                                         material_palette) = 0;
    00508
    00521   virtual void OnMaterialMaskUpdate (iTerrainCell* cell,
    00522     const csRect& rectangle, const unsigned char* materialMap, size_t pitch) = 0;
    00523
    00537   virtual void OnMaterialMaskUpdate (iTerrainCell* cell, size_t materialIdx,
    00538     const csRect& rectangle, const unsigned char* materialMap, size_t pitch) = 0;
    00539
    00548   virtual void OnAlphaMapUpdate (iTerrainCell* cell,
    00549     iMaterialWrapper* material, iImage* alphaMap) = 0;
    00550 };
    00551
    00553 struct iTerrainCellHeightDataCallback : public virtual iBase
    00554 {
    00555   SCF_INTERFACE (iTerrainCellHeightDataCallback, 1, 0, 0);
    00556
    00563   virtual void OnHeightUpdate (iTerrainCell* cell, const csRect& rectangle) = 0;
    00564 };
    00565
    00567 struct iTerrainCellLoadCallback : public virtual iBase
    00568 {
    00569   SCF_INTERFACE (iTerrainCellLoadCallback, 1, 0, 0);
    00570
    00576   virtual void OnCellLoad (iTerrainCell* cell) = 0;
    00577
    00583   virtual void OnCellPreLoad (iTerrainCell* cell) = 0;
    00584
    00590   virtual void OnCellUnload (iTerrainCell* cell) = 0;
    00591 };
    00592
    00593 struct iTerrainFactoryCell;
    00594
    00601 struct iTerrainSystem : public virtual iBase
    00602 {
    00603   SCF_INTERFACE (iTerrainSystem, 3, 0, 0);
    00604
    00613   virtual iTerrainCell* GetCell (const char* name, bool loadData = false) = 0;
    00614
    00626   virtual iTerrainCell* GetCell (const csVector2& pos, bool loadData = false) = 0;
    00627
    00634   virtual iTerrainCell* GetCell (size_t index, bool loadData = false) = 0;
    00635
    00639   virtual size_t GetCellCount () const = 0;
    00640
    00646   virtual const csTerrainMaterialPalette& GetMaterialPalette () const = 0;
    00647
    00653   virtual void SetMaterialPalette (const csTerrainMaterialPalette& array) = 0;
    00654
    00672   virtual bool CollideSegment (const csVector3& start, const csVector3& end,
    00673                            bool oneHit, iTerrainVector3Array* points,
    00674                            iMaterialArray* materials) = 0;
    00675
    00693   virtual bool CollideSegment (const csVector3& start, const csVector3& end,
    00694                                csVector3& hitPoint,
    00695                                iMaterialWrapper** hitMaterial) = 0;
    00696
    00713   virtual csTerrainColliderCollideSegmentResult CollideSegment (
    00714       const csVector3& start, const csVector3& end,
    00715       bool use_ray = false) = 0;
    00716
    00739   virtual bool CollideTriangles (const csVector3* vertices,
    00740                        size_t tri_count,
    00741                        const unsigned int* indices, float radius,
    00742                        const csReversibleTransform& trans,
    00743                        bool oneHit, iTerrainCollisionPairArray* pairs) = 0;
    00744
    00765   virtual bool Collide (iCollider* collider, float radius,
    00766                        const csReversibleTransform& trans, bool oneHit,
    00767                        iTerrainCollisionPairArray* pairs) = 0;
    00768
    00775   virtual float GetVirtualViewDistance () const = 0;
    00776
    00783   virtual void SetVirtualViewDistance (float distance) = 0;
    00784
    00792   virtual bool GetAutoPreLoad () const = 0;
    00793
    00799   virtual void SetAutoPreLoad (bool mode) = 0;
    00800
    00813   virtual void PreLoadCells (iRenderView* rview, iMovable* movable) = 0;
    00814
    00826   virtual float GetHeight (const csVector2& pos) = 0;
    00827
    00838   virtual csVector3 GetTangent (const csVector2& pos) = 0;
    00839
    00850   virtual csVector3 GetBinormal (const csVector2& pos) = 0;
    00851
    00862   virtual csVector3 GetNormal (const csVector2& pos) = 0;
    00863
    00869   virtual size_t GetMaxLoadedCells () const = 0;
    00870
    00878   virtual void SetMaxLoadedCells (size_t value) = 0;
    00879
    00883   virtual void UnloadOldCells () = 0;
    00884
    00888   virtual void AddCellLoadListener (iTerrainCellLoadCallback* cb) = 0;
    00889
    00893   virtual void RemoveCellLoadListener (iTerrainCellLoadCallback* cb) = 0;
    00894
    00898   virtual void AddCellHeightUpdateListener (iTerrainCellHeightDataCallback* cb) = 0;
    00899
    00903   virtual void RemoveCellHeightUpdateListener (iTerrainCellHeightDataCallback* cb) = 0;
    00904
    00912   virtual iTerrainCell* AddCell (iTerrainFactoryCell*) = 0;
    00913
    00917   virtual void RemoveCell (iTerrainCell*) = 0;
    00918 };
    00919
    00928 struct iTerrainCell : public virtual iBase
    00929 {
    00930   SCF_INTERFACE (iTerrainCell, 6, 0, 0);
    00931
    00933   enum LoadState
    00934   {
    00935     NotLoaded,
    00937     PreLoaded,
    00939     Loaded
    00940   };
    00941
    00947   virtual LoadState GetLoadState () const = 0;
    00948
    00964   virtual void SetLoadState (LoadState state) = 0;
    00965
    00971   virtual iTerrainSystem* GetTerrain () = 0;
    00972
    00980   virtual const char* GetName () const = 0;
    00981
    00988   virtual iTerrainCellRenderProperties* GetRenderProperties () const = 0;
    00989
    00996   virtual iTerrainCellCollisionProperties* GetCollisionProperties () const = 0;
    00997
    01004   virtual iTerrainCellFeederProperties* GetFeederProperties () const = 0;
    01005
    01012   virtual int GetGridWidth () const = 0;
    01013
    01020   virtual int GetGridHeight () const = 0;
    01021
    01028   virtual csLockedHeightData GetHeightData () = 0;
    01029
    01043   virtual csLockedHeightData LockHeightData (const csRect& rectangle) = 0;
    01044
    01050   virtual void UnlockHeightData () = 0;
    01051
    01058   virtual csLockedNormalData GetNormalData () = 0;
    01059
    01072   virtual csLockedNormalData LockNormalData (const csRect& rectangle) = 0;
    01073
    01079   virtual void UnlockNormalData () = 0;
    01080
    01084   virtual void RecalculateNormalData () = 0;
    01085
    01092   virtual const csVector2& GetPosition () const = 0;
    01093
    01102   virtual const csVector3& GetSize () const = 0;
    01103
    01110   virtual int GetMaterialMapWidth () const = 0;
    01111
    01118   virtual int GetMaterialMapHeight () const = 0;
    01119
    01125   virtual bool GetMaterialPersistent() const = 0;
    01126
    01145   virtual csLockedMaterialMap LockMaterialMap (const csRect& rectangle) = 0;
    01146
    01155   virtual void UnlockMaterialMap() = 0;
    01156
    01166   virtual void SetMaterialMask (unsigned int material, iImage* image) = 0;
    01167
    01179   virtual void SetMaterialMask (unsigned int material, const unsigned char*
    01180                           data, unsigned int width, unsigned int height) = 0;
    01181
    01188   virtual void SetAlphaMask (iMaterialWrapper* material, iImage* alphaMap) = 0;
    01189
    01195   virtual void SetBaseMaterial (iMaterialWrapper* material) = 0;
    01196
    01200   virtual iMaterialWrapper* GetBaseMaterial () const = 0;
    01201
    01207   virtual void SetAlphaSplatMaterial (iMaterialWrapper* material) = 0;
    01208
    01214   virtual iMaterialWrapper* GetAlphaSplatMaterial () const = 0;
    01215
    01228   virtual bool CollideSegment (const csVector3& start, const csVector3& end,
    01229                            bool oneHit, iTerrainVector3Array* points) = 0;
    01230
    01242   virtual bool CollideSegment (const csVector3& start, const csVector3& end,
    01243                                csVector3& hitPoint) = 0;
    01244
    01261   virtual bool CollideTriangles (const csVector3* vertices,
    01262                        size_t tri_count,
    01263                        const unsigned int* indices, float radius,
    01264                        const csReversibleTransform& trans,
    01265                        bool oneHit, iTerrainCollisionPairArray* pairs) = 0;
    01266
    01281   virtual bool Collide (iCollider* collider, float radius,
    01282                        const csReversibleTransform& trans, bool oneHit,
    01283                        iTerrainCollisionPairArray* pairs) = 0;
    01284
    01294   virtual float GetHeight (int x, int y) const = 0;
    01295
    01304   virtual float GetHeight (const csVector2& pos) const = 0;
    01305
    01314   virtual csVector3 GetTangent (int x, int y) const = 0;
    01315
    01323   virtual csVector3 GetTangent (const csVector2& pos) const = 0;
    01324
    01333   virtual csVector3 GetBinormal (int x, int y) const = 0;
    01334
    01342   virtual csVector3 GetBinormal (const csVector2& pos) const = 0;
    01343
    01352   virtual csVector3 GetNormal (int x, int y) const = 0;
    01353
    01361   virtual csVector3 GetNormal (const csVector2& pos) const = 0;
    01362
    01364   virtual csRefCount* GetRenderData () const = 0;
    01365
    01367   virtual void SetRenderData (csRefCount* data) = 0;
    01368
    01370   virtual csRefCount* GetCollisionData () const = 0;
    01371
    01373   virtual void SetCollisionData (csRefCount* data) = 0;
    01374
    01376   virtual csRefCount* GetFeederData () const = 0;
    01377
    01379   virtual void SetFeederData (csRefCount* data) = 0;
    01380
    01388   virtual void SetName (const char* name) = 0;
    01389
    01396   virtual void SetSplatBaseMaterial (iMaterialWrapper* material) = 0;
    01397
    01399   virtual iMaterialWrapper* GetSplatBaseMaterial () const = 0;
    01400
    01405   virtual csLockedNormalData GetTangentData () = 0;
    01406
    01411   virtual csLockedNormalData GetBitangentData () = 0;
    01412 };
    01413
    01415 struct iTerrainFactoryCell : public virtual iBase
    01416 {
    01417   SCF_INTERFACE (iTerrainFactoryCell, 2, 0, 1);
    01418
    01425   virtual iTerrainCellRenderProperties* GetRenderProperties () const = 0;
    01426
    01433   virtual iTerrainCellCollisionProperties* GetCollisionProperties () const = 0;
    01434
    01441   virtual iTerrainCellFeederProperties* GetFeederProperties () const = 0;
    01442
    01448   virtual void SetBaseMaterial (iMaterialWrapper* material) = 0;
    01449
    01455   virtual void SetAlphaSplatMaterial (iMaterialWrapper* material) = 0;
    01456
    01458   virtual const char* GetName() = 0;
    01459
    01461   virtual void SetName (const char* name) = 0;
    01462
    01469   virtual int GetGridWidth () const = 0;
    01470
    01477   virtual int GetGridHeight () const = 0;
    01478
    01485   virtual const csVector2& GetPosition () const = 0;
    01486
    01495   virtual const csVector3& GetSize () const = 0;
    01496
    01503   virtual int GetMaterialMapWidth () const = 0;
    01504
    01511   virtual int GetMaterialMapHeight () const = 0;
    01512
    01516   virtual iMaterialWrapper* GetBaseMaterial () const = 0;
    01517
    01523   virtual iMaterialWrapper* GetAlphaSplatMaterial () const = 0;
    01524
    01530   virtual bool GetMaterialPersistent() const = 0;
    01531
    01536   virtual void SetGridWidth (int w) = 0;
    01537
    01542   virtual void SetGridHeight (int h) = 0;
    01543
    01548   virtual void SetPosition (const csVector2& pos) = 0;
    01549
    01556   virtual void SetSize (const csVector3& size) = 0;
    01557
    01562   virtual void SetMaterialMapWidth (int w) = 0;
    01563
    01568   virtual void SetMaterialMapHeight (int h) = 0;
    01569
    01574   virtual void SetMaterialPersistent (bool flag) = 0;
    01575
    01582   virtual void SetSplatBaseMaterial (iMaterialWrapper* material) = 0;
    01583
    01585   virtual iMaterialWrapper* GetSplatBaseMaterial () const = 0;
    01586 };
    01587
    01589 struct iTerrainFactory : public virtual iBase
    01590 {
    01591   SCF_INTERFACE (iTerrainFactory, 2, 0, 3);
    01592
    01598   virtual void SetRenderer (iTerrainRenderer* renderer) = 0;
    01599
    01605   virtual void SetCollider (iTerrainCollider* collider) = 0;
    01606
    01612   virtual void SetFeeder (iTerrainDataFeeder* feeder) = 0;
    01613
    01634   virtual iTerrainFactoryCell* AddCell (const char* name,
    01635     int gridWidth, int gridHeight, int materialMapWidth,
    01636     int materialMapHeight, bool materiaMapPersistent,
    01637     const csVector2& position, const csVector3& size) = 0;
    01638
    01644   virtual void SetMaxLoadedCells (size_t number) = 0;
    01645
    01652   virtual void SetVirtualViewDistance (float distance) = 0;
    01653
    01659   virtual void SetAutoPreLoad (bool mode) = 0;
    01660
    01661
    01665   virtual iTerrainRenderer* GetRenderer () = 0;
    01666
    01670   virtual iTerrainCollider* GetCollider () = 0;
    01671
    01675   virtual iTerrainDataFeeder* GetFeeder () = 0;
    01676
    01681   virtual size_t GetMaxLoadedCells () = 0;
    01682
    01684   virtual size_t GetCellCount () = 0;
    01685
    01687   virtual iTerrainFactoryCell* GetCell (size_t index) = 0;
    01688
    01690   virtual iTerrainFactoryCell* GetDefaultCell () = 0;
    01691
    01699   virtual iTerrainFactoryCell* AddCell () = 0;
    01700
    01702   virtual iTerrainFactoryCell* GetCell (const char* name) = 0;
    01703
    01705   virtual void RemoveCell (iTerrainFactoryCell*) = 0;
    01706 };
    01707
    01708
    01709 #endif