OpenGL es 2.0 iOS中的球体[重复]

时间:2022-09-10 22:58:47

Possible Duplicate:
Drawing a sphere in OpenGL ES

可能重复:在OpenGL ES中绘制球体

I have been browsing around for quite some time now, and have yet to find an adequate answer. I started learning Opengl es 2.0 (Because I need to for a project in university) and have recently accomplished drawing a circle. WOOPIE!

我已经浏览了很长一段时间了,还没有找到合适的答案。我开始学习Opengl es 2.0(因为我需要参加大学的一个项目)并且最近完成了绘制圆圈。 WOOPIE!

I have looked at a great deal of similar questions, but it is either outdated or I too complex for me to grasp. Can anyone point me in the proper direction of how to draw a solid sphere with opengl ES 2.0 on iOS?

我看了很多类似的问题,但它要么已经过时,要么我太复杂了,无法掌握。任何人都可以指出我在iOS上如何用opengl ES 2.0绘制实体球的正确方向?

1 个解决方案

#1


6  

I'm not sure how far along you are, so I'm just going to give some general notes that I think might be helpful, and point you to some resources that I've been using to climb up the learning curve.

我不确定你有多远,所以我只想给出一些我认为可能有用的一般性说明,并指出一些我一直用来爬上学习曲线的资源。

A sphere is a complex enough object that you're probably not going to want to generate the vertices in code, as you may have drawn the circle -- you'll want to use a program like Blender or Maya or Houdini, whatever you like to use to build a 3d object, and then export it.

一个球体是一个足够复杂的物体,你可能不想在代码中生成顶点,因为你可能已经绘制了圆圈 - 你会想要使用像Blender或Maya或Houdini这样的程序,无论你喜欢什么用于构建3d对象,然后导出它。

Your goal will be to follow a workflow like: 3D program > .obj or maybe a .collada file > array of vertices that OpenGL can use.

您的目标是遵循以下工作流程:3D程序> .obj或者.collada文件> OpenGL可以使用的顶点数组。

Your array of vertices (which should be a C array[], not NSArray) will hold a {x,y,z} position for each vertex, and you may also want to use texture coordinates and normals. You'll want to export texture coordinates from your 3D program if you plan on using textures, and you'll want to export normals if you plan on lighting the object. The texture coordinates will be in the format {s,t} which connects the vertex it is associated with to a 2d coordinate on the rectangular texture. The normals will be a vector in the format {x,y,z}. The tex coords & normals may either be in the same array you have the vertices in (interleaved) or in separate arrays. If they're interleaved, then in your code you'll have one VBO and it's generally faster, but if they're not, you'll have separate VBOs - one for the position vertices, one for the tex coords, one for the normals.

您的顶点数组(应该是C数组[],而不是NSArray)将为每个顶点保持{x,y,z}位置,您可能还想使用纹理坐标和法线。如果计划使用纹理,则需要从3D程序中导出纹理坐标,如果计划点亮对象,则需要导出法线。纹理坐标将采用格式{s,t},其将与其关联的顶点连接到矩形纹理上的2d坐标。法线将是{x,y,z}格式的向量。 tex坐标和法线可以位于具有顶点(交错)的相同阵列中,也可以位于单独的阵列中。如果它们是交错的,那么在你的代码中你将有一个VBO并且它通常更快,但如果它们不是,你将有单独的VBO - 一个用于位置顶点,一个用于tex坐标,一个用于法线。

This is a good script I've come across for converting .obj to a C header for use with OpenGL. So after you export from your 3D program to .obj, you'd pass the .obj to this script and it would spit out a .h file: http://heikobehrens.net/2009/08/27/obj2opengl/

这是我用来将.obj转换为用于OpenGL的C头的好脚本。因此,在从3D程序导出到.obj后,您将.obj传递给此脚本,它会吐出.h文件:http://heikobehrens.net/2009/08/27/obj2opengl/

Once you have the C header file, you just #import "sphere.h" - and then when you later call glBufferData to read in the vertices, you pass the name of the array that's in sphere.h.

获得C头文件后,只需#import“sphere.h” - 然后当您稍后调用glBufferData读取顶点时,将传递sphere.h中的数组名称。

This book is the best I've come across for learning OpenGL on iOS. It provides good explanations of the GLKit classes, and is friendly to beginners: http://my.safaribooksonline.com/book/animation-and-3d/9780132478939

这本书是我在iOS上学习OpenGL时遇到的最好的书。它提供了很好的GLKit课程解释,对初学者很友好:http://my.safaribooksonline.com/book/animation-and-3d/9780132478939

And in case it's helpful, here's some sample code I put together for a talk I gave a couple months ago. It actually puts us 'inside' an exploded sphere and lets us swipe to rotate: http://davidsweetman.com/mobilemeetup-talk-glkit-demo.html

如果它有用,这里有一些示例代码,我把它放在一起,几个月前我给的一个演讲。它实际上让我们“内部”爆炸的球体,让我们滑动旋转:http://davidsweetman.com/mobilemeetup-talk-glkit-demo.html

#1


6  

I'm not sure how far along you are, so I'm just going to give some general notes that I think might be helpful, and point you to some resources that I've been using to climb up the learning curve.

我不确定你有多远,所以我只想给出一些我认为可能有用的一般性说明,并指出一些我一直用来爬上学习曲线的资源。

A sphere is a complex enough object that you're probably not going to want to generate the vertices in code, as you may have drawn the circle -- you'll want to use a program like Blender or Maya or Houdini, whatever you like to use to build a 3d object, and then export it.

一个球体是一个足够复杂的物体,你可能不想在代码中生成顶点,因为你可能已经绘制了圆圈 - 你会想要使用像Blender或Maya或Houdini这样的程序,无论你喜欢什么用于构建3d对象,然后导出它。

Your goal will be to follow a workflow like: 3D program > .obj or maybe a .collada file > array of vertices that OpenGL can use.

您的目标是遵循以下工作流程:3D程序> .obj或者.collada文件> OpenGL可以使用的顶点数组。

Your array of vertices (which should be a C array[], not NSArray) will hold a {x,y,z} position for each vertex, and you may also want to use texture coordinates and normals. You'll want to export texture coordinates from your 3D program if you plan on using textures, and you'll want to export normals if you plan on lighting the object. The texture coordinates will be in the format {s,t} which connects the vertex it is associated with to a 2d coordinate on the rectangular texture. The normals will be a vector in the format {x,y,z}. The tex coords & normals may either be in the same array you have the vertices in (interleaved) or in separate arrays. If they're interleaved, then in your code you'll have one VBO and it's generally faster, but if they're not, you'll have separate VBOs - one for the position vertices, one for the tex coords, one for the normals.

您的顶点数组(应该是C数组[],而不是NSArray)将为每个顶点保持{x,y,z}位置,您可能还想使用纹理坐标和法线。如果计划使用纹理,则需要从3D程序中导出纹理坐标,如果计划点亮对象,则需要导出法线。纹理坐标将采用格式{s,t},其将与其关联的顶点连接到矩形纹理上的2d坐标。法线将是{x,y,z}格式的向量。 tex坐标和法线可以位于具有顶点(交错)的相同阵列中,也可以位于单独的阵列中。如果它们是交错的,那么在你的代码中你将有一个VBO并且它通常更快,但如果它们不是,你将有单独的VBO - 一个用于位置顶点,一个用于tex坐标,一个用于法线。

This is a good script I've come across for converting .obj to a C header for use with OpenGL. So after you export from your 3D program to .obj, you'd pass the .obj to this script and it would spit out a .h file: http://heikobehrens.net/2009/08/27/obj2opengl/

这是我用来将.obj转换为用于OpenGL的C头的好脚本。因此,在从3D程序导出到.obj后,您将.obj传递给此脚本,它会吐出.h文件:http://heikobehrens.net/2009/08/27/obj2opengl/

Once you have the C header file, you just #import "sphere.h" - and then when you later call glBufferData to read in the vertices, you pass the name of the array that's in sphere.h.

获得C头文件后,只需#import“sphere.h” - 然后当您稍后调用glBufferData读取顶点时,将传递sphere.h中的数组名称。

This book is the best I've come across for learning OpenGL on iOS. It provides good explanations of the GLKit classes, and is friendly to beginners: http://my.safaribooksonline.com/book/animation-and-3d/9780132478939

这本书是我在iOS上学习OpenGL时遇到的最好的书。它提供了很好的GLKit课程解释,对初学者很友好:http://my.safaribooksonline.com/book/animation-and-3d/9780132478939

And in case it's helpful, here's some sample code I put together for a talk I gave a couple months ago. It actually puts us 'inside' an exploded sphere and lets us swipe to rotate: http://davidsweetman.com/mobilemeetup-talk-glkit-demo.html

如果它有用,这里有一些示例代码,我把它放在一起,几个月前我给的一个演讲。它实际上让我们“内部”爆炸的球体,让我们滑动旋转:http://davidsweetman.com/mobilemeetup-talk-glkit-demo.html