Co-ordinates - Newbie

In OpenGL when a window s created, the window co-ordiantes are given in the order of (640, 480) etc… But, when i define an object at a position say, (20, 20), the object is placed way outside my viewport.

i have used the following code…


This places the lines starting at the origin and until 25 units out…

How can i gett his whole thing to fit into my viewport?


the viewPort is only the portion of the window that is going to be used, it doesn’t say anything about the axis coordinates you use and how the coordinates will be mapped to the screen. What does this it is the projection Matrix and the origin will be the middle of the viewport if no transformations are applied.
for that you use glFrustum or gluPerspective.

To set my view frustum this how I do it:

glfrustum(left, right, top, bottom, near, far)

the frustum that I will create will be symetrical :

I say that I want an ojbect of heigth Y to cover all the screen in the y direction if it is at z unit from the viewpoint.

so we have top = y/2(symetrical)
and we have near = z;

You can do the same thing for the right value or you can just do

right = top *aspect ; where aspect is the the ratio of width/heigth of the window.

They both can give realistic projection unless the ratio is very huge or very small.

and then

bottom = -top;
left = -right;
//far is whatever view limit you want
//far and near must never be =<0
//the call

so for your problem the only thing you have to is set how big you want your object for a distance and create the frustum like I told you.

It sometimes easier if you change unit to a real unit(cm, m), it gives you a better understanding of the proportions.

Oh yeah, there is something else, if you create a point with a zero z value, well it won’t be seen because it outside the view volume. You have to put it in your view volume.

if you do absolutly no transformation before rendering, the view point is on the x/y plane with the negative z axis going away from you.

so just do

gltranslatef(0.0, 0.0, -5.0)
//draw object

and will now be in the view volume at five unit from z = 0.

have fun.

[This message has been edited by Gorg (edited 02-29-2000).]

[This message has been edited by Gorg (edited 02-29-2000).]