Converting DirectX SDK code to new Windows 8.1 SDK Code

自闭症网瘾萝莉.ら 提交于 2019-12-05 15:51:14

Should I be doing this at all, and / or is it the best way to do this?

Use XMVECTOR instead of XMFLOAT3 since most of the functions in DriectXMath use XMVECTOR. thus you can avoid the boring type cast and make your code clean.

I was able to use the + operator on D3DXVECTOR3, but now not XMFLOAT3? How do I add these together?

Again, use XMVECTOR instead of XMFLOAT3

XMVECTOR also has some disadvantage(I mean the code seems a little complicated sometimes). with D3DXVECTOR3, you can simply initialize a variable as D3DXVECTOR3 a(x, y, z, w) and get it's component as a.x, a.y, ... but XMVECTOR use a different way.

To initialize an XMVECTOR, use XMVectorSet function.

XMVECTOR lookAt = XMVectorSet(x, y, z, w);

To get component of an XMVECTOR, use the following functions.

  • XMVectorGetX
  • XMVectorGetY
  • XMVectorGetZ
  • XMVectorGetW

1. Should I?

Should I be doing this at all, and / or is it the best way to do this?

Generally speaking, you use Windows SDK to write your new code, but you don't have to convert any old code (yours or, especially, others). It`s just a waste of time. You can install DirectX SDK to be able to build it.

On the other hand, it is a good opportunity to learn a little more about DrectX and its infrastructure. For example, portng from D3DXMath to DirectXMath (previously XMMath), you will learn pros and cons of SSE-based math libraries, and it is a good place to begin to write your own.

2. How to?

If you really decided to do this hard work, then 90% of info you will find in a good article by Chuck Walbourn - MSFT: Living without D3DX. Another 9.9% you will figure out by yourself from documentation, and 0.1% more from looking at DirectXMath source code (it is a header library, all functions inlined and you cann freely learn them). You will, probably, also interested in another articles by that guy on MSDN.

3. operator+ problem

Instead of single D3DXVECTORn type (where n is a number of components), new math contains two types: XMFLOATn and XMVECTOR. Same for matrices: XMMATRIX and XMFLOATaXb (where a and b is a dimensions of matrix).

  • XMFLOAT folks are to be used to just store values. It is just a plain floats. No operators defined for them and no functions, except XMLoad*/XMStore* accept them.
  • XMVECTOR and XMMATRIX is a work horses: they used in all functions and also have overloaded operators (which is not recommended to use. Use XM* functions instead). They use supersonic speed SSE internals. But.. it is a hard to use it to store values. For example, you will have alignment problems if you make XMVECTOR class member.
  • So, basically, you store and moving around your values in XMFLOATs, but before any calculations, you transform them to XMVECTOR and XMMATRIX, using XMLoad* functions (as you've done with XMVector3TransformCoord()), and after calculations, you transform them back to XMFLOATs, using XMStore* functions. Or you can gain a little more profit, by aligning properly your classes and structs, so you can store XMVECTOR and XMMATRIX directly (probably, you will need aligned memory allocator).

Well, now you are ready to go. Happy porting! =)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!