Skip to main content
gamedev.net
🔒 Locked

Need help

Started by dawoodr Aug 10, 2014 at 11:54 PM 1 replies 1.2k views
Original Post
dawoodr
dawoodr
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!

Buckeye
Buckeye

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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
dawoodr
dawoodr

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;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.