简体   繁体   English

DirectX :: XMVECTOR函数XMVectorSetByIndex()未设置浮点(C ++)

[英]DirectX::XMVECTOR function XMVectorSetByIndex() not setting float (C++)

I am having some trouble performing what seems like it should be a simple task in C++, where I am trying to change the values inside a vector (DirectX::XMVECTOR) using the command XMVectorSetByIndex(). 我在执行C ++中看起来应该是一个简单任务的过程中遇到了一些麻烦,在这里我试图使用命令XMVectorSetByIndex()来更改矢量(DirectX :: XMVECTOR)中的值。

In the code below, the command XMVectorGetByIndex() works fine, with new_y being set to 1.7 (after adding 0.2). 在下面的代码中,命令XMVectorGetByIndex()可以正常工作,将new_y设置为1.7(添加0.2之后)。 However, XMVectorSetByIndex() does not lead to test becoming {0.0f, 1.7f, 2.0f, 0.0f} as I would expect (rather it remains unchanged). 但是,XMVectorSetByIndex()不会导致测试变得像我期望的那样{0.0f,1.7f,2.0f,0.0f}(而是保持不变)。

    XMVECTOR test = { 0.0f, 1.5f, 2.0f, 0.0f };
    float new_y = XMVectorGetByIndex(test, 1) + 0.2;
    XMVectorSetByIndex(test, new_y, 1);

I've tried a few different things but had no luck getting the function to work. 我尝试了几种不同的方法,但是没有运气使该功能正常工作。 I just can't see what the issue is (especially given XMVectorGetByIndex() works with no issues. 我只是看不到问题是什么(特别是考虑到XMVectorGetByIndex()可以正常工作)。

Any help would be greatly appreciated :) 任何帮助将不胜感激 :)

https://msdn.microsoft.com/en-us/library/hh404810(v=vs.85).aspx (XMVectorSetByIndex) https://msdn.microsoft.com/en-us/library/Hh404786(v=VS.85).aspx (XMVectorGetByIndex) https://msdn.microsoft.com/en-us/library/hh404810(v=vs.85).aspx (XMVectorSetByIndex) https://msdn.microsoft.com/en-us/library/Hh404786(v=VS .85).aspx (XMVectorGetByIndex)

XMVectorSetByIndex function returns new vector with modified content, it does not modify input vector inplace. XMVectorSetByIndex函数返回具有修改内容的新向量,它不会就地修改输入向量。 So you should overwrite test : 因此,您应该覆盖test

test = XMVectorSetByIndex(test, new_y, 1);

XMVectorSetByIndex does not modify the vector you pass in, it returns the new result instead. XMVectorSetByIndex不会修改您传入的向量,而是返回新结果。

XMVECTOR test = { 0.0f, 1.5f, 2.0f, 0.0f };
float new_y = XMVectorGetByIndex(test, 1) + 0.2;
test = XMVectorSetByIndex(test, new_y, 1);

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

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