简体   繁体   English

DirectX 中的 XMVECTOR

[英]XMVECTOR in DirectX

Sorry for the dumb question .... but why this does not work ?抱歉这个愚蠢的问题......但是为什么这不起作用? To show the problem I wrote this simple code:为了显示这个问题,我写了这个简单的代码:

#include <windows.h> 
#include <DirectXMath.h>
#include <DirectXPackedVector.h>
#include <iostream>
using namespace std;
using namespace DirectX;
using namespace DirectX::PackedVector;

int main()
{
XMVECTOR c = XMVECTORSet(3.0f, 3.0f, 3.0f, 3.0f);

return 0;
}

VS answers "error C3861: 'XMVECTORSet': identifier not found" VS 回答“错误 C3861:‘XMVECTORSet’:未找到标识符”

You should use XMVectorSet instead of XMVECTORSet (This function does not exist)您应该使用XMVectorSet而不是XMVECTORSet (此函数不存在)

Function definition on msdn msdn 上的函数定义

There are a number of ways to initialize a vectorized-constant for DirectXMath.有多种方法可以为 DirectXMath 初始化向量化常量。 XMVectorSet is best when the parameters are float variables not literal values.当参数是浮点变量而不是文字值时, XMVectorSet是最好的。

XMVECTOR c = XMVectorSet( 3.f, 3.f, 3.f, .3f );

In the case of a literal constant, you are better off using:对于文字常量,最好使用:

const XMVECTORF32 c = { 3.f, 3.f, 3.f, 3.f };

clang will want you to write it as: const XMVECTORF32 c = { { { 3.f, 3.f, 3.f, 3f.f } } }; clang 会希望你把它写成: const XMVECTORF32 c = { { { 3.f, 3.f, 3.f, 3f.f } } }; if you have -Wmissing-braces enabled.如果您启用了-Wmissing-braces

Other options (again, not the best for literal values, but better for variables):其他选项(同样,对于文字值不是最好的,但对于变量更好):

XMVECTOR c = XMVectorReplicate( 3.f );
float x = 3.f;
XMVECTOR c = XMVectorReplicatePtr(&x);
const XMVECTORF32 t = { 1.f, 2.f, 3.f, 4.f };
XMVECTOR c = XMVectorSplatZ(t);

The DirectXMath Programmer's Guide is a short read, and it covers a lot of use cases. DirectXMath 程序员指南是一个简短的读物,它涵盖了许多用例。

If you are new to DirectXMath, you should consider using the SimpleMath wrapper types for DirectXMath that is included in DirectX Tool Kit for DX11 / DX12 .如果您不熟悉 DirectXMath,您应该考虑使用DirectXMath 的 SimpleMath包装器类型,它包含在DirectX Tool Kit for DX11 / DX12 中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM