Reputation: 947
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().
In the code below, the command XMVectorGetByIndex() works fine, with new_y being set to 1.7 (after adding 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).
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.
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)
Upvotes: 1
Views: 150
Reputation: 9678
XMVectorSetByIndex does not modify the vector you pass in, it returns the new result instead.
XMVECTOR test = { 0.0f, 1.5f, 2.0f, 0.0f };
float new_y = XMVectorGetByIndex(test, 1) + 0.2;
test = XMVectorSetByIndex(test, new_y, 1);
Upvotes: 2
Reputation: 37599
XMVectorSetByIndex
function returns new vector with modified content, it does not modify input vector inplace. So you should overwrite test
:
test = XMVectorSetByIndex(test, new_y, 1);
Upvotes: 3