修改OpenGl渲染底层之前

This commit is contained in:
2025-10-20 20:50:12 +08:00
parent 1b011b9b68
commit 2b888aae5b
61 changed files with 1609 additions and 680 deletions

View File

@@ -84,6 +84,7 @@ typedef struct VecPos
y -= other.y;
return *this;
}
} VecPos;
// 浮点数坐标向量
@@ -120,6 +121,12 @@ typedef struct VecFPos
return VecFPos(x * other.x, y * other.y);
}
// 除法运算符重载:除以一个 float 值
VecFPos operator/(float value) const
{
return VecFPos(x / value, y / value);
}
// 等于运算符重载:判断两个 VecFPos 是否相等
// 注意:浮点数比较需要考虑精度问题
bool operator==(const VecFPos &other) const
@@ -212,38 +219,19 @@ typedef struct VecPos3
return x == other.x && y == other.y && z == other.z;
}
bool operator!=(const VecPos3 &other) const
{
return x != other.x || y != other.y || z != other.z;
}
} VecPos3;
typedef struct VecFPos3
{
float x;
float y;
float z;
VecFPos3(float x_ = 0, float y_ = 0, float z_ = 0) : x(x_), y(y_), z(z_) {}
VecFPos3 operator+(const VecFPos3 &other) const
{
return VecFPos3(x + other.x, y + other.y, z + other.z);
}
VecFPos3 operator-(const VecFPos3 &other) const
{
return VecFPos3(x - other.x, y - other.y, z - other.z);
}
bool operator==(const VecFPos3 &other) const
{
return x == other.x && y == other.y && z == other.z;
}
} VecFPos3;
typedef struct VecSpeed3
{
float x;
float y;
float z;
VecSpeed3(float x_ = 0, float y_ = 0, float z_ = 0) : x(x_), y(y_), z(z_) {}
int x;
int y;
int z;
VecSpeed3(int x_ = 0, int y_ = 0, int z_ = 0) : x(x_), y(y_), z(z_) {}
VecSpeed3 operator+(const VecSpeed3 &other) const
{

View File

@@ -15,37 +15,6 @@ std::string Tool_toLowerCase(const std::string &str)
{ return std::tolower(c); });
return result;
}
// GBK 转 UTF-8基于 SDL2 的 SDL_iconv
std::string Tool_Gbk2Utf8(const std::string &gbk_str)
{
iconv_t cd = iconv_open("UTF-8", "GBK");
if (cd == (iconv_t)-1)
{
throw std::runtime_error("Failed to open iconv conversion descriptor");
}
size_t in_bytes_left = gbk_str.size();
char *in_buf = const_cast<char *>(gbk_str.data());
// 分配输出缓冲区GBK转UTF-8后长度最多可能增长到原长的3倍
size_t out_bytes_left = gbk_str.size() * 3 + 1;
std::string utf8_str(out_bytes_left, '\0');
char *out_buf = &utf8_str[0];
// 执行转换
size_t result = iconv(cd, &in_buf, &in_bytes_left, &out_buf, &out_bytes_left);
iconv_close(cd);
if (result == (size_t)-1)
{
throw std::runtime_error("Conversion failed!");
}
// 调整字符串大小以去除未使用的空间
utf8_str.resize(utf8_str.size() - out_bytes_left);
return utf8_str;
}
std::string Tool_RegRealPath(const std::string &Path)
{
// 检查路径中是否包含"../"

View File

@@ -5,8 +5,6 @@
std::string Tool_toLowerCase(const std::string &str);
std::string Tool_Gbk2Utf8(const std::string &gbk_str);
std::string Tool_RegRealPath(const std::string &Path);
std::string Tool_TruncatePath(const std::string &path);