00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef LILITH_TERRAINMORPH_INCLUDED
00023 #define LILITH_TERRAINMORPH_INCLUDED
00024
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4786 ) // Debugger truncating names.
00027 #pragma warning( disable : 4530 ) // Exception handler isn't used
00028 #endif
00029
00030 #include "../grinliz/gltypes.h"
00031 #include "../grinliz/glrandom.h"
00032 #include "../grinliz/glpublisher.h"
00033 #include "../grinliz/glvector.h"
00034 #include "../grinliz/glrectangle.h"
00035 #include "../grinliz/glgeometry.h"
00036 #include "sequence.h"
00037
00038 namespace lilith3d
00039 {
00040
00041 class TerrainMesh;
00042 class TimeClock;
00043 class VolcanoMorph;
00044
00045 class StaticResource;
00046 class Texture;
00047 class DecalMesh;
00048
00057 class TerrainMorph : public ISequence
00058 {
00059 public:
00060 TerrainMorph();
00061 virtual ~TerrainMorph();
00062
00070 virtual bool DoSequence( TimeClock* timeClock ) = 0;
00071
00072 protected:
00073 void GenerateHeightMap( grinliz::LineLoop* loop,
00074 float blendDistance,
00075 float contribution,
00076 float* maxDelta );
00077 void DoTick( TimeClock* timeClock, float speed );
00078
00079
00080 grinliz::Rectangle2I mapBounds;
00081 float* targetMap;
00082
00083 grinliz::Random rand;
00084 };
00085
00086
00087 class VolcanoMorphListener : public grinliz::Listener< VolcanoMorphListener >
00088 {
00089 public:
00090 virtual void VolcanoGrow( VolcanoMorph* volcano, int x, int y, float newAltitude ) = 0;
00091 virtual void VolcanoDone( VolcanoMorph* volcano, int x, int y, float finalAltitude ) = 0;
00092 };
00093
00094
00096 class VolcanoMorph : public TerrainMorph
00097 {
00098 public:
00104 VolcanoMorph( int x, int y, float altitude );
00105 ~VolcanoMorph();
00106
00108 void AddTexture( const Texture* texture );
00109
00110 grinliz::Publisher< VolcanoMorphListener > publish;
00111
00112 virtual bool DoSequence( TimeClock* timeClock );
00113
00114 private:
00115 enum {
00116 FUZZ_SIZE = 37
00117 };
00118 float fuzzHeight[ FUZZ_SIZE ];
00119
00120 float altitude;
00121
00122 U32 lastParticleTime;
00123 int terrainX, terrainY;
00124 DecalMesh* decal;
00125 };
00126
00127 class PitMorph;
00128
00129 class PitMorphListener : public grinliz::Listener< PitMorphListener >
00130 {
00131 public:
00132 virtual void PitSink( PitMorph* pit, int x, int y, float newAltitude ) = 0;
00133 virtual void PitDone( PitMorph* pit, int x, int y, float finalAltitude ) = 0;
00134 };
00135
00136
00138 class PitMorph : public TerrainMorph
00139 {
00140 public:
00141 PitMorph( int x, int y, float altitude );
00142 ~PitMorph() {}
00143
00144 grinliz::Publisher< PitMorphListener > publish;
00145
00146 virtual bool DoSequence( TimeClock* timeClock );
00147
00148 private:
00149 float altitude;
00150 int terrainX, terrainY;
00151 };
00152
00153
00154 class BridgeMorph;
00155
00156 class BridgeMorphListener : public grinliz::Listener< BridgeMorphListener >
00157 {
00158 public:
00159 virtual void BridgeDone( BridgeMorph* bridge ) = 0;
00160 };
00161
00162
00164 class BridgeMorph : public TerrainMorph
00165 {
00166 public:
00167 BridgeMorph( float width, float originX, float originY, float destX, float destY );
00168 ~BridgeMorph() {}
00169
00170 grinliz::Publisher< BridgeMorphListener > publish;
00171
00172 virtual bool DoSequence( TimeClock* timeClock );
00173
00174 private:
00175
00176 float maxDelta;
00177 U32 startTime;
00178 };
00179
00180 class FlattenMorph;
00181
00182 class FlattenMorphListener : public grinliz::Listener< FlattenMorphListener >
00183 {
00184 public:
00185 virtual void FlattenDone( FlattenMorph* flatten ) = 0;
00186 };
00187
00188
00190 class FlattenMorph : public TerrainMorph
00191 {
00192 public:
00194 FlattenMorph( const grinliz::Rectangle2I& bounds, float height, float blendDistace=1.0f, float blendAmount=1.0f );
00195 virtual ~FlattenMorph() {};
00196
00197 grinliz::Publisher< FlattenMorphListener > publish;
00198
00199 virtual bool DoSequence( TimeClock* timeClock );
00200
00201 const grinliz::Rectangle2I& Bounds() const { return bounds; }
00202 float HeightTarget() const { return heightTarget; }
00203
00204 private:
00205 U32 startTime;
00206 U32 runTime;
00207 grinliz::Rectangle2I bounds;
00208 float heightTarget;
00209 float maxDelta;
00210 };
00211
00212 class BuildingMorph;
00213 class BuildingMesh;
00214
00215 class BuildingMorphListener : public grinliz::Listener< BuildingMorphListener >
00216 {
00217 public:
00218 virtual void BuildingMorphDone( BuildingMorph* flatten, BuildingMesh* placed ) = 0;
00219 };
00220
00221
00223 class BuildingMorph : public TerrainMorph
00224 {
00225 public:
00227 BuildingMorph( int x, int y, float height, const StaticResource* buildingResource );
00228 virtual ~BuildingMorph() {};
00229
00233 void SetTime( U32 timeInMSec );
00234
00235 grinliz::Publisher< BuildingMorphListener > publish;
00236
00237 virtual bool DoSequence( TimeClock* timeClock );
00238
00239 const grinliz::Rectangle2I& Bounds() { return bounds; }
00240
00241 private:
00242 U32 startTime;
00243 U32 runTime;
00244 float ratio;
00245
00246 grinliz::Rectangle2I bounds;
00247 grinliz::Vector2I pos;
00248 float maxDelta;
00249 bool canPlace;
00250 const StaticResource* resource;
00251 };
00252
00253
00254 class CycleMorph : public TerrainMorph
00255 {
00256 public:
00257 CycleMorph( float intensity, int iterations );
00258 virtual ~CycleMorph() {}
00259
00260 virtual bool DoSequence( TimeClock* tc );
00261
00262 private:
00263 int maxIteration;
00264 float intensity;
00265 int index;
00266 float bias;
00267 int iteration;
00268 };
00269
00270 };
00271
00272 #endif
00273