将DirectX SDK代码转换为新的Windows 8.1 SDK代码 [英] Converting DirectX SDK code to new Windows 8.1 SDK Code

查看:144
本文介绍了将DirectX SDK代码转换为新的Windows 8.1 SDK代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在创建一个视频游戏+引擎。我发现在RasterTek上有关DirectX 11编程的一些非常令人惊奇的教程。不幸的是,他们使用的是折旧的DirectX SDK,而我正在将VS 2013与Windows SDK中包含的新DirectX SDK一起使用。



我正在将代码转换为使用Windows SDK ,但我在第4篇教程中遇到了一些问题(是的,我将转换所有49篇教程,并且可能还会有更多问题)



来自使用D3DXMath ,我被告知D3DXVECTOR3应该转换为XMFLOAT3。
然后我尝试在D3DXVec3TransformCoord中使用这些XMFLOAT3,该XMFLOAT3已转换为 XMVector3TransformCoord



示例:

  XMFLOAT3向上,位置,lookAt; 

//设置指向上方的向量。
up.x = 0.0f
up.y = 1.0f
up.z = 0.0f

//设置摄像机在世界上的位置。
position.x = m_positionX;
position.y = m_positionY;
position.z = m_positionZ;

//设置默认情况下相机所处的位置。
lookAt.x = 0.0f;
lookAt.y = 0.0f;
lookAt.z = 1.0f;

//通过旋转矩阵转换lookAt和up向量,以便视图在原点正确旋转。
XMVector3TransformCoord(lookAt,rotationMatrix);
XMVector3TransformCoord(up,rotationMatrix);

我收到一个错误:


IntelliSense:不存在从
DirectX :: XMFLOAT3到 DirectX :: XMVECTOR的合适的用户定义转换


我发现我可以使用 XMLoadFloat3

  XMVector3TransformCoord(XMLoadFloat3(& lookAt),rotationMatrix); 
XMVector3TransformCoord(XMLoadFloat3(& up),rotationMatrix);

我应该完全这样做,和/或这是最好的方法吗? / p>

这样做之后,我尝试:

  //将相机位置旋转到观看者的位置。 
lookAt =位置+ lookAt;

并得到错误:


IntelliSense:没有运算符 +与这些操作数匹配
操作数类型为:DirectX :: XMFLOAT3 + DirectX :: XMFLOAT3


我可以在D3DXVECTOR3上使用+运算符,但是现在不能使用XMFLOAT3了吗?如何将它们加在一起?

解决方案

1。我应该吗?


我应该这样做吗,并且/或者这是最好的方法吗? / p>

通常来说,您使用Windows SDK编写新代码,但不必转换任何旧代码(您也可以,特别是其他)。只是浪费时间。您可以安装DirectX SDK来构建它。



另一方面,这是一个学习DrectX及其基础结构的好机会。例如,从D3DXMath移植到DirectXMath(以前是XMMath),您将学习基于SSE的数学库的优缺点,这是一个开始编写自己的好地方。



2。



如果您真的决定做这项艰苦的工作,那么您将在Chuck Walbourn的一篇好文章-MSFT中找到90%的信息:
没有D3DX的生活
另外9.9%的资源您可以自己从
文档,并且从DirectXMath源代码(它是一个头文件库,所有函数都已内联,您无法自由学习它们)中获得0.1%的收益。
您可能还会对MSDN上的该人的另一篇文章感兴趣。



3。 operator + 问题



代替单个 D3DXVECTORn 类型(其中 n 是许多组件),新数学包含两种类型: XMFLOATn XMVECTOR 。矩阵相同: XMMATRIX XMFLOATaXb (其中 a b 是矩阵的维度。




  • XMFLOAT 人们只能用来存储值。它只是一个普通的花车。除了 XMLoad * / XMStore * 之外,没有为它们定义任何运算符和任何函数。

  • XMVECTOR XMMATRIX 十分有用:它们用于所有功能,并且具有重载运算符(不建议使用。请改用 XM * 函数)。他们使用超音速SSE内部构件。但是..很难用它来存储值。例如,如果您成为 XMVECTOR 类成员,则会遇到对齐问题。

  • 因此,基本上,您可以存储和移动值在 XMFLOAT s中,但是在进行任何计算之前,您将其转换为 XMVECTOR XMMATRIX ,使用 XMLoad * 函数(与使用 XMVector3TransformCoord()完成的功能一样)计算,您可以使用 XMStore * 函数将其转换回 XMFLOAT s。或者,您可以通过适当地调整 es和 struct s来获得更多利润,以便存储 XMVECTOR XMMATRIX 直接(可能需要对齐的内存分配器)。



好,现在您可以开始了。移植愉快! =)


I'm currently creating a Video Game + Engine. I found some really amazing tutorials on DirectX 11 programming at RasterTek. They unfortunately use the depreciated DirectX SDK, and I am using VS 2013 with the new DirectX SDK included in the Windows SDK.

I am converting the code to use the Windows SDK, but I've run into some problems on tutorial 4 (yes I will be converting all 49 tutorials, and there will probably be more issues)

From Working with D3DXMath, I am told that D3DXVECTOR3 should be converted to XMFLOAT3. I am then trying to use these XMFLOAT3 in D3DXVec3TransformCoord, which has been converted to XMVector3TransformCoord.

Example:

XMFLOAT3 up, position, lookAt;

// Setup the vector that points upwards.
up.x = 0.0f
up.y = 1.0f
up.z = 0.0f

// Setup the position of the camera in the world.
position.x = m_positionX;
position.y = m_positionY;
position.z = m_positionZ;

// Setup where the camera is looking by default.
lookAt.x = 0.0f;
lookAt.y = 0.0f;
lookAt.z = 1.0f;

// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
XMVector3TransformCoord(lookAt, rotationMatrix);
XMVector3TransformCoord(up, rotationMatrix);

I get an error:

IntelliSense: no suitable user-defined conversion from "DirectX::XMFLOAT3" to "DirectX::XMVECTOR" exists

I have found that I can TypeCast lookAt and up using XMLoadFloat3:

XMVector3TransformCoord(XMLoadFloat3(&lookAt), rotationMatrix);
XMVector3TransformCoord(XMLoadFloat3(&up), rotationMatrix);

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

After doing this, I try to:

// Translate the rotated camera position to the location of the viewer.
lookAt = position + lookAt;

and get the error:

IntelliSense: no operator "+" matches these operands operand types are: DirectX::XMFLOAT3 + DirectX::XMFLOAT3

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

解决方案

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! =)

这篇关于将DirectX SDK代码转换为新的Windows 8.1 SDK代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆