#include#include int main() { sf::RenderWindow window(sf::VideoMode(800, 600), "Example"); sf::CircleShape shape(50.f); shape.setFillColor(sf::Color::Green); sf::Vector2f position(400, 300); // initialize the position float speed = 100.f; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); } } float deltaTime = clock.restart().asSeconds(); // calculate the elapsed time position.x += cos(deltaTime) * speed; // move in x-axis position.y += sin(deltaTime) * speed; // move in y-axis shape.setPosition(position); // set the new position window.clear(); window.draw(shape); window.display(); } }
#includeIn this example, we are using a simple Vector2 class and its member functions to calculate the magnitude, normalized and dot product of two vectors. We do this all in the same function.#include int main() { Vector2 v(3.0f, 4.0f); // initialize the vector std::cout << "Magnitude: " << v.magnitude() << std::endl; // calculate the magnitude std::cout << "Normalized: (" << v.normalized().x << ", " << v.normalized().y << ")" << std::endl; // normalize the vector Vector2 u(2.0f, -1.0f); std::cout << "Dot Product: " << Vector2::dot(v, u) << std::endl; // calculate the dot product }