I'm working on a flow visualization task where I need to analyze the data in some way. The visualization iswritten by someone else and expects a vector of GLFloat containing the data. However, I would much prefer to have a class structure like below. Is there any way to achieve this without copying the data (like a union)?
struct Vertex
{
math::vec3 pos;
float time;
float velocity;
};
class Pathline
{
std::vector<Vertex> points;
};
//these have the same data
std::vector<Pathline> lines;
std::vector<GLfloat> lineData;
Thanks
答案 0 :(得分:0)
从您的示例中,我想到了几个问题:
可能你可以将你的结构改为:
struct Vertex
{
GLfloat[3] pos;
GLfloat time;
GLFloat velocity;
};
std::vector<Vertex> lineVertexData;
std::vector<GLfloat> lineData;
如果您有其他外部数据来定义路径,您可以更进一步。
一切都取决于你想做多远?#34;哲学上正确&#34; C ++代码。有些时候难以用OpenGL实现。
只要您的2个结构相同,您就可以在它们之间投射指针/引用。但这种等价并不容易。
回答您的问题: