PDA

View Full Version : viewing problem, would like to use 1-100 and not 0.1-1

Andrew Davey
04-09-2004, 03:26 AM
Hi,

I have a probelm when drawing in 3d. For some reason when drawing a line from 1-100 it is massive but if i draw a line from 0-1 it is the size i expect.

How can i make it so that if i draw a line from 1-100 it draws as 0-1?

Cheers, this will make my life so much easier.

t0y
04-09-2004, 03:55 AM
If I understood your post correctly, you should play around with glTranslatef()

Try:
glTranslatef(0,0,-100);

just before your drawing code. The three parameters are a vector to move the "camera", and you should play around with the values to achieve the effect you want.

nexusone
04-09-2004, 04:43 AM
The size of the line will also depend on your ortho or perspective settings.

Let's say you have a ortho setting of 1 unit x 1 unit. Then a line from 0 to 1 would fill the screen.
But if you have a ortho setting of 100 units x 100 units then a line drawn from 0 to 100 would look the same.

I would look at your projection matrix settings first to try and correct this problem. Can you post how you are setting up your projection matrix?

Originally posted by Andrew Davey:
Hi,

I have a probelm when drawing in 3d. For some reason when drawing a line from 1-100 it is massive but if i draw a line from 0-1 it is the size i expect.

How can i make it so that if i draw a line from 1-100 it draws as 0-1?

Cheers, this will make my life so much easier.

Andrew Davey
04-09-2004, 05:25 AM
yes that i can, although i dont know what you need so i will give what i think you want:

//reset the current viewport
//viewport creates a scene that will draw stuff in
glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);

//enables and sets up perspective viewing for the simulation
//angle, ratio, z range
gluPerspective(45.0f,(GLfloat)w / (GLfloat)h,0.1f,150.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();n.b. ortho View? i havent set one up, not completely sure what it does.

nexusone
04-09-2004, 11:51 AM
You project matrix tell openGL how we view the scene, sort of like settings on a lense of a camera.

Ortho projection is like your looking down at a piece of paper. and everthing is draw to scale without adjustment for distance. So a if you where looking down at a cube without any rotation would look like a square. Also the x/y limits are the same for the any z distance.

Perspective projection adjust the object to give them a 3D depth. Under perspective the same cube would be able to see no only the top but the sides .
Under perspective projections your x/y limits change with the z axis. Where a line draw at z max maybe in view at x/y (100,100) but not in view at z min.

Are you changing the z value when you draw your line?

Also maybe that it is you need to be drawing in ortho mode to get the effect you want.

Originally posted by Andrew Davey:
yes that i can, although i dont know what you need so i will give what i think you want:

//reset the current viewport
//viewport creates a scene that will draw stuff in
glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);

//enables and sets up perspective viewing for the simulation
//angle, ratio, z range
gluPerspective(45.0f,(GLfloat)w / (GLfloat)h,0.1f,150.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();n.b. ortho View? i havent set one up, not completely sure what it does.

t0y
04-09-2004, 12:48 PM
Check nate robins' tutorials on
tutorials (http://www.xmission.com/~nate/tutors.html)

Specially the ones on projection and transformation.