Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: viewing problem, would like to use 1-100 and not 0.1-1

  1. #1
    Intern Contributor
    Join Date
    Mar 2004
    Location
    UK, Portsmouth
    Posts
    71

    viewing problem, would like to use 1-100 and not 0.1-1

    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.

  2. #2
    Intern Contributor
    Join Date
    Mar 2002
    Location
    Figueira da Foz, Portugal
    Posts
    84

    Re: viewing problem, would like to use 1-100 and not 0.1-1

    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.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: viewing problem, would like to use 1-100 and not 0.1-1

    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.

  4. #4
    Intern Contributor
    Join Date
    Mar 2004
    Location
    UK, Portsmouth
    Posts
    71

    Re: viewing problem, would like to use 1-100 and not 0.1-1

    yes that i can, although i dont know what you need so i will give what i think you want:

    Code :
    	//reset the current viewport
    	//viewport creates a scene that will draw stuff in
    	glViewport(0,0,w,h);
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
     
    	//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.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: viewing problem, would like to use 1-100 and not 0.1-1

    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:

    Code :
    	//reset the current viewport
    	//viewport creates a scene that will draw stuff in
    	glViewport(0,0,w,h);
     
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
     
    	//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.

  6. #6
    Intern Contributor
    Join Date
    Mar 2002
    Location
    Figueira da Foz, Portugal
    Posts
    84

    Re: viewing problem, would like to use 1-100 and not 0.1-1

    Check nate robins' tutorials on
    tutorials

    Specially the ones on projection and transformation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •