I am having a trouble implementing an interpolation to move an object to a point in my screen.
Here is the code:
factor += timer.getElapsedTime().asSeconds() * speed;
for(int i = 0; i < 50; i++) {
circleObjectArray[i].setPosition(Interpolate(movePositionsX[rand() % 5], movePositionsY[rand() % 5], factor));
window.draw(circleObjectArray[i]);
}
And I want to use this body of the interpolate function but I'm not able to call it
sf::Vector2f Interpolate(const sf::Vector2& pointA, const sf::Vector2& pointB, float factor) {
if(factor > 1.f)
factor = 1.f;
else if(factor < 0.f)
factor = 0.f;
return pointA + (pointB - pointA) * factor;
}
Thank you for you time :D
You need to give your shapes time to move. For each shape you should store the three inputs of your interpolate function. Then, update the factor a little bit every frame and render it by calling Interpolate with the stored arguments. For example, adding 1/60 every frame will make the shape do the complete move in one second at 60 fps.
When the factor reaches 1, select new parameters for the next transition like you do now, or maybe wait a few frames to select the next target. It's up to you.
As for your actual compile error: sf::Vector2
is a template type. You cannot use it by itself. Either write sf::Vector2<float>
, or use the predefined type alias sf::Vector2f
.