开发者

Best (and fastest) way to store triangles and lines in C++?

I've got a few 3D apps going, and I was wondering, what is the best way to store lines and triangles? At the m开发者_如何学Gooment, I have lines as an array of typedef'd vectors as such:

typedef struct
{
    float x, y, z;
}
Vector

Vector line[2];

Now, I could do it like this:

typedef struct 
{
    Vector start, end;
}
Line

Line lineVar;

Faces could be similar:

typdef struct
{
    Vector v1, v2, v3;
}

Face faceVar;

My question is this: Is there a better or faster way to store lines and faces? Or am I doing it OK?

Thanks,

James


What you have is pretty much how vectors are represented in computer programs. I can't imagine any other way to do it. This is perfectly fine:

typedef struct
{
    float x, y, z;
} Vector;

(DirectX stores vector components like this, by the way.)

However, 3D intensive programs typically have the faces index into a vector array to save space since the same points often appear on different faces of a 3D model:

typedef struct
{
    int vectorIndex1, vectorIndex2, vectorIndex3;
} Face;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜