Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Need help

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 dawoodr   Members   

391
Like
0Likes
Like

Posted 10 August 2014 - 05:54 PM

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!

 



#2 Buckeye   GDNet+   

10743
Like
1Likes
Like

Posted 10 August 2014 - 06:08 PM


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, 10 August 2014 - 06:15 PM.

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.


#3 dawoodr   Members   

391
Like
0Likes
Like

Posted 10 August 2014 - 06:18 PM

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;





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.