简体   繁体   English

定义和操纵具有特定旋转度的3D对象

[英]Defining and Manipulating a 3D Object with Specific Rotations

I have rendered a very rough model of a molecule that consists of 7 helices and would like to ask if there is anyway possible to allow the helices themselves to tilt (rotate) in certain ways so as to interact with one another. 我已经绘制了一个由7个螺旋组成的分子的非常粗糙的模型,并想问一问是否有可能允许螺旋自身以某些方式倾斜(旋转)以便彼此相互作用。 For clarity, I insert an image of my program output (although for an orthographic projection, so it appears as the projection of a 3D helix onto a 2D plane). 为了清楚起见,我插入了程序输出的图像(尽管是正交投影,所以它看起来像是3D螺旋在2D平面上的投影)。

在此处输入图片说明

I have included the code for rending a single helix (all others are the same). 我已经包含了用于租用单个螺旋的代码(所有其他螺旋都相同)。

Would it be useful to store the geometry of my objects in vertex arrays instead of rendering them each time separately for the 7 different colors? 将我的对象的几何形状存储在顶点数组中,而不是每次分别为7种不同的颜色进行渲染,是否有用? (Each helix consists of 36,000 vertices and I am concerned that the arrays might get large enough to cause serious performance issues?) (每个螺旋由36,000个顶点组成,我担心数组的大小可能会引起严重的性能问题吗?)

I understand the matrix stack is the data structure for performing multiple consecutive individual transformations on particular objects, but I not sure how exactly to specify so that an entire one of my helices can tilt? 我知道矩阵堆栈是用于在特定对象上执行多个连续的单独转换的数据结构,但是我不确定如何确切指定以便使我的整个螺旋都可以倾斜? (glRotatef does not actually tilt the helices for some reason) (由于某些原因,glRotatef实际上不会倾斜螺旋)

/*HELIX RENDERING*/

glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(0.0, 100.0, -5.0);  //Move Position
glRotatef(90.0, 0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);

for(theta = 0.0; theta <= 360.0; theta += 0.01) {   
    x = r*(cosf(theta));
    y = r*(sinf(theta));
    z = c*theta;
    glVertex3f(x,y,z);
    glColor3f(1.0, 1.0, 0.0);           
}

glEnd();
glPopMatrix(); 

Would it be useful to store the geometry of my objects in vertex arrays instead of rendering them each time separately for the 7 different colors? 将我的对象的几何形状存储在顶点数组中,而不是每次分别为7种不同的颜色进行渲染,是否有用? (Each helix consists of 36,000 vertices and I am concerned that the arrays might get large enough to cause serious performance issues? (每个螺旋包含36,000个顶点,我担心数组的大小可能会引起严重的性能问题?

Drawing geometry using vertex arrays always makes sense. 使用顶点数组绘制几何图形总是有意义的。 And in your case, the overhead caused by those 36k * (5 floating pointer operations + 2 function calls) will seriously affect your performance. 在您的情况下,由这些36k *(5个浮指针操作+ 2个函数调用)引起的开销将严重影响您的性能。 Using vertex arrays will give you a 100× performance gain easily, just because you're not recreating the data each and every call. 使用顶点数组将使您轻松获得100倍的性能提升,只是因为您不会在每次调用时都重新创建数据。

You may also be interested in not using lines, since you can't shade those in any useful way. 您可能还对不使用线条感兴趣,因为您无法以任何有用的方式为它们着色。 I'd render those helices by creating basic building blocks, created from ellipses extruded along the helical. 我会通过创建基本的构建块来渲染这些螺旋,这些基本的构建块是由沿螺旋线拉伸的椭圆形创建的。 One basic block for the intra helix and two caps. 一个基本块用于内螺旋和两个帽。 The chirality is easily changed by mirroring along one axis. 通过沿一个轴镜像可以很容易地改变手性。 With modern OpenGL implementations you can implement instancing on the intra-helix-element to further increase performance. 使用现代OpenGL实现,您可以在内部螺旋元素上实现实例化以进一步提高性能。

If you want to flex the helix, I'd do this using skeletal skinning. 如果您想弯曲螺旋线,我将使用骨骼蒙皮进行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM