CTerrain implementation

Added rewritten CTerrain implementation
Compiles OK, but functions are missing from other classes
Also needs testing
dev-ui
Piotr Dziwinski 2012-08-08 21:32:44 +02:00
parent f7e78b21e9
commit 878eec8eea
7 changed files with 1985 additions and 101 deletions

View File

@ -56,10 +56,10 @@ public:
void Draw(); void Draw();
bool SetLevel(float level); bool SetLevel(float level);
float RetLevel(); float GetLevel();
void SetEnable(bool bEnable); void SetEnable(bool bEnable);
bool RetEnable(); bool GetEnable();
protected: protected:
bool EventFrame(const Event &event); bool EventFrame(const Event &event);

View File

@ -674,6 +674,11 @@ Math::IntSize Gfx::CEngine::InterfaceToWindowSize(Math::Size size)
static_cast<int>(size.h * m_size.h)); static_cast<int>(size.h * m_size.h));
} }
std::string Gfx::CEngine::GetTextureDir()
{
return m_texPath;
}
void Gfx::CEngine::DrawMouse() void Gfx::CEngine::DrawMouse()
{ {
if (! m_mouseVisible) if (! m_mouseVisible)

View File

@ -552,6 +552,7 @@ public:
//! Converts interface size to window size //! Converts interface size to window size
Math::IntSize InterfaceToWindowSize(Math::Size size); Math::IntSize InterfaceToWindowSize(Math::Size size);
std::string GetTextureDir();
bool WriteProfile(); bool WriteProfile();
@ -606,7 +607,7 @@ public:
bool AddSurface(int objRank, Gfx::VertexTex2* vertex, int nb, const Gfx::Material &mat, bool AddSurface(int objRank, Gfx::VertexTex2* vertex, int nb, const Gfx::Material &mat,
int state, std::string texName1, std::string texName2, int state, std::string texName1, std::string texName2,
float min, float max, bool globalUpdate); float min, float max, bool globalUpdate);
bool AddQuick(int objRank, Gfx::EngineObjLevel5* buffer, bool AddQuick(int objRank, const Gfx::EngineObjLevel5& buffer,
std::string texName1, std::string texName2, std::string texName1, std::string texName2,
float min, float max, bool globalUpdate); float min, float max, bool globalUpdate);
Gfx::EngineObjLevel5* SearchTriangle(int objRank, const Gfx::Material &mat, Gfx::EngineObjLevel5* SearchTriangle(int objRank, const Gfx::Material &mat,

View File

@ -260,7 +260,7 @@ public:
CParticle(CInstanceManager* iMan, CEngine* engine); CParticle(CInstanceManager* iMan, CEngine* engine);
~CParticle(); ~CParticle();
void SetGLDevice(CDevice device); void SetDevice(CDevice* device);
void FlushParticle(); void FlushParticle();
void FlushParticle(int sheet); void FlushParticle(int sheet);
@ -283,7 +283,7 @@ public:
void SetPhase(int channel, ParticlePhase phase, float duration); void SetPhase(int channel, ParticlePhase phase, float duration);
bool GetPosition(int channel, Math::Vector &pos); bool GetPosition(int channel, Math::Vector &pos);
Gfx::Color RetFogColor(Math::Vector pos); Gfx::Color GetFogColor(Math::Vector pos);
void SetFrameUpdate(int sheet, bool bUpdate); void SetFrameUpdate(int sheet, bool bUpdate);
void FrameParticle(float rTime); void FrameParticle(float rTime);
@ -311,7 +311,7 @@ protected:
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
CEngine* m_engine; CEngine* m_engine;
CDevice* m_pDevice; CDevice* m_device;
CRobotMain* m_main; CRobotMain* m_main;
CTerrain* m_terrain; CTerrain* m_terrain;
CWater* m_water; CWater* m_water;

File diff suppressed because it is too large Load Diff

View File

@ -40,15 +40,12 @@ enum TerrainRes
TR_STONE = 1, TR_STONE = 1,
TR_URANIUM = 2, TR_URANIUM = 2,
TR_POWER = 3, TR_POWER = 3,
TR_KEYa = 4, TR_KEY_A = 4,
TR_KEYb = 5, TR_KEY_B = 5,
TR_KEYc = 6, TR_KEY_C = 6,
TR_KEYd = 7, TR_KEY_D = 7,
}; };
const short MAXBUILDINGLEVEL = 100;
struct BuildingLevel struct BuildingLevel
{ {
Math::Vector center; Math::Vector center;
@ -61,35 +58,54 @@ struct BuildingLevel
float bboxMaxX; float bboxMaxX;
float bboxMinZ; float bboxMinZ;
float bboxMaxZ; float bboxMaxZ;
BuildingLevel()
{
factor = min = max = level = height = 0.0f;
bboxMinX = bboxMaxX = bboxMinZ = bboxMaxZ = 0.0f;
}
}; };
const short MAXMATTERRAIN = 100;
struct TerrainMaterial struct TerrainMaterial
{ {
short id; short id;
char texName[20]; std::string texName;
float u,v; float u,v;
float hardness; float hardness;
char mat[4]; // up, right, down, left char mat[4]; // up, right, down, left
TerrainMaterial()
{
id = 0;
u = v = 0.0f;
hardness = 0.0f;
mat[0] = mat[1] = mat[2] = mat[3] = 0;
}
}; };
struct DotLevel struct DotLevel
{ {
short id; short id;
char mat[4]; // up, right, down, left char mat[4]; // up, right, down, left
DotLevel()
{
id = 0;
mat[0] = mat[1] = mat[2] = mat[3] = 0;
}
}; };
const short MAXFLYINGLIMIT = 10;
struct FlyingLimit struct FlyingLimit
{ {
Math::Vector center; Math::Vector center;
float extRadius; float extRadius;
float intRadius; float intRadius;
float maxHeight; float maxHeight;
FlyingLimit()
{
extRadius = intRadius = maxHeight = 0.0f;
}
}; };
@ -100,72 +116,124 @@ public:
CTerrain(CInstanceManager* iMan); CTerrain(CInstanceManager* iMan);
~CTerrain(); ~CTerrain();
bool Generate(int mosaic, int brickP2, float size, float vision, int depth, float hardness); //! Generates a new flat terrain
bool InitTextures(char* baseName, int* table, int dx, int dy); bool Generate(int mosaic, int brickPow2, float size, float vision, int depth, float hardness);
//! Initializes the names of textures to use for the land
bool InitTextures(const std::string& baseName, int* table, int dx, int dy);
//! Empties level
void LevelFlush(); void LevelFlush();
bool LevelMaterial(int id, char* baseName, float u, float v, int up, int right, int down, int left, float hardness); //! Initializes the names of textures to use for the land
void LevelMaterial(int id, std::string& baseName, float u, float v, int up, int right, int down, int left, float hardness);
//! Initializes all the ground with a material
bool LevelInit(int id); bool LevelInit(int id);
//! Generates a level in the terrain
bool LevelGenerate(int *id, float min, float max, float slope, float freq, Math::Vector center, float radius); bool LevelGenerate(int *id, float min, float max, float slope, float freq, Math::Vector center, float radius);
//! Initializes a completely flat terrain
void FlushRelief(); void FlushRelief();
bool ReliefFromBMP(const char* filename, float scaleRelief, bool adjustBorder); //! Load relief from a PNG file
bool ReliefFromDXF(const char* filename, float scaleRelief); bool ReliefFromPNG(const std::string& filename, float scaleRelief, bool adjustBorder);
bool ResFromBMP(const char* filename); //! Load resources from a PNG file
bool CreateObjects(bool bMultiRes); bool ResFromPNG(const std::string& filename);
//! Creates all objects of the terrain within the 3D engine
bool CreateObjects(bool multiRes);
//! Modifies the terrain's relief
bool Terraform(const Math::Vector& p1, const Math::Vector& p2, float height); bool Terraform(const Math::Vector& p1, const Math::Vector& p2, float height);
//@{
//! Management of the wind
void SetWind(Math::Vector speed); void SetWind(Math::Vector speed);
Math::Vector RetWind(); Math::Vector GetWind();
//@}
float RetFineSlope(const Math::Vector &pos); //! Gives the exact slope of the terrain of a place given
float RetCoarseSlope(const Math::Vector &pos); float GetFineSlope(const Math::Vector& pos);
//! Gives the approximate slope of the terrain of a specific location
float GetCoarseSlope(const Math::Vector& pos);
//! Gives the normal vector at the position p (x,-,z) of the ground
bool GetNormal(Math::Vector& n, const Math::Vector &p); bool GetNormal(Math::Vector& n, const Math::Vector &p);
float RetFloorLevel(const Math::Vector &p, bool bBrut=false, bool bWater=false); //! returns the height of the ground
float RetFloorHeight(const Math::Vector &p, bool bBrut=false, bool bWater=false); float GetFloorLevel(const Math::Vector& p, bool brut=false, bool water=false);
bool MoveOnFloor(Math::Vector &p, bool bBrut=false, bool bWater=false); //! Returns the height to the ground
float GetFloorHeight(const Math::Vector& p, bool brut=false, bool water=false);
//! Modifies the coordinate "y" of point "p" to rest on the ground floor
bool MoveOnFloor(Math::Vector& p, bool brut=false, bool water=false);
//! Modifies a coordinate so that it is on the ground
bool ValidPosition(Math::Vector& p, float marging); bool ValidPosition(Math::Vector& p, float marging);
TerrainRes RetResource(const Math::Vector &p); //! Returns the resource type available underground
Gfx::TerrainRes GetResource(const Math::Vector& p);
//! Adjusts a position so that it does not exceed the boundaries
void LimitPos(Math::Vector &pos); void LimitPos(Math::Vector &pos);
//! Empty the table of elevations
void FlushBuildingLevel(); void FlushBuildingLevel();
//! Adds a new elevation for a building
bool AddBuildingLevel(Math::Vector center, float min, float max, float height, float factor); bool AddBuildingLevel(Math::Vector center, float min, float max, float height, float factor);
//! Updates the elevation for a building when it was moved up (after a terraforming)
bool UpdateBuildingLevel(Math::Vector center); bool UpdateBuildingLevel(Math::Vector center);
//! Removes the elevation for a building when it was destroyed
bool DeleteBuildingLevel(Math::Vector center); bool DeleteBuildingLevel(Math::Vector center);
float RetBuildingFactor(const Math::Vector &p); //! Returns the influence factor whether a position is on a possible rise
float RetHardness(const Math::Vector &p); float GetBuildingFactor(const Math::Vector& p);
float GetHardness(const Math::Vector& p);
int RetMosaic(); int GetMosaic();
int RetBrick(); int GetBrick();
float RetSize(); float GetSize();
float RetScaleRelief(); float GetScaleRelief();
//! Shows the flat areas on the ground
void GroundFlat(Math::Vector pos); void GroundFlat(Math::Vector pos);
float RetFlatZoneRadius(Math::Vector center, float max); //! Calculates the radius of the largest flat area available
float GetFlatZoneRadius(Math::Vector center, float max);
//@{
//! Management of the global max flying height
void SetFlyingMaxHeight(float height); void SetFlyingMaxHeight(float height);
float RetFlyingMaxHeight(); float GetFlyingMaxHeight();
//@}
//! Empty the table of flying limits
void FlushFlyingLimit(); void FlushFlyingLimit();
bool AddFlyingLimit(Math::Vector center, float extRadius, float intRadius, float maxHeight); //! Adds a new flying limit
float RetFlyingLimit(Math::Vector pos, bool bNoLimit); void AddFlyingLimit(Math::Vector center, float extRadius, float intRadius, float maxHeight);
//! Returns the maximum height of flight
float GetFlyingLimit(Math::Vector pos, bool noLimit);
protected: protected:
//! Adds a point of elevation in the buffer of relief
bool ReliefAddDot(Math::Vector pos, float scaleRelief); bool ReliefAddDot(Math::Vector pos, float scaleRelief);
//! Adjust the edges of each mosaic to be compatible with all lower resolutions
void AdjustRelief(); void AdjustRelief();
Math::Vector RetVector(int x, int y); //! Calculates a vector of the terrain
Gfx::VertexTex2 RetVertex(int x, int y, int step); Math::Vector GetVector(int x, int y);
//! Calculates a vertex of the terrain
Gfx::VertexTex2 GetVertex(int x, int y, int step);
//! Creates all objects of a mosaic
bool CreateMosaic(int ox, int oy, int step, int objRank, const Gfx::Material& mat, float min, float max); bool CreateMosaic(int ox, int oy, int step, int objRank, const Gfx::Material& mat, float min, float max);
bool CreateSquare(bool bMultiRes, int x, int y); //! Creates all objects in a mesh square ground
bool CreateSquare(bool multiRes, int x, int y);
TerrainMaterial* LevelSearchMat(int id); //! Seeks a materials based on theirs identifier
void LevelTextureName(int x, int y, char *name, Math::Point &uv); Gfx::TerrainMaterial* LevelSearchMat(int id);
float LevelRetHeight(int x, int y); //! Chooses texture to use for a given square
void LevelTextureName(int x, int y, std::string& name, Math::Point &uv);
//! Returns the height of the terrain
float LevelGetHeight(int x, int y);
//! Decide whether a point is using the materials
bool LevelGetDot(int x, int y, float min, float max, float slope); bool LevelGetDot(int x, int y, float min, float max, float slope);
//! Seeks if material exists
int LevelTestMat(char *mat); int LevelTestMat(char *mat);
//! Modifies the state of a point and its four neighbors, without testing if possible
void LevelSetDot(int x, int y, int id, char *mat); void LevelSetDot(int x, int y, int id, char *mat);
//! Tests if a material can give a place, according to its four neighbors. If yes, puts the point.
bool LevelIfDot(int x, int y, int id, char *mat); bool LevelIfDot(int x, int y, int id, char *mat);
//! Modifies the state of a point
bool LevelPutDot(int x, int y, int id); bool LevelPutDot(int x, int y, int id);
//! Initializes a table with empty levels
void LevelOpenTable(); void LevelOpenTable();
//! Closes the level table
void LevelCloseTable(); void LevelCloseTable();
//! Adjusts a position according to a possible rise
void AdjustBuildingLevel(Math::Vector &p); void AdjustBuildingLevel(Math::Vector &p);
protected: protected:
@ -173,39 +241,49 @@ protected:
CEngine* m_engine; CEngine* m_engine;
CWater* m_water; CWater* m_water;
int m_mosaic; // number of mosaics //! Number of mosaics
int m_brick; // number of bricks per mosaics int m_mosaic;
float m_size; // size of an item in an brick //! Number of bricks per mosaics
float m_vision; // vision before a change of resolution int m_brick;
float* m_relief; // table of the relief int m_levelDotSize;
int* m_texture; // table of textures //! Size of an item in a brick
int* m_objRank; // table of rows of objects float m_size;
bool m_bMultiText; //! Vision before a change of resolution
bool m_bLevelText; float m_vision;
float m_scaleMapping; // scale of the mapping //! Table of the relief
std::vector<float> m_relief;
//! Table of textures
std::vector<int> m_texture;
//! Table of rows of objects
std::vector<int> m_objRank;
//! Table of resources
std::vector<unsigned char> m_resources;
bool m_multiText;
bool m_levelText;
//! Scale of the mapping
float m_scaleMapping;
float m_scaleRelief; float m_scaleRelief;
int m_subdivMapping; int m_subdivMapping;
int m_depth; // number of different resolutions (1,2,3,4) //! Number of different resolutions (1,2,3,4)
char m_texBaseName[20]; int m_depth;
char m_texBaseExt[10]; std::string m_texBaseName;
std::string m_texBaseExt;
float m_defHardness; float m_defHardness;
TerrainMaterial m_levelMat[MAXMATTERRAIN+1]; std::vector<TerrainMaterial> m_levelMat;
int m_levelMatTotal; std::vector<Gfx::DotLevel> m_levelDot;
int m_levelMatMax; int m_levelMatMax;
int m_levelDotSize;
DotLevel* m_levelDot;
int m_levelID; int m_levelID;
int m_buildingUsed; std::vector<Gfx::BuildingLevel> m_buildingLevels;
BuildingLevel m_buildingTable[MAXBUILDINGLEVEL];
unsigned char* m_resources; //! Wind speed
Math::Vector m_wind; // wind speed Math::Vector m_wind;
//! Global flying height limit
float m_flyingMaxHeight; float m_flyingMaxHeight;
int m_flyingLimitTotal; //! List of local flight limits
FlyingLimit m_flyingLimit[MAXFLYINGLIMIT]; std::vector<Gfx::FlyingLimit> m_flyingLimits;
}; };
}; // namespace Gfx }; // namespace Gfx

View File

@ -72,7 +72,7 @@ public:
CWater(CInstanceManager* iMan, Gfx::CEngine* engine); CWater(CInstanceManager* iMan, Gfx::CEngine* engine);
~CWater(); ~CWater();
void SetGLDevice(Gfx::CDevice device); void SetDevice(Gfx::CDevice* device);
bool EventProcess(const Event &event); bool EventProcess(const Event &event);
void Flush(); void Flush();
bool Create(WaterType type1, WaterType type2, const char *filename, Gfx::Color diffuse, Gfx::Color ambient, float level, float glint, Math::Vector eddy); bool Create(WaterType type1, WaterType type2, const char *filename, Gfx::Color diffuse, Gfx::Color ambient, float level, float glint, Math::Vector eddy);
@ -80,11 +80,11 @@ public:
void DrawSurf(); void DrawSurf();
bool SetLevel(float level); bool SetLevel(float level);
float RetLevel(); float GetLevel();
float RetLevel(CObject* object); float GetLevel(CObject* object);
void SetLava(bool bLava); void SetLava(bool bLava);
bool RetLava(); bool GetLava();
void AdjustEye(Math::Vector &eye); void AdjustEye(Math::Vector &eye);
@ -92,7 +92,7 @@ protected:
bool EventFrame(const Event &event); bool EventFrame(const Event &event);
void LavaFrame(float rTime); void LavaFrame(float rTime);
void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2); void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2);
bool RetWater(int x, int y); bool GetWater(int x, int y);
bool CreateLine(int x, int y, int len); bool CreateLine(int x, int y, int len);
void VaporFlush(); void VaporFlush();
@ -102,7 +102,7 @@ protected:
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
CEngine* m_engine; CEngine* m_engine;
CDevice* m_pDevice; CDevice* m_device;
CTerrain* m_terrain; CTerrain* m_terrain;
CParticle* m_particule; CParticle* m_particule;
CSound* m_sound; CSound* m_sound;