PDA

View Full Version : Incorrect displaying of Polyline!



HanWu
06-24-2008, 08:30 AM
I have a rectangle(width == height) which was located in a very far place from origin. When I perform the zoom extend(a sequence of transformation ) I am able to project the rectangle to the center of the screen but the display of rectangle is awful(the width and the height of the rectangle is different when display in the screen). For example:
void AddRectangle(){
Point3DList temPList = new Point3DList();
temPList.Add(new Point3D(-10, -10, 0));
temPList.Add(new Point3D(10, -10, 0));
temPList.Add(new Point3D(10, 10, 0));
temPList.Add(new Point3D(-10, 10, 0));
sdPolyline poliline = AddPolyline(temPList);
// move the rectangle to very far from the origin.
poliline.Move(new Point3D(-71000000, 12000000, 0));
}

internal virtual void orthographic(int width,int height)
{
if (width <= height)
Gl.glOrtho(-tmpUser.OrthoSize, tmpUser.OrthoSize, -tmpUser.OrthoSize * (float) height / (float) width,
tmpUser.OrthoSize * (float) height / (float) width, -tmpUser.OrthoSize*DEPTH, tmpUser.OrthoSize*DEPTH);
else
Gl.glOrtho(-tmpUser.OrthoSize * (float) width / (float) height,
(tmpUser.OrthoSize)* (float) width / (float) height,-tmpUser.OrthoSize,tmpUser.OrthoSize, -tmpUser.OrthoSize*DEPTH, tmpUser.OrthoSize*DEPTH);
}

void RenderScene(){
orthographic(view.width,view.height);
Gl.glMatrixMode(Gl.GL_MODELVIEW );
Gl.glLoadIdentity();
// The final transformation matrix.
Gl.glMultMatrixd(view.object16form);
}

If you move the rectangle back to the origin then the problem will disappear. Can anyone explain about this fenomena and any solution on this problem? Your help will be appreciated. Thanks.

tirsac
06-24-2008, 03:45 PM
It appears that you have a precision problem. Even if you're using doubles for your Point3D (this is unclear), current OpenGL implementations use 32 bit floating point values for vertex positions. The farther you move your points, the less precise they will be.

Solution: Stop moving your points so far.

If you have widely separated items, use different local coordinate systems for each (stored using double precision), transform your view location (again, double precision) and other models (if desired) into the closest local coordinate system and draw your model from there. Your precision loss will then be mostly in the far away objects where it will be less noticeable.

HanWu
06-25-2008, 05:45 AM
Can you explain a little bit detail about the local coordinate systems? I am not clear with this concept. Pseudocode is most welcome. Thanks
It appears that you have a precision problem. Even if you're using doubles for your Point3D (this is unclear), current OpenGL implementations use 32 bit floating point values for vertex positions. The farther you move your points, the less precise they will be.

Solution: Stop moving your points so far.

If you have widely separated items, use different local coordinate systems for each (stored using double precision), transform your view location (again, double precision) and other models (if desired) into the closest local coordinate system and draw your model from there. Your precision loss will then be mostly in the far away objects where it will be less noticeable.

Can you explain a little bit detail about the local coordinate systems? I am not clear with this concept. Pseudocode is most welcome. Thanks

tirsac
06-25-2008, 03:41 PM
In your case you only need to be concerned with storing the position in higher precision. Instead of moving the polyline by adding some value to each of the points, store the position of the polyline in addition to the coordinates. When it comes time to draw the polyline, find the relative position between the eye and the polyline and call glTranslate with that value.