PDA

View Full Version : glortho ?!



gunsboy
07-19-2002, 08:27 AM
Following is the a portion of my code ..
The size of the view port is 500, 500 ..

I'm trying to center the image on the viewport ..

I have not been able to see the image .. am I doin something wrong ?! Could someone help please ?

//------------------------------------>

double world_xmin, world_xmax, world_ymin, world_ymax;
double range, avg;

double world_zmin = -20.;
double world_zmax = +10.;


double xmin = 57.1044016670;
double xmax = 57.1047319402;
double ymin = 1.9807138864;
double ymax = 1.9809711113;
double zmin = 88.47;
double zmax = 89.28;

double world_ratio;
double screen_ratio;


void GLView::initializeGL()
{
qglClearColor( black ); // Let OpenGL clear to black
object = makeObject(); // Generate an OpenGL display list
glShadeModel( GL_FLAT );
}

void GLView::resizeGL( int w, int h )
{
world_ratio = (xmax - xmin)/(ymax-ymin);
screen_ratio = (float) w /(float) h;

// Modify the world coordinates so they fill as much of the viewport
// as possible and so that a square in world coordinates will remain
// a square in the viewport.
if ( world_ratio >= screen_ratio )
{
// The world x size will match the viewport x size. Scale y accordingly.
range = (xmax - xmin) / screen_ratio ;
avg = (ymin+ymax)*.5;
world_xmin = xmin;
world_xmax = xmax;
world_ymin = (avg - range*.5);
world_ymax = (avg + range*.5);
}
else
{
// The world y size will match the viewport y size. Scale x accordingly.
range = (ymax - ymin) * screen_ratio ;
avg = ( xmin + xmax)*.5;
world_xmin = (avg - .5*range);
world_xmax = (avg + .5*range);
world_ymin = ymin;
world_ymax = ymax;
}

glViewport( 0, 0, (GLint)w, (GLint)h );
glMatrixMode( GL_PROJECTION );

// Tell OPENGL what the world coordinates are in the viewport
glOrtho((GLdouble)world_xmin,(GLdouble)world_xmax,
(GLdouble)world_ymin,(GLdouble)world_ymax,
(GLdouble)1., (GLdouble)(zmax-zmin+1.));

glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
}

void GLView: http://www.opengl.org/discussion_boards/ubb/tongue.gifaintGL()
{
glClear( GL_COLOR_BUFFER_BIT );

glPointSize(1.0);
glLoadIdentity();

// transform();

double cx = .5*(world_xmin + world_xmax);
double cy = .5*(world_ymin + world_ymax) ;
double cz = .5*(world_zmin + world_zmax) ;

gluLookAt( 0.,0., world_zmax+1., 0.,0., 0., 0., 1., 0. );

glCallList( object );
}


GLuint GLView::makeObject()
{
input.open();

glLoadIdentity();
glMatrixMode( GL_MODELVIEW );

double x,y,z;

GLuint list;
list = glGenLists( 1 );

glNewList( list, GL_COMPILE );
qglColor( white ); // Shorthand for glColor3f or glIndex
glBegin( GL_POINTS );
for (int i = 0; i < input.getNumRecords(); i++)
{
x = (double) input.x[i];
y = (double) input.y[i];
z = (double) input.z[i];
glVertex3d( x, y, z );
input.nextRecord();
}
glEnd();
glEndList();
return list;
}

chennes
07-22-2002, 03:39 AM
You are calling glOrtho to set up your view, and are immediately destroying it with your call to glLoadIdentity - reverse the order of your calls and see what you get.

Chris