Games for Windows and the DirectX SDK blog

Technical tips, tricks, and news about game development for Microsoft platforms including desktop, Xbox, and UWP

Project maintained by walbourn Hosted on GitHub Pages — Theme by mattgraham
Home | Posts by Tag | Posts by Month

XNA Math Version 2.05 - Smoothing the transition to DirectXMath

directxmath, xnamath

Originally posted to Chuck Walbourn's Blog on MSDN,

The July 2012 release of the Xbox 360 XDK includes a new version of XNA Math, version 2.05. We are making it available here for Windows developers. The update is subject to the same EULA as the DirectX SDK (June 2010) release MIT license.

What’s New

XNA Math version 2.05 includes:

  • Template forms have been added for XMVectorSwizzle, XMVectorPermute, XMVectorShiftLeft, XMVectorRotateLeft, XMVectorRotateRight, and XMVectorInsert.
  • The XM_STRICT_XMMATRIX compilation define has been added for opaque XMMATRIX.
  • Stream stride and count arguments have been changed to size_t.
  • The pDeterminant parameter of XMMatrixInverse is now optional.
  • Additional operator= overloads for XMBYTEN4, XMBYTE4, XMUBYTEN4, and XMUBYTE4 types are now available.

See XNA Math version 2.04 for details on what changed previously compared to XNA Math version 2.03 in the DirectX SDK (June 2010) release.

Why update XNA Math?

The DirectXMath library that ships as part of the Windows 8.0 SDK and Visual Studio 2012 RC is the recommended latest version of “XNA Math”. You can think of it as “XNAMath version 3.x”. It is very similar although it does have a number of ‘breaking’ changes (there’s a migration guide as well), requires Visual Studio 2010 or later, and is not available for the Xbox 360.

The primary purpose for the XNA Math version 2.05 update is for developers who need to maintain compatibility with the Xbox 360 version in the XDK or VS 2008, but want to prepare for migration to DirectXMath or support compiling with either math library.

XNAMath / DirectXMath Portability Recommendations

For an example of how to use this, see DirectXTex which builds with either DirectXMath or using the USE_XNAMATH define with XNA Math version 2.05. Here are some guidelines for achieving this:

  • Set preprocessor defines XM_STRICT_VECTOR4 and XM_STRICT_MATRIX in your build to ensure you are using XMVECTOR and XMMATRIX as opaque types.
  • Where possible, prefer the template forms to function forms. Note that for template forms, you should use simple indices (0-7) rather than the XM_PERMUTE_? values which have different definitions in the two library versions or XM_SWIZZLE_? which is not defined for XNA Math.
  • Make use of typedef or using namespace statements to cope with the lack of namespaces in XNA Math

Note: DirectXMath is now hosted on GitHub.