在opengl中计算球体
我想计算所需的所有顶点并用线连接它们,所以我最终想出了一个球体。有多少种方法可以做到?顶点之间的线也是直的;我怎样才能使它们“弯曲” 我知道我可以使用 glutWireSphere(),但我对实际计算顶点感兴趣。我想到的一种方法是将所有顶点手动放入一个数组中,但我想这不是它的完成方式。
I want to calculate all the vertices needed and connect them with lines, so I eventually come up with a sphere. How many ways are there to do it? And also the lines between the vertices, will be straight; how can I make them "curved" I know that I can use glutWireSphere(), but I am interested in actually calculating the vertices. A way that I thought about it, was to put all the vertices manually in an array, but I guess that is not the way it's done.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
复制并粘贴我最初在 使用 Visual C++ 在 Opengl 中创建 3D 球体
你不能。所有 OpenGL 图元都是“仿射”的,即平面的或直线的。通过绘制具有足够分辨率的短而直的部分来模拟曲率。
Copy and Pasting some code I originally wrote in Creating a 3D sphere in Opengl using Visual C++
You can't. All OpenGL primitives are "affine", i.e. planar or straight. Curvature is emulated by drawing short, straight sections with sufficient resolution.
有不止一种方法可以做到这一点:a) icosphere 生成和 b)UV 球体生成。可能有更多方法可以做到这一点。一些谷歌搜索让我找到了这篇关于 icosphere 生成的优秀文章。但我找不到 UV 球体生成方法。
There's more than one way to do this: a) icosphere generation and b)UV sphere generation. There may be more methods to do this. Some googling got me this excellent post on icosphere generation. I couldn't find UV sphere generation method though.
Paul Bourke 实际上对球体生成有一个很好的介绍。至于曲线,OpenGL中没有这样的东西。您只能通过添加更多中间连接点来使它们看起来弯曲。
Paul Bourke actually has a nice introduction to sphere generation. And as for curved lines, there is no such thing in OpenGL. You can only make them appear curved by adding more intermediate connected points.
datenwolf 的答案很好,但包含一些错误。
使用 vbo 时,客户端状态必须在启用后禁用。
添加三行绘制代码
datenwolf's answer is great but contains some error.
When you use vbo, client states must be disabled after enabled.
Add Three lines to draw code
一个圣像圈就能达到目的。
不过,要用它制作一个球体,您必须细分它的三角形。
An iconosphere would do the trick .
Still , to make a sphere with it , you will have to subdivide it's triangles.
在我看来,关于如何制作 icosphere 的教程有很多,但关于使用极坐标的面逼近方法的教程却很少。
因此,这里是 Richard S. Wright Jr. 所著的《OpenGL Superbible》第 4 版书中的代码示例,经过稍加编辑。
因为它是固定功能管道的非常简单的使用(没有 glDrawElements 等...),我发现它对于教育很有用目的。
堆栈被绘制为一系列三角形条带。显然不是最佳性能,但它确实有效!
不幸的是,我找不到该源代码的原始在线存储库的链接,它非常古老。如果您知道在哪里可以找到它,请随时发帖!
It seems to me there's a great abundance of tutorials on how to make icospheres, but not so much about the method of facet approximation using polar coordinates.
So here's a very slightly edited code sample from the OpenGL Superbible 4th Edition book by Richard S. Wright Jr.
Since it's a very bare bones usage of the fixed-function pipeline (no glDrawElements, etc...) I found it useful for educational purposes.
Stacks are drawn as series of triangle strips. Obviously not the optimal performance, but it works!
Unfortunately I couldn't find back a link to the original online repository of this source code, it's pretty ancient. Feel free to post if you know where to find it !