XNAMath and double's in the constant buffer

Started by
1 comment, last by MJP 11 years, 3 months ago

Hi everyone,

XNAMath has a lot of useful structures for loading data into the mapped constant buffers. Like casting the appropriate piece of memory the XMFLOAT4A* and then assigning to it does the job. What I cannot find is the data structures that allow me to do the same for double4, double4x4 and similar entries in constant buffers. What is the best way to do that?

Advertisement

I don't know the reason why, but from XNA documentation I've read, floats are faster than doubles. but doubles have better accuracy. Not as in number of digits, but as in valid data. For instance, 1-1 in a double = 0. but 1-1 as a float equals something more like 0.000000000000017. For games, this gap was not as big of a deal as it would be in say scientific application physics engines or financial applications.

You could create your own Double classes if you really need to, but what I recommend, is to reproduce any math functions you need to use floats instead of doubles.

Since XNA relies on Floats at a lower level, you cannot get around using floats. Even if you store your data as doubles and work with it as such, you still have to recast to floats prior to passing data into XNA's framework. most common math functions are already duplicated in xna vectors/matrixes and the MathHelper class.

If you are attaching a physics engine or something else that rellies on doubles, and it is not convenient, you will need to convert them with tools of your own to tie it into XNA.

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

XNAMath/DirectXMath don't have any support for double-precision math, and don't have an structures that use doubles internally. If you want to use doubles you'll need to write your own functions and/or structures for converting from float to double. It should be pretty simple to make a "double4" and "double4x4" C++ struct that contains doubles and has a constructor that takes XMFLOAT4/XMFLOAT4x4/XMVECTOR/XMMATRIX and assigns the values to its members.

This topic is closed to new replies.

Advertisement