Jump to content
  • Advertisement
Sign in to follow this  
jojygv

OpenGL How To Draw Converging Parallel Lines?

This topic is 4852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All Thanks in advance for your time. I am new to this forum and new to OpenGL programming. I am trying to draw a converging parallel line. Here is the code which writes the lines in windows environment: void drawOutline(void) { glBegin(GL_LINES); glVertex3f(-0.7f, -0.1f,0.9f); glVertex3f(-0.7f, -0.1f,-0.9f); glEnd(); glBegin(GL_LINES); glVertex3f(0.7f, -0.1f,0.9f); glVertex3f(0.7f, -0.1f,-0.9f); glEnd(); } Now as you can see this is a set of parallel lines along Z-axiz. Now how do I render these something like two rail lines (using projection)? Any help is appreciated. george

Share this post


Link to post
Share on other sites
Advertisement
I would just make the lines longer


void drawOutline(void)
{

glBegin(GL_LINES);
glVertex3f(-0.7f, -0.1f,1000.0f);
glVertex3f(-0.7f, -0.1f,-1000.0f);
glEnd();

glBegin(GL_LINES);
glVertex3f(0.7f, -0.1f,1000.0f);
glVertex3f(0.7f, -0.1f,-1000.0f);
glEnd();
}




I made them longer on both sides because I didn't know how you set your coordinate system was set up. And to set up the coordinate system you can do:


glMatrixMode(GL_PROJECTION);
gluPerspective(45,1.333,0.1,500);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,0, 0,0,1, 0,1,0);




The arguments for gluPerspective are the field of view (in degrees), the aspect ratio (adjust this with screen resolution), and the near and far clipping planes. (Any closer than 0.1 units to the camera or further than 500m will be cut off.)

gluLookAt is the quick way to set up the view. The first three coordinates are the position of the camera, the next three are the direction that it's looking at (the positive z-axis) and the last three are the camera's up vector (positive y-axis in most cases, you would change this to roll the camera).

Share this post


Link to post
Share on other sites
Thanks for the post! Well I am a newbie and am trying things. I thought in wondows the maximum co-ordinate value is 1. Am i wrong?

Share this post


Link to post
Share on other sites
windows and opengl doesnt use the same "distance" when drawing...
in theory, drawing is only limited by the Far Clipping Plane in Opengl... but windows coordinates are within 0-1 I think...


Share this post


Link to post
Share on other sites
I want to thank "dyerseve" for helping me with the code which does what I wanted. It works! But i am not sure how it works. I have a question about the Code line :

gluPerspective(45,1.333,0.1,500);

Now from what I understand, the 3rd parameter is the "near" value and fourth is the "far" value. Also I think they both are values on the Z axis which increases away from the monitor plane. So a near and far values of 0.1 and 500 means that its an inverted cone (top towards the monitor). Am i right?

thanks in advance


Share this post


Link to post
Share on other sites
That's what would be known as the view frustrum. Also its more like a pyramid with the top lopped off. The base would be the far plane and the top would be the near plane.

Some images here:

http://astronomy.swin.edu.au/~pbourke/stereographics/HET409_2003/frustum.html


-=[ Megahertz ]=-

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!