【发布时间】:2013-06-20 14:06:07
【问题描述】:
我从 www.directxtutorial.com 学习 DirectX (DirectX 9) 并在 Windows 8 中使用 Visual Studio 2012。d3dx9 (d3dx) 被 DirectXMath 等其他标题替换,因此我替换了所有需要的,但有一个问题 -将 XMVECTOR 转换为 D3DVECTOR 和 D3DCOLORVALUE。
问题代码(编写的问题 - /problem!/):
void init_light(void) {
D3DLIGHT9 light; // create the light struct
D3DMATERIAL9 material; // create the material struct
ZeroMemory(&light, sizeof(light)); // clear out the light struct for use
light.Type = D3DLIGHT_DIRECTIONAL; // make the light type 'directional light'
light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); /*problem!*/ // set the light's color
light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f); /*problem!*/
d3ddev->SetLight(0, &light); // send the light struct properties to light #0
d3ddev->LightEnable(0, TRUE); // turn on light #0
ZeroMemory(&material, sizeof(D3DMATERIAL9)); // clear out the struct for use
material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); /*problem!*/ // set diffuse color to white
material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); /*problem!*/ // set ambient color to white
d3ddev->SetMaterial(&material); /*set the globably-used material to &material*/ }
【问题讨论】:
-
您能否详细说明问题所在?当我阅读问题时,您有一个 XMVECTOR 并且想要一个 D3DVECTOR 对吗?你得到什么编译器错误?
-
IntelliSense:不存在从“DirectX::XMVECTOR”到“D3DCOLORVALUE”的合适的用户定义转换。 IntelliSense:不存在从“DirectX::XMVECTOR”到“D3DVECTOR”的合适的用户定义转换。
-
嗯。我会做更多的挖掘,但据我所知,可以对正确的类型进行简单的转换。您是否尝试过类似 material.Diffuse = (D3DXCOLOR)xm_vector; ?
-
d3dx9 (d3dx) 替换为 DirectXMath 等其他标头...
-
我正在调查。现在是我的时间 14:00,我只能在今晚 20:00 左右进一步调查,但我会看看我能不能解决一些问题。您也可以随时在项目中包含 d3dx9.h。似乎没有理由不能同时使用 DX9 和 DX11 接头。不过,我会尝试提出一个比将两者混合更优雅的解决方案。
标签: c++ visual-c++ directx direct3d directx-9