Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to give a 2D structure 3D depth
    primarykey
    data
    text
    <p>I am begging to learn OpenGL as part of a molecular modeling project, and currently I am trying to render 7 helices that will be placed spatially close to each other and will move, tilt and interact with each other in certain ways. My question is how to give the 2D scene 3-Dimensional depth so that the geometric structures look like true helices in three dimensions? </p> <p>I have tried playing around with projection matrices (gulPerspective, glFrustum) without much luck, as well as using the glDepthRange function.</p> <p>I include my code for rendering the helices, but for simplicity I insert the code for rendering one helix (the other 6 helices are exactly the same except for their translation matrix and the color function parameters) and for reshaping when mapping from object coordinates to clip coordinates: </p> <p>Any help would be much appreciated. </p> <pre><code>void init() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black background glLineWidth(8.0); } /* CALLED TO DRAW THE HELICES */ void RenderHelix() { GLfloat x,y,z; GLfloat c = 2.5f; //helical pitch GLfloat theta; //constant angle between tangent and x-axis GLfloat r = 4.5f; //radius //GLint i = 1; //loop through code to render 7 helices glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* GREEN HELIX */ glBegin(GL_LINE_STRIP); glColor3f(0.0, 1.0, 0.0); for(theta = 0; theta &lt;= 360; ++theta) { x = r*(cos(theta)); y = r*(sin(theta)); z = c*theta; glVertex3f(x,y,z); } glEnd(); glLoadIdentity(); glScalef(1.0,1.0,12.0); glTranslatef(50.0, 100.0, 0.0); //Move Position glRotatef(90.0, 0.0, 0.0, 0.0); /* Other 6 helices .... */ glFlush(); glutSwapBuffers(); } void Reshape(GLint w, GLint h) { if(h==0) h=1; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat aspectratio = (GLfloat)w/(GLfloat)h; if(w&lt;=h) glOrtho(-100,100,-100/aspectratio,100/aspectratio, -100,310); else glOrtho(-100*aspectratio,100*aspectratio,-100,100,-100,310); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload