The only problem i was having was the amount of time required to do the normalization. I was unwilling to do computation on the normalized coordinates because there was a much higer occurence of floating point error in normalized form. So i had to normalize to display and unnormalize to work.
example coordinates
x = (654964.44, 750957.00)
y = (3587928.8, 3685371.5)
z = (49.919220, 147.53792)
I was having projection problems but have gotten things working here is code if anyone else as similar problems.
Camera positioning code.
void DisplayWindow::center_on_bounds()
{
if ( surface.bounds() == false )
{
surface.make_bounds();
}
Vector3d position;
double x_width = surface.x_max() - surface.x_min();
double y_width = surface.y_max() - surface.y_min();
double z_width = surface.z_max() - surface.z_min();
const double scale = 1.2071067811865475244008443621048; //(1 / ( 2 * tan(22.5 deg) )
if ( mode != Side )
{
// set the camera in the middle of the x y bounds of the surface
position = Vector3d( (surface.x_min() + surface.x_max()) / 2,
(surface.y_min() + surface.y_max() ) / 2,
surface.z_max() );
cam.set_position( position );
// set the camera to look down -z with y being up
cam.set_direction( Vector3d(0,0,-1), Vector3d(0,1,0) );
// find out how far back the camera needs to be to see the entire surface
// find the longer side
double l = (x_width > y_width) ? x_width : y_width;
// calculate how far to move the camera back it is current on z_max for the surface
double dist = l * scale;
cam.move_back(dist);
}
else
{
// set the camera looking at the side of the surface
position = Vector3d( (surface.x_min() + surface.x_max()) / 2,
surface.y_min(),
(surface.z_min() + surface.z_max() ) / 2);
cam.set_position( position );
// set the camera to look up y with z being up
cam.set_direction( Vector3d(0,1,0), Vector3d(0,0,1) );
// find out how far back the camera needs to be to see the entire surface
// find the longer side
double l = (x_width > z_width) ? x_width : z_width;
// calculate how far to move the camera back it is current on z_max for the surface
double dist = l * scale;
cam.move_back(dist);
}
// set up perspective matrix code
void DisplayWindow::update_perspective()
{
glViewport (0, 0, (GLsizei) w(), (GLsizei) h() );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (mode == Top )
{
double z = cam.get_position().get_z();
double front, back;
front = z - surface.z_max() - 5;
back = z - surface.z_min() + 5;
gluPerspective(45.0, (GLfloat) w() / (GLfloat) h() ,front , back);
}
else
{
double y = cam.get_position().get_z();
double front, back;
front = surface.y_min() - y - 5;
back = surface.y_max()- y + 5;
gluPerspective(45.0, (GLfloat) w() / (GLfloat) h() , front, back);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}