Opengl对象挤出 [英] Opengl object extrusion

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

问题描述

我有一个在opengl中绘制的3d框,有人可以解释如何在opengl中挤出对象吗?

I've got a 3d box drawn in opengl, can someone explain how to extrude objects in opengl? do i just translate further back in the z axis for each box?

推荐答案

这种方法可以工作,但你必须做一些计算每个步骤需要翻译的数量。我建议以更智能的方式生成挤压几何。

That approach could work, but you have to do some calculations on how much to translate for each step. I'd recommend generating the extruded geometry in a smarter way, though.

例如,您不应为中间的框绘制盒盖(地板和天花板)。

For example, you shouldn't draw the box caps (floor and ceiling) for in-between boxes. You also have to make sure the sides touch perfectly or you will get artifacts.

我建议使用路径来确定每组顶点的平面。路径应由一系列点和每个点的方向矢量组成,确定围绕方向矢量旋转多少。这样,你可以非常容易地计算4个环顶点,只需使用基本的向量数学。

I recommend using a path to determine the planes where each set of vertices goes. The path should consist of a series of points and an orientation vector for each point, that determines how much to rotate around the direction vector. With that, you can calculate the 4 ring vertices very easily, just using basic vector math.

因此,例如,你从cap [(0.5,0.5, 0),( - 0.5,0.5,0),( - 0.5,-0.5,0),(0.5,-0.5,0)]并沿着路径移动(第一个是中心点, 0,0,0),(1,0,0)],[(0,5,10),(1,1,0)],[(10,5,12),(0,1,0) ]

So, for example, you start with the cap [(0.5,0.5,0),(-0.5,0.5,0),(-0.5,-0.5,0),(0.5,-0.5,0)] and move it along the path (first is center point, second is right vector) [(0,0,0),(1,0,0)],[(0,5,10),(1,1,0)],[(10,5,12),(0,1,0)]

现在,首先计算所有三个方向向量。正常是当前点和下一点之间的差,因此(0,5,10) - (0,0,0)=(0,5,10)。右向量必须投影到由法线定义的平面上,因此我们首先使用交叉乘积计算向量向量:(0,5,10)x(1,0,0)=(0,10,-5) 。作为最后一步,我们计算投影右向量,它是正常和向上之间的交叉乘积:(0,5,10)x(-2,4,-2)=(-125,0,0)。所有三个向量必须被归一化,然后,如果你把它们并排,你将得到一个很好的转换矩阵,你应用于帽向量,产生当前步骤的4个顶点:

Now, you first calculate all three orientation vectors. The normal is the difference between the current and next point, so (0,5,10) - (0,0,0) = (0,5,10). The right vector must be projected onto the plane defined by the normal, so we calculate the up vector first using the cross product: (0,5,10) x (1,0,0) = (0,10,-5). And as a last step, we calculate the projected right vector, which is the cross product between normal and up: (0,5,10) x (-2,4,-2) = (-125,0,0). All three vectors must be normalized then, and if you put them side by side, you will get a nice transformation matrix that you apply to the cap vectors, yielding the 4 vertices for the current step:


|-1  0        0       |   |0.5|   |-0.5     |
| 0  0.894427 0.447214| * |0.5| = | 0.447213| etc.
| 0 -0.447214 0.894427|   |0  |   | 0.223607|

(我可能已经弄乱了标志,你可能需要交换交叉乘积因子才能得到正确的结果)

(I've probably messed up with the signs a bit, you might have to swap the cross product factors to get the right results)

然后对路径上的每个步骤重复相同的过程,每次绘制4个环形图。

Then you repeat the same procedure for each step on the path and draw the 4 ring quads each time.

这篇关于Opengl对象挤出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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