Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I have a func that takes a Vector2f how do I pass a vector without using another  (Read 4237 times)

0 Members and 2 Guests are viewing this topic.

carton83

  • Newbie
  • *
  • Posts: 38
    • View Profile
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.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
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?
« Last Edit: May 02, 2014, 10:25:44 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

carton83

  • Newbie
  • *
  • Posts: 38
    • View Profile
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?

carton83

  • Newbie
  • *
  • Posts: 38
    • View Profile
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. 

 

anything