Note that there are some explanatory texts on larger screens.

plurals
  1. POGiving 2D structures 3D depth
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/4947733/how-to-give-a-2d-structure-3d-depth">How to give a 2D structure 3D depth </a> </p> </blockquote> <p>Hello everyone, </p> <p>I posted this same question yesterday. I would like to have uploaded images showing my program output but due to spamming protection I am informed I need 10 reputation "points". I could send images of my output under different projection matrices to anyone willing. </p> <p>I am beginning to learn OpenGL as part of a molecular modeling project, and currently I am trying to render 7 helices that will be arranged spatially close to each other and will move, tilt, rotate and interact with each other in certain ways.</p> <p>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 (gluPerspective, glFrustum) without much luck, as well as using the glDepthRange function. As I understand from textbook/website references, when rendering a 3D scene it is appropriate to use a (perspective) projection matrix that has a vanishing point (either gluPerspective or glFrustum) to create the illusion of 3 dimensions on a 2D surface (the screen)</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) as well as the reshape handler. </p> <p>This is the output ![enter image description here][1] I get when I run my program with an orthographic projection (glOrtho) and it looks as a 2D projection of helices (curved lines drawn in three dimensions). This is my output (![enter image description here][2]) when I use a perspective projection (glFrustum in my case). It does not appear as if I am looking at my helices in 3D!! </p> <p>Perhaps the glFrustum parameters are wrong? </p> <pre><code>//GLOBALS GLfloat x, y, z; GLfloat c = 1.5f; //helical pitch GLfloat theta; //constant angle between tangent and x-axis thetarad = theta/(Pi/180.0); //angle converted from degrees to radians GLfloat r = 7.0f; //radius glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); /* enable depth testing */ glDepthFunc(GL_LESS); /* make sure the right depth function is used */ /*CALLED TO DRAW HELICES*/ void RenderHelix() { /**** WHITE HELIX ****/ glColor3f(1.0,1.0,1.0); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(-30.f, 100.f, 0.f); //Move Position glRotatef(90.0, 0.0, 0.0, 0.0); glBegin(GL_LINE_STRIP); for(theta = 0; theta &lt;= 360; ++theta) { /* Also can use: for(theta = 0; theta &lt;= 2*Pi; ++rad) */ x = r*(cosf(theta)); y = r*(sinf(theta)); z = c*theta; glVertex3f(x,y,z); } glEnd(); glScalef(1.0,1.0,12.0); //Stretch or contract the helix glPopMatrix(); /* Code for Other 6 Helices */ ............. 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, -50.0,310.0); //glOrtho(-100,100,-100/aspectratio,100/aspectratio, 0.0001,1000000.0); //CLIPPING FAILSAFE TEST //gluPerspective(122.0,(GLfloat)w/(GLfloat)h,10.0,50.0); glFrustum(-10.f,10.f, -100.f/aspectratio, 100.f/aspectratio, 1.0f, 15.0f); else //glOrtho(-100*aspectratio,100*aspectratio,-100,100,-50.0,310.0); //glOrtho(-100*aspectratio,100*aspectratio,-100,100,0.0001,1000000.0); //CLIPPING FAILSAFE TEST //gluPerspective(122.0,(GLfloat)w/(GLfloat)h,10.0,50.0); glFrustum(-10.f*aspectratio,10.f*aspectratio,-10.f,10.f, 1.0f,15.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); </code></pre> <p>}</p>
    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.
    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