Jump to content

  • Log In with Google      Sign In   
  • Create Account

XNAMath and double's in the constant buffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 barsiwek   Members   -  Reputation: 114

Like
0Likes
Like

Posted 10 January 2013 - 04:48 AM

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?



Sponsor:

#2 Dan Violet Sagmiller   Members   -  Reputation: 897

Like
0Likes
Like

Posted 10 January 2013 - 09:27 AM

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.


Edited by hpdvs2, 10 January 2013 - 09:28 AM.

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."

My Game(s), Warp Wars is in early development and can be found here: http://blog.WarpWars.Net.


#3 MJP   Moderators   -  Reputation: 11846

Like
0Likes
Like

Posted 10 January 2013 - 04:11 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS