Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphics GDI+ / Direct2D and world size

I am porting a legacy CAD app to .NET. Its graphics requirements aren't very complex and GDI+ with some optimizations has good performance as long as you don't do any fancy things. However I'll support Direct2D too as it offers better experience and performance.

My problem is that old app supported Mercator coordinates and they simply don't fit within float so application crashes and GDI+ doesn't go well with extreme translation transforms. I see that Direct2D uses floats too.

So should I implement custom matrix for this, in order to translate etc to screen coordinates? Is there any other solution?

like image 972
GorillaApe Avatar asked Oct 31 '22 16:10

GorillaApe


2 Answers

Maybe this library can help in your porting efforts:

https://github.com/NetTopologySuite/NetTopologySuite

It is a port of JTS (Java Topology Suite) which includes geometry/gis related functionality.

The GeoAPI.NET project (part of NetTopologySuite) provides a base geometry classes, coordinate systems and more.

Take a look a this Coordinate class where their fields X, Y and Z are double precision.:

https://github.com/NetTopologySuite/GeoAPI/blob/master/GeoAPI/Geometries/Coordinate.cs

like image 72
Eric Acevedo Avatar answered Nov 16 '22 13:11

Eric Acevedo


Both GDI+ and Direct2D use floats.

Graphics Cards that support doubles do exist but you can NOT use this through GDI+ or Direct2D

I see a couple of options to load to use GDI+/Direct2D depending on required speed and precision:

  1. Load the data using doubles and scale/convert to floats immediately after loading. This allows you to use all features of the of GDI+, Direct2D and any related libraries to manipulate the models (rotating, scaling, translation, ... ) The downside is that the model loses precision before the transformations.

  2. Load the data using doubles, do all manipulation using doubles and scale/convert to floats just before rendering. Downside: you need to find or write a library that uses doubles to manipulate the data and you can't use the GPU to the manipulations. Positive: a precision is kept longer and might be crucial for your data.

I would try option 1 first as it is easier (more standard graphics programming). Only when the precision proves to be insufficient I would try option 2.

I have no experience with using/programming double precision API's perhaps someone else will add that as an answer.

An interesting discussion on doubles/floats can be found here based on this discussion I strongly suggest you first try to find out whether you need double precision at all as in the end it will be rendered on the screen with single precision.

like image 28
Emond Avatar answered Nov 16 '22 14:11

Emond