获得圆形opengl立方体的最简单方法是什么
始终在 Java/Opengl 和 lwjgl 中的魔方应用程序的上下文中,我想改进我的绘图 (http://manuelselva.files.wordpress.com/2010/09/cube.gif),以便 27 个小立方体中的每一个都有圆角边缘?我最终想要达到的效果与维基百科立方体图片相同: http://fr.wikipedia.org/wiki/Fichier:Rubik%27s_cube.svg
最简单的解决方案是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些巧妙的纹理和精心制作的法线贴图大部分会在不编辑模型的情况下伪造出圆形的外观。最终渲染将被着色,就好像各个边都是圆形的一样。
不幸的是,通过这种方法,当从侧面观察时,这种错觉就会崩溃。
Some clever texturing and a properly crafted normal map will mostly fake the look of it being rounded without editing the model. The final render would be shaded as if the individual sides were rounded.
Unfortunately with this approach the illusion falls apart when viewed edge-on.
您还可以使用基本立方体并实现细分算法,使每次迭代使用的顶点数量加倍。然后创建从立方体中心到每个顶点的向量。如果对顶点进行标准化,您将得到一个球体(介于:这是最简单的球体生成算法之一)。但如果你只改变角向量的长度,你将得到一个圆角立方体。
You can also use a basic cube and implement a subdivide algorithm, that doubles the number of used vertices with each iteration. Then create a vector from the center of the cube to each vertice. If you normalize the vertices you get a sphere (between: This is one of the simplest sphere generation algorithms). But if you only change the length of the vectors of the corners, you will get a rounded cube.
最简单的可能是在众多 3D 建模程序之一中绘制圆角立方体的模型(例如 Maya、Blender),然后加载您的代码中有 27 个模型实例。学习使用这样的程序并不是一件容易的事,所以即使这是大多数游戏等中使用的通用方法,对于这么简单的东西来说可能有点矫枉过正——可能需要更长的时间才能弄清楚如何要在程序中完成任何事情,就必须以不同的方式做事。
明显的替代方案是在代码中生成模型。基本思想相当简单,但将它们放在一起可能有点不简单。首先选择要用于拐角的半径。当你生成你的面时,你在它们之间留下足够的空间,以适应具有该半径的圆的象限(即,每个面的末端比它们两个相交的地方短一个半径)。您将它们与遵循圆的象限的一组顶点坐标/法线连接起来——基本上,编写一个小循环,以均匀间隔的角度生成几十个(左右)点。每个点的角度将是法线,正弦/余弦将给出坐标。在拐角处(而不是边缘),您需要在球体上生成点,每个角对应一个球体的一个象限。
The easiest is probably to draw a model of a rounded cube in one of the many 3D modeling programs around (e.g., Maya, Blender), and load 27 instances of the model in your code. Learning to use a program like one of these isn't trivial though, so even though this is the general approach used in most games and such, for something this simple it may be kind of overkill -- it may take longer to figure out how to accomplish anything in the program, than it would have to do things a different way.
The obvious alternative would be to generate a the model in your code. The basic idea is fairly simple, though getting it all put together may be somewhat non-trivial. You start by picking the radius you want to use for the corners. When you generate your faces, you leave enough space between them to fit in a quadrant of a circle with that radius (i.e., each face ends one radius short of where they two would intersect). You connect them with a set of vertex coordinates/normals that follow a quadrant of a circle -- basically, write a small loop that generates a few dozen points (or so) at evenly spaced angles. The angle at each point will be the normal, and the sine/cosine will give the coordinates. At the corners (as opposed to the edges) you need to generate points on a sphere, with one quadrant of a sphere for each corner.