OpenGL es 2.0 iOS中的球体 [英] Sphere in OpenGL es 2.0 iOS

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

问题描述


可能重复:

在OpenGL ES中绘制球体


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



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

解决方案

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

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



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



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



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



一旦你有了C头文件,你只需#importsphere.h - 然后当你稍后调用glBufferData读取顶点时,你传递的是sphere.h中数组的名称。



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



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


Possible Duplicate:
Drawing a sphere in 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!

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?

解决方案

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.

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

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.

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/

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.

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

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

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

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