我试图使ImGui (ImVec)和glm (glm::vec)向量类型之间的隐式转换正常工作。
在这里中,我看到必须更改imconfig.h
文件中的下列行:
#define IM_VEC2_CLASS_EXTRA \
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
operator MyVec2() const { return MyVec2(x,y); }
#define IM_VEC4_CLASS_EXTRA \
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
operator MyVec4() const { return MyVec4(x,y,z,w); }
第一行对我来说是有意义的,但我看不出第二行为MyVec创建新构造函数的意义。因为我真的不知道这里发生了什么,所以我只是尝试用glm::vecN
或vecN
代替glm::vecN
,但两者都不起作用。
我也不明白为什么会有这些反斜杠,我想他们要评论一下?不管怎么说,我都把它们移走了,但还是没起作用。
编译器最终会抛出大量错误,所以我不知道问题出在哪里。
发布于 2022-09-18 11:23:29
在包含imgui之前,必须定义/包含您的结构:
// define glm::vecN or include it from another file
namespace glm
{
struct vec2
{
float x, y;
vec2(float x, float y) : x(x), y(y) {};
};
struct vec4
{
float x, y, z, w;
vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {};
};
}
// define extra conversion here before including imgui, don't do it in the imconfig.h
#define IM_VEC2_CLASS_EXTRA \
constexpr ImVec2(glm::vec2& f) : x(f.x), y(f.y) {} \
operator glm::vec2() const { return glm::vec2(x, y); }
#define IM_VEC4_CLASS_EXTRA \
constexpr ImVec4(const glm::vec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
operator glm::vec4() const { return glm::vec4(x,y,z,w); }
#include "imgui/imgui.h"
反斜杠\
只是#define
中的换行符,以指定一个连续的定义。
https://stackoverflow.com/questions/73601927
复制相似问题