PDA

View Full Version : Problems displaying data with UTM coordinates



FireCat12
12-02-2004, 08:03 AM
Iím currently creating a model which uses data sets with UTM coordinates. Thus the x and y coordinate values are very large. I have been unable to get the models to display with any projection settings. I know the 3d bounding box for all objects in the world and set the projection so that the bounding box was with in the view volume but nothing is displayed. If I normalized all coordinates to fit within a 100x100x100 cube and set the view volume accordingly then the model is viewable. However this makes the distance between points so small that floating point error is a major problem. This requires the data to either be duplicated or converted between normalized and unnormalized continuously. In most cases the objects are too large for duplication to be practical so I must keep normalizing to display and unnormalizing to process. As a result most of my time is spent normalizing and unnormalizing data. Can anyone tell me how to get opengl to work with very large coordinate values?

I also tried to use a combination of glTranslate and glScale to mimic my normalization but that also yielded a black screen.

Normalization Code looks like this


for( unsigned long i = 0; i < object_data.size(); ++i)
{
object_data[i] -= offset_vect;
object_data[i] *= scale_vect;
}

mikael_aronsson
12-02-2004, 11:36 AM
Hi !

You say the values are big, but how big ?, most OpenGL hardware use float (32 bits) for floating point values could this is the problem (7 digits).

Also if you set the far clipping plane very far away you must be careful with the near clipping plane, if you make that too small you will just get crap.

Mikael

12-05-2004, 05:15 PM
I'm doing exactly the same thing with my aircraft flight track monitoring system. I have had no problems at all doing this. What are the extents of your coordinates? Are you using ortho or perspective? How have you set up your viewport? Some sample code would be good.

Steve

FireCat12
12-06-2004, 10:58 AM
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();
}

12-07-2004, 02:23 AM
From the code you posted, I can see that you are positioning your camera. The example coordinates you posted look like an excellent place to start your debugging. First thing I did to setup my viewing volume was to determine the coordinates of Sydney Airport which lie in UTM zone 56 South.

I drew the lines that represent the runways and determined where my Aerodrome Reference Point (ARP) is. I moved my camera there. Sounds simplistic, but I got my camera settings right and eliminated that as a possiblity.

It seems odd to me that your unnormalized world cannot be seen while your normalized world can. Try drawing those lines in first and then see if you can see them. If your viewing volume encompasses those coordinates and you still cannot see them then that would suggest you are having problems with your setup of the camera and viewing volume. Just as an example here is my setup code:


public void OnSize(int wWidth, int hHeight)
{
Width = wWidth; //copy to member variables
Height = hHeight;

//Make sure no divide by zero errors occur
If(Width == 0)
Width = 1;
If(Height == 0)
Height = 1;

glViewport( 0F, 0F, Width, Height);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();

gluPerspective(FOV/*60*/, Width / Height, Near_Plane, Far_Plane);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}I set my cam dist with gluLookAt to 10000 and it drew no problems.

Try reading the chapter on transformations in the redbook. As a troubleshooting measure, it suggests to set your near and far to really insane values. If you are still having problems then send me your source code if possible and I will attempt to help you through it. send to austcro at internode dot on dot net.

Steve

FireCat12
12-07-2004, 04:47 AM
I fixed it the posted code works. Thanks though