获得圆形opengl立方体的最简单方法是什么

发布于 2024-09-18 14:49:18 字数 433 浏览 4 评论 0 原文

始终在 Java/Opengl 和 lwjgl 中的魔方应用程序的上下文中,我想改进我的绘图 (http://manuelselva.files.wordpress.com/2010/09/cube.gif),以便 27 个小立方体中的每一个都有圆角边缘?我最终想要达到的效果与维基百科立方体图片相同: http://fr.wikipedia.org/wiki/Fichier:Rubik%27s_cube.svg

最简单的解决方案是什么?

Always in the context of a Rubik's cube app in Java/Opengl with lwjgl, i want to improve my drawing (http://manuelselva.files.wordpress.com/2010/09/cube.gif) in order to have rounded edges for each one of the 27 small cube ? What i would like to acheive at the end is the same as the wikipedia cube picture: http://fr.wikipedia.org/wiki/Fichier:Rubik%27s_cube.svg

What is the easiest solution to do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄离 2024-09-25 14:49:19

一些巧妙的纹理和精心制作的法线贴图大部分会在不编辑模型的情况下伪造出圆形的外观。最终渲染将被着色,就好像各个边都是圆形的一样。

不幸的是,通过这种方法,当从侧面观察时,这种错觉就会崩溃。

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.

梦毁影碎の 2024-09-25 14:49:19

您还可以使用基本立方体并实现细分算法,使每次迭代使用的顶点数量加倍。然后创建从立方体中心到每个顶点的向量。如果对顶点进行标准化,您将得到一个球体(介于:这是最简单的球体生成算法之一)。但如果你只改变角向量的长度,你将得到一个圆角立方体。

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.

王权女流氓 2024-09-25 14:49:18

最简单的可能是在众多 3D 建模程序之一中绘制圆角立方体的模型(例如 MayaBlender),然后加载您的代码中有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文