Hi,
I came across a fool proof method for setting up gluLookAt but it has not worked for me. ( OpenGL FAQ / 8 Viewing and Camera Transforms, and Using gluLookAt()):
It suggested that all the data should fit inside a circle.
GLdouble left = c.x - diam;
GLdouble right = c.x + diam;
GLdouble bottom c.y - diam;
GLdouble top = c.y + diam;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(left, right, bottom, top, zNear, zFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLdouble aspect = (GLdouble) windowWidth / windowHeight;
if ( aspect < 1.0 ) { // window taller than wide
bottom /= aspect;
top /= aspect;
} else {
left *= aspect;
right *= aspect;
}
The above code should position the objects in your scene appropriately. If you intend to manipulate (i.e. rotate, etc.), you need to add a viewing transform to it.
A typical viewing transform will go on the ModelView matrix and might look like this:
GluLookAt (0., 0., 2.*diam,
c.x, c.y, c.z,
0.0, 1.0, 0.0);
Is it because I am getting the coordinates of a mapping system confused with the coordinates of the graphics system confused? Any help gratefully appreciated.
MacSam
//Circle() returns the centre of the circle and the radius.
//123
cirCentre = Circle(
e_3dMin,//1
n_3dMin,
e_3dMin,//2
n_3dMax,
e_3dMax,//3
n_3dMax);
//check 4 is it inside or outside of the circle
dRadius = sqrt((cirCentre.dEast - e_3dMax ) * (cirCentre.dEast - e_3dMax ) + (cirCentre.dNorth - n_3dMin ) * (cirCentre.dNorth - n_3dMin )) ;
if( dRadius > cirCentre.dRadiusSq )
{
//124
cirCentre = Circle(
e_3dMin,//1
n_3dMin,
e_3dMin,//2
n_3dMax,
e_3dMax,//4
n_3dMin
);
//check 3
dRadius = sqrt((cirCentre.dEast - e_3dMax ) * (cirCentre.dEast - e_3dMax ) + (cirCentre.dNorth - n_3dMax ) * (cirCentre.dNorth - n_3dMax ));
if( dRadius > cirCentre.dRadiusSq )
{
//2 3 4
cirCentre = Circle(
e_3dMin,//2
n_3dMax,
e_3dMax,//3
n_3dMax,
e_3dMax,//4
n_3dMin
);
//check 1
dRadius = sqrt((cirCentre.dEast - e_3dMin ) * (cirCentre.dEast - e_3dMin ) + (cirCentre.dNorth - n_3dMin ) * (cirCentre.dNorth - n_3dMin ));
if( dRadius > cirCentre.dRadiusSq )
{
//3 4 1
cirCentre = Circle(
e_3dMax,//3
n_3dMax,
e_3dMax,//4
n_3dMin,
e_3dMin,//1
n_3dMin
);
//check 2
dRadius = sqrt((cirCentre.dEast - e_3dMin ) * (cirCentre.dEast - e_3dMin ) + (cirCentre.dNorth - n_3dMax ) * (cirCentre.dNorth - n_3dMax ));
if( dRadius > cirCentre.dRadiusSq )
{
//error
MessageBox (hwndThrd, "Error centering model",
"qwerty", MB_ICONASTERISK );
}
}
}
}
gldLeft = (GLdouble)(cirCentre.dEast - 2.*(cirCentre.dRadiusSq ));
gldRight = (GLdouble)(cirCentre.dEast + 2.*(cirCentre.dRadiusSq ));
gldTop = (GLdouble)(cirCentre.dNorth + 2.*(cirCentre.dRadiusSq ));
gldBottom = (GLdouble)(cirCentre.dNorth - 2.*(cirCentre.dRadiusSq ));
glFar = (GLdouble)cirCentre.dRadiusSq;
if( gldAspect < 1.0 )
{
gldBottom /= gldAspect;
gldTop /= gldAspect;
}
else
{
gldLeft *= gldAspect;
gldRight *= gldAspect;
}
glScaled( 1.0, 1.0, 1.0 );
glOrtho( (GLdouble)gldLeft, (GLdouble)gldRight, (GLdouble)gldTop, (GLdouble)gldBottom, -4.* glFar, 4.*glFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,4.*glFar, 0.0, cirCentre.dEast, cirCentre.dNorth, 0.0, 0.0, 0.0, -1.0);