Followers 0

# Need help

## 2 posts in this topic

Hello!

	XMVECTOR gringo = { 1, 2, 3, 4 };

float a = XMVectorGetY(gringo);
cout << a << endl;
XMVectorSetY(gringo, 40);
a = XMVectorGetY(gringo);
cout << a << endl;


The first output should be 2 which it is. The second output should be 40 put it's still 2, why? What have I done wrong?

Regards!

0

##### Share on other sites

What have I done wrong?

XMVectorSetY does not set the Y value in gringo. It returns an XMVECTOR the same as the argument (gringo, in your case), except the Y value is replaced. Your code generates the new vector, which would be { 1, 40, 3, 4} but you don't store it.

    XMVECTOR g = { 1, 2, 3, 4 };
float a = XMVectorGetY(g); // get g's Y value of 2.0f
XMVECTOR g2 = XMVectorSetY(g, 40.0f);
a = XMVectorGetY(g2); // get g2's Y value of 40.0f


Alternatively,

gringo = XMVectorSetY(gringo, 40.0f);
a = XMVectorGetY(gringo); // now a==40.0f


FYI, I didn't know that of my own certain knowledge. I looked at the docs (which you can, also) and tried a quick test.

Edited by Buckeye
1

##### Share on other sites

Thanks, so it was just that it was never stored,

Here is how I changed it now and it works fine, thanks once again!

XMVECTOR gringo = { 1, 2, 3, 4 };

float a = XMVectorGetY(gringo);
cout << a << endl;
gringo = XMVectorSetY(gringo, 40);
a = XMVectorGetY(gringo);
cout << a << endl;
0

## Create an account

Register a new account