在 C++ 中存储三角形和直线的最佳(也是最快)方法?
我正在运行一些 3D 应用程序,我想知道存储直线和三角形的最佳方式是什么?目前,我将线条作为 typedef 向量的数组,如下所示:
typedef struct { float x, y, z; } Vector Vector line[2];
现在,我可以这样做:
typedef struct { Vector start, end; } Line Line lineVar;
面孔可能相似:
typdef struct { Vector v1, v2, v3; } Face faceVar;
我的问题是: 有没有更好或更快的方法来存储线条和面孔?或者说我做得还好吗?
谢谢,
詹姆斯
I've got a few 3D apps going, and I was wondering, what is the best way to store lines and triangles? At the moment, 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所拥有的几乎就是向量在计算机程序中的表示方式。我无法想象任何其他方法可以做到这一点。这完全没问题:(
DirectX 像这样存储矢量分量,通过)
但是,3D 密集型程序通常将面索引放入向量数组中以节省空间,因为相同的点经常出现在 3D 模型的不同面上:
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:
(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: