OpenGL ES 2.0 球体 [英] OpenGL ES 2.0 Sphere

查看:23
本文介绍了OpenGL ES 2.0 球体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 OpenGL ES 2.0 中使用 GL_TRIANGLES 绘制纹理球体的最简单方法是什么?

What is the easiest way to draw a textured Sphere in OpenGL ES 2.0 with GL_TRIANGLES?

我特别想知道如何计算顶点.

I'm especially wondering how to calculate the vertices.

推荐答案

对球体进行三角测量的方法有很多种.受欢迎的,不太受欢迎的,好的,不太好的.不幸的是,最广泛使用的方法并不是很好.

There are various ways of triangulating spheres. Popular ones, less popular ones, good ones, and not so good ones. Unfortunately the most widely used approach isn't very good.

这可能是最广泛使用的方法.您在两个嵌套循环中遍历 球坐标系 中的两个角度,并为每个角度生成点一对角.角度 theta-pi/2 迭代到 pi/2 角度 phi0 迭代2*pi,球体半径r,每个点计算为:

This might be the most widely used approach. You iterate through the two angles in a spherical coordinate system in two nested loops, and generate points for each pair of angles. With angle theta iterating from -pi/2 to pi/2 and angle phi iterating from 0 to 2*pi, and sphere radius r, each point is calculated as:

x = r * cos(theta) * cos(phi)
y = r * cos(theta) * sin(phi)
z = r * sin(theta)

如有必要,计算可以提高效率,但我将跳过这方面的答案.细分的级别(精度)由角度的细分数决定.

The calculation can be made more efficient if necessary, but I'll skip that aspect for this answer. The level (precision) of the tessellation is determined by the number of subdivisions of the angles.

这种方法的主要优点是实现简单,并且易于理解.您可以将细分想象成地球上的经纬线.

The main advantage of this approach is that it's simple to implement, and easy to understand. You can picture the subdivision as the lines of latitude and longitude on a globe.

但是,它不会产生非常好的三角测量.赤道周围的三角形在所有方向上都有相似的尺寸,但靠近北极/南极的三角形变得越来越窄.在北极/南极,您有大量非常窄的三角形在一个点上相遇.好的三角剖分都有大小非常相似的三角形,而这个没有.

It does not result in a very good triangulation, though. The triangles around the equator have similar dimensions in all directions, but the triangles closer to the north/south pole get increasingly narrow. At the north/south pole you have a large number of very narrow triangles meeting in a single point. Good triangulations have all very similar sized triangles, and this one does not.

使用这种方法,您从一个常规的八面体开始,为您提供 8 个三角形.然后递归地将每个三角形细分为 4 个子三角形,如下所示:

With this approach, you start with a regular octahedron, giving you 8 triangles. You then recursively subdivide each triangle into 4 sub-triangles, as illustrated here:

     /
    /  
   /____
  /    /
 /    /  
/____/____

因此每个三角形通过计算两个现有顶点中间的 3 个附加顶点来细分,并且由这 6 个顶点形成 4 个三角形.为了计算两个输入点之间的中点,您需要计算两个向量的和,然后对结果进行归一化以使该点回到球体上.

So each triangle is subdivided by calculating 3 additional vertices that are midway between two of the existing vertices, and 4 triangles are formed from these 6 vertices. For calculating the midway point between two input points, you calculate the sum of the two vectors, and normalize the result to get the point back on the sphere.

细分的级别(精度)由递归细分中的级别数确定.它从 0 层八面体的 8 个原始三角形开始,在 1 层产生 32 个三角形,在 2 层产生 128 个三角形,在 3 层产生 512 个等.通常在 3 层附近得到一个相当漂亮的球体.

The level (precision) of the tessellation is determined by the number of levels in the recursive subdivision. It starts with the 8 original triangles of the octahedron at level 0, results in 32 triangles at level 1, 128 at level 2, 512 at level 3, etc. You normally get a reasonably good looking sphere around level 3.

这种方法产生更规则的三角测量,因此优于球坐标方法.

This approach results in a much more regular triangulation, and is therefore superior to the spherical coordinate approach.

主要缺点是它可能看起来更复杂.积分的计算其实很简单.如果您想使用索引顶点而不是重复公共顶点,它会变得更加棘手.如果你想构建漂亮的三角形条带,那就更痛苦了.不是很困难,但需要一些工作.

The main disadvantage is that it might seem more complex. The calculation of the points is in fact very simple. It gets slightly more tricky if you want to use indexed vertices, instead of repeating common vertices. And even more painful if you want to build nice triangle strips. Not terribly difficult, but it takes some work.

这是我最喜欢的绘制球体的方法.

This is my favorite approach of drawing spheres.

您可以从其他多面体开始对八面体进行我描述的相同操作.由三角形组成的正多面体特别合适,这使得四面体和二十面体成为自然候选者.八面体是最吸引人的恕我直言,因为初始坐标很容易枚举.使用二十面体可能会导致更规则的三角剖分,并且可以查找顶点坐标.

You can do the same thing I described for the octahedron starting with other polyhedra. Regular polyhedra that consist of triangles are particularly suitable, which makes the tethrahedron and the icosahedron natural candidates. The octahedron is the most attractive IMHO because the initial coordinates are so easy to enumerate. Using an icosahedron would probably result in an even more regular triangulation, and the vertex coordinates can be looked up.

我不确定是否有人真的在使用它.但我最近尝试了它,它很有趣.:) 这个想法是你取一个以原点为中心的立方体,并将六个边中的每一个细分为更小的子正方形.然后,您可以通过简单地对描述顶点的每个向量进行归一化来将立方体变成一个球体.

I'm not sure if anybody is actually using this. But I tried it recently, and it was kind of fun. :) The idea is that you take a cube centered at the origin, and subdivide each of the six sides into smaller sub-squares. You can then turn the cube into a sphere by simply normalizing each of the vectors that describe a vertex.

这种方法的优点是非常简单,包括构建三角条.三角测量的质量似乎相当不错.我认为它不像递归细分八面体那样规则,但绝对比(非常)广泛使用的球坐标方法更好.

The advantage of this approach is that it's very simple, including building triangle strips. The quality of the triangulation seems reasonably good. I don't think it's as regular as the recursively subdivided octahedron, but definitely better than the (much too) widely used spherical coordinate approach.

这篇关于OpenGL ES 2.0 球体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆