Skip to content

Instantly share code, notes, and snippets.

@MarioLiebisch
Created August 25, 2017 08:30
Show Gist options
  • Save MarioLiebisch/b5d9de83b649a63a5ac9c1b64bfa2822 to your computer and use it in GitHub Desktop.
Save MarioLiebisch/b5d9de83b649a63a5ac9c1b64bfa2822 to your computer and use it in GitHub Desktop.
Transforming a vector using SFML, e.g. by rotating it by 45 degree.
#include <SFML/Graphics/Transform.hpp>
#include <SFML/System/Vector2.hpp>
#include <iostream>
int main() {
// First we'll need a vector to tranform
sf::Vector2f myVector(2, 0);
std::cout << "myVector: " << myVector.x << ", " << myVector.y << "\n";
// Then the actual transform
sf::Transform myTransform;
myTransform.rotate(45); // Rotate by 45 degree
// Now calculate and output the resulting vector
sf::Vector2f myTransformedVector = myTransform.transformPoint(myVector);
std::cout << "myTransformedVector: " << myTransformedVector.x << ", " << myTransformedVector.y << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment