SFML community forums

Help => System => Topic started by: carton83 on May 02, 2014, 09:29:00 am

Title: I have a func that takes a Vector2f how do I pass a vector without using another
Post by: carton83 on May 02, 2014, 09:29:00 am
Damn, the character limit for titles is tiny.

I have a function that takes two vectors uses them to create their magnitude.

If I try to do
get2DMagnitude((0.f,0.f),(1.f,1.f));
gcc complains that "error: could not convert '(0, 0.0f)' from 'float' to 'sf::Vector2f {aka sf::Vector2<float>}'"

I'm doing something wrong.



Also, does anyone know where I can learn about how to animate using vector math?  I think I have figured it out, but it's always good to have something that just says "hey, this is how you do x".

I just can't seem to find any.

Title: AW: I have a func that takes a Vector2f how do I pass a vector without using another
Post by: eXpl0it3r on May 02, 2014, 09:41:11 am
If you use C++11 you can use the general initialization brackets: func({0.1f, 0.5f})
Otherwise you need to use the class name: func(sf::Vector2f(0.1f, 0.5f))


Animation with vector math? What do you mean with that?
Title: Re: I have a func that takes a Vector2f how do I pass a vector without using another
Post by: carton83 on May 02, 2014, 09:10:04 pm
Ah, thanks!

I'm gonna give an example of what I'm talking about.  I have a sprite at 0,0 and I want to move it to say 157,56.  How do I do the math that moves him along that vector in an efficient manner?
Title: Re: I have a func that takes a Vector2f how do I pass a vector without using another
Post by: carton83 on May 02, 2014, 10:21:31 pm
I think I just figured it out.  I take the unit vector, multiply it by the displacement, and then use that as what you move the sprite by.