我以前做过 OpenGL
,现在正在学习一些 DirectX11
。新数学库中的一件事是存在用于 vector 和矩阵的加载/存储方法(例如 http://msdn.microsoft.com/en-us/library/ee415635(v=vs.85).aspx )。
对我来说,这让我很奇怪,当我想使用它们时必须存储/加载每个 vector 和矩阵 - 很多笨重的代码 - 我想知道是否有任何好的、干净的替代加载/存储过程?
最佳答案
你可以看看simplemath如果有帮助的话。它现在是 DirectXTK 的一部分.
来自链接站点:
Why wrap DirectXMath?
DirectXMath provides highly optimized vector and matrix math functions, which take advantage of SSE SIMD intrinsics when compiled for x86/x64, or the ARM NEON instruction set when compiled for an ARM platform such as Windows RT or Windows Phone. The downside of being designed for efficient SIMD usage is that DirectXMath can be somewhat complicated to work with. Developers must be aware of correct type usage (understanding the difference between SIMD register types such as XMVECTOR vs. memory storage types such as XMFLOAT4), must take care to maintain correct alignment for SIMD heap allocations, and must carefully structure their code to avoid accessing individual components from a SIMD register. This complexity is necessary for optimal SIMD performance, but sometimes you just want to get stuff working without so much hassle!You should use SimpleMath if you are:
- Looking for a C++ math library with similar API to the C# XNA types
- Porting existing XNA code from C# to C++
- Wanting to optimize for programmer efficiency (simplicity, readability, development speed) at the expense of runtime efficiency
You should go straight to the underlying DirectXMath API if you:
- Want to create the fastest possible code
- Enjoy the lateral thinking needed to express algorithms in raw SIMD
关于c++ - 避免使用 DirectXMath XMStore/load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24435848/