<i id='VspUD'><tr id='VspUD'><dt id='VspUD'><q id='VspUD'><span id='VspUD'><b id='VspUD'><form id='VspUD'><ins id='VspUD'></ins><ul id='VspUD'></ul><sub id='VspUD'></sub></form><legend id='VspUD'></legend><bdo id='VspUD'><pre id='VspUD'><center id='VspUD'></center></pre></bdo></b><th id='VspUD'></th></span></q></dt></tr></i><div id='VspUD'><tfoot id='VspUD'></tfoot><dl id='VspUD'><fieldset id='VspUD'></fieldset></dl></div>

    • <bdo id='VspUD'></bdo><ul id='VspUD'></ul>

  1. <legend id='VspUD'><style id='VspUD'><dir id='VspUD'><q id='VspUD'></q></dir></style></legend>

      <small id='VspUD'></small><noframes id='VspUD'>

      <tfoot id='VspUD'></tfoot>

      Opengl 对象挤出

      时间:2023-09-17
    1. <small id='VLyLw'></small><noframes id='VLyLw'>

        <i id='VLyLw'><tr id='VLyLw'><dt id='VLyLw'><q id='VLyLw'><span id='VLyLw'><b id='VLyLw'><form id='VLyLw'><ins id='VLyLw'></ins><ul id='VLyLw'></ul><sub id='VLyLw'></sub></form><legend id='VLyLw'></legend><bdo id='VLyLw'><pre id='VLyLw'><center id='VLyLw'></center></pre></bdo></b><th id='VLyLw'></th></span></q></dt></tr></i><div id='VLyLw'><tfoot id='VLyLw'></tfoot><dl id='VLyLw'><fieldset id='VLyLw'></fieldset></dl></div>

          <tfoot id='VLyLw'></tfoot>

              <bdo id='VLyLw'></bdo><ul id='VLyLw'></ul>
              <legend id='VLyLw'><style id='VLyLw'><dir id='VLyLw'><q id='VLyLw'></q></dir></style></legend>
                  <tbody id='VLyLw'></tbody>
                本文介绍了Opengl 对象挤出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有一个用 opengl 绘制的 3d 框,有人能解释一下如何在 opengl 中挤出对象吗?对于每个框,我是否只是在 z 轴上进一步平移?

                解决方案

                这种方法可行,但您必须计算每一步要翻译多少.不过,我建议以更智能的方式生成挤压几何体.

                例如,您不应为中间的盒子绘制盒盖(地板和天花板).您还必须确保两侧完美接触,否则会出现伪影.

                我建议使用路径来确定每组顶点所在的平面.路径应该由一系列点和每个点的方向向量组成,这决定了围绕方向向量旋转多少.有了它,您可以非常轻松地计算 4 个环顶点,只需使用基本的向量数学即可.

                因此,例如,您从上限 [(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)]

                现在,您首先计算所有三个方向向量.法线是当前点和下一个点之间的差值,所以 (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 个顶点:

                <前>|-1 0 0 ||0.5||-0.5 ||0 0.894427 0.447214|* |0.5|= |0.447213|等等.|0 -0.447214 0.894427||0 ||0.223607|

                (我可能对符号有点搞砸了,你可能需要交换交叉乘积因子才能得到正确的结果)

                然后对路径上的每一步重复相同的过程,每次绘制 4 个环形四边形.

                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.

                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.

                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)]

                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)

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

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

                上一篇:单个 MFC 对话框上的 OpenGL 两种不同的 3d 渲染图片 下一篇:如何在 C++ 和 openGL 中将类方法作为另一个函数的

                相关文章

                最新文章

                <tfoot id='odRTo'></tfoot>

                  1. <i id='odRTo'><tr id='odRTo'><dt id='odRTo'><q id='odRTo'><span id='odRTo'><b id='odRTo'><form id='odRTo'><ins id='odRTo'></ins><ul id='odRTo'></ul><sub id='odRTo'></sub></form><legend id='odRTo'></legend><bdo id='odRTo'><pre id='odRTo'><center id='odRTo'></center></pre></bdo></b><th id='odRTo'></th></span></q></dt></tr></i><div id='odRTo'><tfoot id='odRTo'></tfoot><dl id='odRTo'><fieldset id='odRTo'></fieldset></dl></div>

                    <legend id='odRTo'><style id='odRTo'><dir id='odRTo'><q id='odRTo'></q></dir></style></legend>

                    <small id='odRTo'></small><noframes id='odRTo'>

                    • <bdo id='odRTo'></bdo><ul id='odRTo'></ul>