Convert.ToDecimal gives different results when loading DirectX / Direct3D

I am loading data from a MySQL database into a C # .NET application. The data is stored in the database as DBType.Double, but for use in my application I use Decimal with Convert.ToDecimal (). The data is the positional data used when shooting, and can be used to display a 3D model in the Direct3D window.

When the Direct3D window and therefore the Direct3D DLL do not load, the conversion works fine, so values โ€‹โ€‹like 1769301.6485186936, 5880300.8152837148 stored in the database are loaded as 1769301.64851869, 5880300.81528371. However, if I downloaded the Direct3D module, then the conversion leads to the same values โ€‹โ€‹that are converted to 1769301.7112576, 5880300.79401984.

The base code is as follows: a vertex is a class / structure of three decimal values, X, Y and Z.

List<vertex> positions = new List<vertex>(); using (MySqlCommand cmd = new MySqlCommand("SELECT x, y, z FROM positionTable;", conn)) { MySqlDataReader dr = cmd.ExecuteReader(); try { while (dr.Read()) { vertex position = new vertex(); position.X = Convert.ToDecimal(dr[0]); position.Y = Convert.ToDecimal(dr[1]); position.Z = Convert.ToDecimal(dr[2]); positions.Add(position); } } } 
+6
source share
1 answer

When creating a Direct3D device, you must specify D3DCREATE_FPU_PRESERVE in D3DCREATE . Without this, DirectX (9) will switch the stream to use single-precision floating-point operations, which will affect numerical calculations even in your managed code.

+5
source

Source: https://habr.com/ru/post/912887/


All Articles