Skip to main content
GameDev.net gamedev.net
🔒 Locked

How To Draw Converging Parallel Lines?

Started by jojygv Aug 4, 2005 at 6:51 PM 5 replies 4.5k views
Original Post
jojygv
jojygv
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
dyerseve
dyerseve
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).
jojygv
jojygv
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?
Rasmadrak
Rasmadrak
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...


"Game Maker For Life, probably never professional thou." =)
jojygv
jojygv
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


Megahertz
Megahertz
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 ]=-
-=[Megahertz]=-
jojygv
jojygv
thanks everyone who is trying to help me out here!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.