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. 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).
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 ins开发者_如何学Gotead of rendering them each time separately for the 7 different colors? (Each helix consists of 36,000 vertices and I am concerned that the arrays might get large enough to cause serious performance issues?)
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)
/*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? (Each helix consists of 36,000 vertices and I am concerned that the arrays might get large enough to cause serious performance issues?
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. Using vertex arrays will give you a 100× performance gain easily, just because you're not recreating the data each and every call.
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.
If you want to flex the helix, I'd do this using skeletal skinning.
精彩评论