2012-06-22 14:31:55 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
|
|
|
|
// *
|
|
|
|
// * This program is free software: you can redistribute it and/or modify
|
|
|
|
// * it under the terms of the GNU General Public License as published by
|
|
|
|
// * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// * (at your option) any later version.
|
|
|
|
// *
|
|
|
|
// * This program is distributed in the hope that it will be useful,
|
|
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// * GNU General Public License for more details.
|
|
|
|
// *
|
|
|
|
// * You should have received a copy of the GNU General Public License
|
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
2012-08-11 16:39:16 +00:00
|
|
|
/**
|
|
|
|
* \file graphics/engine/terrain.h
|
|
|
|
* \brief Terrain rendering - Gfx::CTerrain class
|
|
|
|
*/
|
2012-06-22 14:31:55 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2012-07-26 20:26:19 +00:00
|
|
|
#include "graphics/engine/engine.h"
|
2012-06-25 14:37:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CInstanceManager;
|
|
|
|
|
2012-06-22 14:31:55 +00:00
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
2012-06-25 14:37:03 +00:00
|
|
|
class CEngine;
|
|
|
|
class CWater;
|
|
|
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
const short FLATLIMIT = (5.0f*Math::PI/180.0f);
|
2012-06-25 14:37:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum TerrainRes
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
TR_NULL = 0,
|
|
|
|
TR_STONE = 1,
|
|
|
|
TR_URANIUM = 2,
|
|
|
|
TR_POWER = 3,
|
2012-08-08 19:32:44 +00:00
|
|
|
TR_KEY_A = 4,
|
|
|
|
TR_KEY_B = 5,
|
|
|
|
TR_KEY_C = 6,
|
|
|
|
TR_KEY_D = 7,
|
2012-06-25 14:37:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BuildingLevel
|
|
|
|
{
|
2012-08-08 19:32:44 +00:00
|
|
|
Math::Vector center;
|
|
|
|
float factor;
|
|
|
|
float min;
|
|
|
|
float max;
|
|
|
|
float level;
|
|
|
|
float height;
|
|
|
|
float bboxMinX;
|
|
|
|
float bboxMaxX;
|
|
|
|
float bboxMinZ;
|
|
|
|
float bboxMaxZ;
|
|
|
|
|
|
|
|
BuildingLevel()
|
|
|
|
{
|
|
|
|
factor = min = max = level = height = 0.0f;
|
|
|
|
bboxMinX = bboxMaxX = bboxMinZ = bboxMaxZ = 0.0f;
|
|
|
|
}
|
2012-06-25 14:37:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TerrainMaterial
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
short id;
|
2012-08-08 19:32:44 +00:00
|
|
|
std::string texName;
|
2012-06-26 20:23:05 +00:00
|
|
|
float u,v;
|
|
|
|
float hardness;
|
|
|
|
char mat[4]; // up, right, down, left
|
2012-08-08 19:32:44 +00:00
|
|
|
|
|
|
|
TerrainMaterial()
|
|
|
|
{
|
|
|
|
id = 0;
|
|
|
|
u = v = 0.0f;
|
|
|
|
hardness = 0.0f;
|
|
|
|
mat[0] = mat[1] = mat[2] = mat[3] = 0;
|
|
|
|
}
|
2012-06-25 14:37:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DotLevel
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
short id;
|
|
|
|
char mat[4]; // up, right, down, left
|
2012-06-25 14:37:03 +00:00
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
DotLevel()
|
|
|
|
{
|
|
|
|
id = 0;
|
|
|
|
mat[0] = mat[1] = mat[2] = mat[3] = 0;
|
|
|
|
}
|
|
|
|
};
|
2012-06-25 14:37:03 +00:00
|
|
|
|
|
|
|
struct FlyingLimit
|
|
|
|
{
|
2012-08-08 19:32:44 +00:00
|
|
|
Math::Vector center;
|
|
|
|
float extRadius;
|
|
|
|
float intRadius;
|
|
|
|
float maxHeight;
|
|
|
|
|
|
|
|
FlyingLimit()
|
|
|
|
{
|
|
|
|
extRadius = intRadius = maxHeight = 0.0f;
|
|
|
|
}
|
2012-06-25 14:37:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CTerrain
|
|
|
|
{
|
|
|
|
public:
|
2012-06-26 20:23:05 +00:00
|
|
|
CTerrain(CInstanceManager* iMan);
|
|
|
|
~CTerrain();
|
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Generates a new flat terrain
|
|
|
|
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
|
2012-06-26 20:23:05 +00:00
|
|
|
void LevelFlush();
|
2012-08-08 19:32:44 +00:00
|
|
|
//! 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
|
2012-06-26 20:23:05 +00:00
|
|
|
bool LevelInit(int id);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Generates a level in the terrain
|
2012-06-26 20:23:05 +00:00
|
|
|
bool LevelGenerate(int *id, float min, float max, float slope, float freq, Math::Vector center, float radius);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Initializes a completely flat terrain
|
2012-06-26 20:23:05 +00:00
|
|
|
void FlushRelief();
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Load relief from a PNG file
|
|
|
|
bool ReliefFromPNG(const std::string& filename, float scaleRelief, bool adjustBorder);
|
|
|
|
//! Load resources from a PNG file
|
|
|
|
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);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
//! Management of the wind
|
|
|
|
void SetWind(Math::Vector speed);
|
|
|
|
Math::Vector GetWind();
|
|
|
|
//@}
|
|
|
|
|
|
|
|
//! Gives the exact slope of the terrain of a place given
|
|
|
|
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);
|
|
|
|
//! returns the height of the ground
|
|
|
|
float GetFloorLevel(const Math::Vector& p, bool brut=false, bool water=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);
|
|
|
|
//! Returns the resource type available underground
|
|
|
|
Gfx::TerrainRes GetResource(const Math::Vector& p);
|
|
|
|
//! Adjusts a position so that it does not exceed the boundaries
|
2012-06-26 20:23:05 +00:00
|
|
|
void LimitPos(Math::Vector &pos);
|
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Empty the table of elevations
|
2012-06-26 20:23:05 +00:00
|
|
|
void FlushBuildingLevel();
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Adds a new elevation for a building
|
2012-06-26 20:23:05 +00:00
|
|
|
bool AddBuildingLevel(Math::Vector center, float min, float max, float height, float factor);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Updates the elevation for a building when it was moved up (after a terraforming)
|
2012-06-26 20:23:05 +00:00
|
|
|
bool UpdateBuildingLevel(Math::Vector center);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Removes the elevation for a building when it was destroyed
|
2012-06-26 20:23:05 +00:00
|
|
|
bool DeleteBuildingLevel(Math::Vector center);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Returns the influence factor whether a position is on a possible rise
|
|
|
|
float GetBuildingFactor(const Math::Vector& p);
|
|
|
|
float GetHardness(const Math::Vector& p);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
int GetMosaic();
|
|
|
|
int GetBrick();
|
|
|
|
float GetSize();
|
|
|
|
float GetScaleRelief();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Shows the flat areas on the ground
|
2012-06-26 20:23:05 +00:00
|
|
|
void GroundFlat(Math::Vector pos);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Calculates the radius of the largest flat area available
|
|
|
|
float GetFlatZoneRadius(Math::Vector center, float max);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
//@{
|
|
|
|
//! Management of the global max flying height
|
2012-06-26 20:23:05 +00:00
|
|
|
void SetFlyingMaxHeight(float height);
|
2012-08-08 19:32:44 +00:00
|
|
|
float GetFlyingMaxHeight();
|
|
|
|
//@}
|
|
|
|
//! Empty the table of flying limits
|
2012-06-26 20:23:05 +00:00
|
|
|
void FlushFlyingLimit();
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Adds a new flying limit
|
|
|
|
void AddFlyingLimit(Math::Vector center, float extRadius, float intRadius, float maxHeight);
|
|
|
|
//! Returns the maximum height of flight
|
|
|
|
float GetFlyingLimit(Math::Vector pos, bool noLimit);
|
2012-06-25 14:37:03 +00:00
|
|
|
|
|
|
|
protected:
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Adds a point of elevation in the buffer of relief
|
2012-06-26 20:23:05 +00:00
|
|
|
bool ReliefAddDot(Math::Vector pos, float scaleRelief);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Adjust the edges of each mosaic to be compatible with all lower resolutions
|
2012-06-26 20:23:05 +00:00
|
|
|
void AdjustRelief();
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Calculates a vector of the terrain
|
|
|
|
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);
|
|
|
|
//! Creates all objects in a mesh square ground
|
|
|
|
bool CreateSquare(bool multiRes, int x, int y);
|
|
|
|
|
|
|
|
//! Seeks a materials based on theirs identifier
|
|
|
|
Gfx::TerrainMaterial* LevelSearchMat(int id);
|
|
|
|
//! 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
|
2012-06-26 20:23:05 +00:00
|
|
|
bool LevelGetDot(int x, int y, float min, float max, float slope);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Seeks if material exists
|
2012-06-26 20:23:05 +00:00
|
|
|
int LevelTestMat(char *mat);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Modifies the state of a point and its four neighbors, without testing if possible
|
2012-06-26 20:23:05 +00:00
|
|
|
void LevelSetDot(int x, int y, int id, char *mat);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Tests if a material can give a place, according to its four neighbors. If yes, puts the point.
|
2012-06-26 20:23:05 +00:00
|
|
|
bool LevelIfDot(int x, int y, int id, char *mat);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Modifies the state of a point
|
2012-06-26 20:23:05 +00:00
|
|
|
bool LevelPutDot(int x, int y, int id);
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Initializes a table with empty levels
|
2012-06-26 20:23:05 +00:00
|
|
|
void LevelOpenTable();
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Closes the level table
|
2012-06-26 20:23:05 +00:00
|
|
|
void LevelCloseTable();
|
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Adjusts a position according to a possible rise
|
2012-06-26 20:23:05 +00:00
|
|
|
void AdjustBuildingLevel(Math::Vector &p);
|
2012-06-25 14:37:03 +00:00
|
|
|
|
|
|
|
protected:
|
2012-06-26 20:23:05 +00:00
|
|
|
CInstanceManager* m_iMan;
|
|
|
|
CEngine* m_engine;
|
|
|
|
CWater* m_water;
|
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Number of mosaics
|
|
|
|
int m_mosaic;
|
|
|
|
//! Number of bricks per mosaics
|
|
|
|
int m_brick;
|
|
|
|
int m_levelDotSize;
|
|
|
|
//! Size of an item in a brick
|
|
|
|
float m_size;
|
|
|
|
//! Vision before a change of resolution
|
|
|
|
float m_vision;
|
|
|
|
//! 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;
|
2012-06-26 20:23:05 +00:00
|
|
|
float m_scaleRelief;
|
2012-08-08 19:32:44 +00:00
|
|
|
int m_subdivMapping;
|
|
|
|
//! Number of different resolutions (1,2,3,4)
|
|
|
|
int m_depth;
|
|
|
|
std::string m_texBaseName;
|
|
|
|
std::string m_texBaseExt;
|
2012-06-26 20:23:05 +00:00
|
|
|
float m_defHardness;
|
|
|
|
|
2012-08-12 17:28:22 +00:00
|
|
|
std::vector<TerrainMaterial> m_levelMats;
|
|
|
|
std::vector<Gfx::DotLevel> m_levelDots;
|
2012-06-26 20:23:05 +00:00
|
|
|
int m_levelMatMax;
|
|
|
|
int m_levelID;
|
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
std::vector<Gfx::BuildingLevel> m_buildingLevels;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Wind speed
|
|
|
|
Math::Vector m_wind;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-08-08 19:32:44 +00:00
|
|
|
//! Global flying height limit
|
2012-06-26 20:23:05 +00:00
|
|
|
float m_flyingMaxHeight;
|
2012-08-08 19:32:44 +00:00
|
|
|
//! List of local flight limits
|
|
|
|
std::vector<Gfx::FlyingLimit> m_flyingLimits;
|
2012-06-25 14:37:03 +00:00
|
|
|
};
|
2012-06-22 14:31:55 +00:00
|
|
|
|
|
|
|
}; // namespace Gfx
|