Refactored Math::Point in CPlanet, CTerrain, CWater and CLevelParserParam

dev
Tomasz Kapuściński 2021-12-24 02:04:15 +01:00
parent 498f15cc92
commit 07d3d79e8d
8 changed files with 32 additions and 32 deletions

View File

@ -113,7 +113,7 @@ void CPlanet::Draw()
else else
m_engine->SetState(ENG_RSTATE_WRAP | ENG_RSTATE_TTEXTURE_BLACK); m_engine->SetState(ENG_RSTATE_WRAP | ENG_RSTATE_TTEXTURE_BLACK);
Math::Point p1, p2; glm::vec2 p1, p2;
// Determine the 2D coordinates of the centre of the planet. // Determine the 2D coordinates of the centre of the planet.
@ -141,10 +141,10 @@ void CPlanet::Draw()
Vertex quad[4] = Vertex quad[4] =
{ {
{ Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2) }, { Math::Vector(p1.x, p1.y, 0.0f), n, { u1, v2 } },
{ Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1) }, { Math::Vector(p1.x, p2.y, 0.0f), n, { u1, v1 } },
{ Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2) }, { Math::Vector(p2.x, p1.y, 0.0f), n, { u2, v2 } },
{ Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1) } { Math::Vector(p2.x, p2.y, 0.0f), n, { u2, v1 } }
}; };
device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, quad, 4); device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, quad, 4);
@ -152,8 +152,8 @@ void CPlanet::Draw()
} }
} }
void CPlanet::Create(PlanetType type, Math::Point start, float dim, float speed, void CPlanet::Create(PlanetType type, const glm::vec2& start, float dim, float speed,
float dir, const std::string& name, Math::Point uv1, Math::Point uv2, float dir, const std::string& name, const glm::vec2& uv1, const glm::vec2& uv2,
bool transparent) bool transparent)
{ {
Planet planet; Planet planet;

View File

@ -26,8 +26,9 @@
#include "graphics/engine/planet_type.h" #include "graphics/engine/planet_type.h"
#include "math/point.h" #include <glm/glm.hpp>
#include <string>
#include <vector> #include <vector>
struct Event; struct Event;
@ -57,8 +58,8 @@ public:
//! Management of an event //! Management of an event
bool EventProcess(const Event &event); bool EventProcess(const Event &event);
//! Creates a new planet //! Creates a new planet
void Create(PlanetType type, Math::Point start, float dim, float speed, float dir, void Create(PlanetType type, const glm::vec2& start, float dim, float speed, float dir,
const std::string& name, Math::Point uv1, Math::Point uv2, const std::string& name, const glm::vec2& uv1, const glm::vec2& uv2,
bool transparent); bool transparent);
//! Indicates if there is at least one planet //! Indicates if there is at least one planet
bool PlanetExist(); bool PlanetExist();
@ -88,9 +89,9 @@ protected:
//! Type of planet //! Type of planet
PlanetType type = PlanetType::Sky; PlanetType type = PlanetType::Sky;
//! Initial position in degrees //! Initial position in degrees
Math::Point start; glm::vec2 start;
//! Current position in degrees //! Current position in degrees
Math::Point angle; glm::vec2 angle;
//! Dimensions (0..1) //! Dimensions (0..1)
float dim = 0.0f; float dim = 0.0f;
//! Speed //! Speed
@ -100,7 +101,7 @@ protected:
//! Name of the texture //! Name of the texture
std::string name; std::string name;
//! Texture mapping //! Texture mapping
Math::Point uv1, uv2; glm::vec2 uv1, uv2;
// TODO: make all textures transparent? // TODO: make all textures transparent?
//! Transparent texture //! Transparent texture

View File

@ -161,7 +161,7 @@ void CTerrain::FlushMaterials()
FlushMaterialPoints(); FlushMaterialPoints();
} }
void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point &uv, void CTerrain::AddMaterial(int id, const std::string& texName, const glm::vec2& uv,
int up, int right, int down, int left, int up, int right, int down, int left,
float hardness) float hardness)
{ {
@ -754,7 +754,7 @@ CTerrain::TerrainMaterial* CTerrain::FindMaterial(int id)
return nullptr; return nullptr;
} }
void CTerrain::GetTexture(int x, int y, std::string& name, Math::Point &uv) void CTerrain::GetTexture(int x, int y, std::string& name, glm::vec2&uv)
{ {
x /= m_brickCount/m_textureSubdivCount; x /= m_brickCount/m_textureSubdivCount;
y /= m_brickCount/m_textureSubdivCount; y /= m_brickCount/m_textureSubdivCount;
@ -1807,7 +1807,7 @@ float CTerrain::GetFlatZoneRadius(Math::Vector center, float max)
return 0.0f; return 0.0f;
float ref = GetFloorLevel(center, true); float ref = GetFloorLevel(center, true);
Math::Point c(center.x, center.z); glm::vec2 c = { center.x, center.z };
float radius = 1.0f; float radius = 1.0f;
while (radius <= max) while (radius <= max)
@ -1816,10 +1816,10 @@ float CTerrain::GetFlatZoneRadius(Math::Vector center, float max)
int nb = static_cast<int>(2.0f*Math::PI*radius); int nb = static_cast<int>(2.0f*Math::PI*radius);
if (nb < 8) nb = 8; if (nb < 8) nb = 8;
Math::Point p (center.x+radius, center.z); glm::vec2 p = { center.x + radius, center.z };
for (int i = 0; i < nb; i++) for (int i = 0; i < nb; i++)
{ {
Math::Point result = Math::RotatePoint(c, angle, p); glm::vec2 result = Math::RotatePoint(c, angle, p);
Math::Vector pos; Math::Vector pos;
pos.x = result.x; pos.x = result.x;
pos.z = result.y; pos.z = result.y;

View File

@ -27,7 +27,6 @@
#include "graphics/core/vertex.h" #include "graphics/core/vertex.h"
#include "math/const.h" #include "math/const.h"
#include "math/point.h"
#include "math/vector.h" #include "math/vector.h"
#include <string> #include <string>
@ -159,7 +158,7 @@ public:
//! Clears all terrain materials //! Clears all terrain materials
void FlushMaterials(); void FlushMaterials();
//! Adds a terrain material the names of textures to use for the land //! Adds a terrain material the names of textures to use for the land
void AddMaterial(int id, const std::string& texName, const Math::Point& uv, void AddMaterial(int id, const std::string& texName, const glm::vec2& uv,
int up, int right, int down, int left, float hardness); int up, int right, int down, int left, float hardness);
//! Initializes all the ground with one material //! Initializes all the ground with one material
bool InitMaterials(int id); bool InitMaterials(int id);
@ -266,7 +265,7 @@ protected:
//! Seeks a material based on neighbor values //! Seeks a material based on neighbor values
int FindMaterialByNeighbors(char *mat); int FindMaterialByNeighbors(char *mat);
//! Returns the texture name and UV coords to use for a given square //! Returns the texture name and UV coords to use for a given square
void GetTexture(int x, int y, std::string& name, Math::Point& uv); void GetTexture(int x, int y, std::string& name, glm::vec2& uv);
//! Returns the height of the terrain //! Returns the height of the terrain
float GetHeight(int x, int y); float GetHeight(int x, int y);
//! Decide whether a point is using the materials //! Decide whether a point is using the materials
@ -334,7 +333,7 @@ protected:
//! Texture //! Texture
std::string texName; std::string texName;
//! UV texture coordinates //! UV texture coordinates
Math::Point uv; glm::vec2 uv;
//! Terrain hardness (defines e.g. sound of walking) //! Terrain hardness (defines e.g. sound of walking)
float hardness = 0.0f; float hardness = 0.0f;
//! IDs of neighbor materials: up, right, down, left //! IDs of neighbor materials: up, right, down, left

View File

@ -191,7 +191,7 @@ void CWater::VaporFrame(int i, float rTime)
speed.x = (Math::Rand()-0.5f)*6.0f; speed.x = (Math::Rand()-0.5f)*6.0f;
speed.z = (Math::Rand()-0.5f)*6.0f; speed.z = (Math::Rand()-0.5f)*6.0f;
speed.y = 8.0f+Math::Rand()*5.0f; speed.y = 8.0f+Math::Rand()*5.0f;
Math::Point dim; glm::vec2 dim;
dim.x = Math::Rand()*1.5f+1.5f; dim.x = Math::Rand()*1.5f+1.5f;
dim.y = dim.x; dim.y = dim.x;
m_particle->CreateParticle(pos, speed, dim, PARTIERROR, 2.0f, 10.0f); m_particle->CreateParticle(pos, speed, dim, PARTIERROR, 2.0f, 10.0f);
@ -207,7 +207,7 @@ void CWater::VaporFrame(int i, float rTime)
speed.x = (Math::Rand()-0.5f)*2.0f; speed.x = (Math::Rand()-0.5f)*2.0f;
speed.z = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f;
speed.y = 4.0f+Math::Rand()*4.0f; speed.y = 4.0f+Math::Rand()*4.0f;
Math::Point dim; glm::vec2 dim;
dim.x = Math::Rand()*2.0f+2.0f; dim.x = Math::Rand()*2.0f+2.0f;
dim.y = dim.x; dim.y = dim.x;
m_particle->CreateParticle(pos, speed, dim, PARTIFLAME); m_particle->CreateParticle(pos, speed, dim, PARTIFLAME);
@ -222,7 +222,7 @@ void CWater::VaporFrame(int i, float rTime)
speed.x = (Math::Rand()-0.5f)*2.0f; speed.x = (Math::Rand()-0.5f)*2.0f;
speed.z = (Math::Rand()-0.5f)*2.0f; speed.z = (Math::Rand()-0.5f)*2.0f;
speed.y = 8.0f+Math::Rand()*8.0f; speed.y = 8.0f+Math::Rand()*8.0f;
Math::Point dim; glm::vec2 dim;
dim.x = Math::Rand()*1.0f+1.0f; dim.x = Math::Rand()*1.0f+1.0f;
dim.y = dim.x; dim.y = dim.x;
m_particle->CreateParticle(pos, speed, dim, PARTIVAPOR); m_particle->CreateParticle(pos, speed, dim, PARTIVAPOR);
@ -236,7 +236,7 @@ void CWater::VaporFrame(int i, float rTime)
} }
void CWater::AdjustLevel(Math::Vector &pos, Math::Vector &norm, void CWater::AdjustLevel(Math::Vector &pos, Math::Vector &norm,
Math::Point &uv1, Math::Point &uv2) glm::vec2& uv1, glm::vec2& uv2)
{ {
float t1 = m_time*1.5f + pos.x*0.1f * pos.z*0.2f; float t1 = m_time*1.5f + pos.x*0.1f * pos.z*0.2f;
pos.y += sinf(t1)*m_eddy.y; pos.y += sinf(t1)*m_eddy.y;
@ -384,7 +384,7 @@ void CWater::DrawSurf()
int vertexIndex = 0; int vertexIndex = 0;
Math::Point uv1, uv2; glm::vec2 uv1, uv2;
Math::Vector n; Math::Vector n;
p.x = pos.x-size; p.x = pos.x-size;

View File

@ -108,7 +108,7 @@ protected:
//! Makes evolve the steam jets on the lava //! Makes evolve the steam jets on the lava
void LavaFrame(float rTime); void LavaFrame(float rTime);
//! Adjusts the position to normal, to imitate reflections on an expanse of water at rest //! Adjusts the position to normal, to imitate reflections on an expanse of water at rest
void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2); void AdjustLevel(Math::Vector &pos, Math::Vector &norm, glm::vec2& uv1, glm::vec2& uv2);
//! Indicates if there is water in a given position //! Indicates if there is water in a given position
bool GetWater(int x, int y); bool GetWater(int x, int y);
//! Updates the positions, relative to the ground //! Updates the positions, relative to the ground

View File

@ -73,7 +73,7 @@ CLevelParserParam::CLevelParserParam(Gfx::Color value)
LoadArray(); LoadArray();
} }
CLevelParserParam::CLevelParserParam(Math::Point value) CLevelParserParam::CLevelParserParam(glm::vec2 value)
{ {
m_array.push_back(MakeUnique<CLevelParserParam>(value.x)); m_array.push_back(MakeUnique<CLevelParserParam>(value.x));
m_array.push_back(MakeUnique<CLevelParserParam>(value.y)); m_array.push_back(MakeUnique<CLevelParserParam>(value.y));

View File

@ -33,13 +33,13 @@
#include "level/scoreboard.h" #include "level/scoreboard.h"
#include "math/point.h"
#include "object/drive_type.h" #include "object/drive_type.h"
#include "object/mission_type.h" #include "object/mission_type.h"
#include "object/object_type.h" #include "object/object_type.h"
#include "object/tool_type.h" #include "object/tool_type.h"
#include <glm/glm.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory> #include <memory>
@ -60,7 +60,7 @@ public:
CLevelParserParam(std::string value); CLevelParserParam(std::string value);
CLevelParserParam(bool value); CLevelParserParam(bool value);
CLevelParserParam(Gfx::Color value); CLevelParserParam(Gfx::Color value);
CLevelParserParam(Math::Point value); CLevelParserParam(glm::vec2 value);
CLevelParserParam(Math::Vector value); CLevelParserParam(Math::Vector value);
CLevelParserParam(ObjectType value); CLevelParserParam(ObjectType value);
CLevelParserParam(Gfx::CameraType value); CLevelParserParam(Gfx::CameraType value);