// $Id: vector.cpp 2642 2005-06-26 13:38:53Z matzebraun $ // // SuperTux - A Jump'n Run // Copyright (C) 2004 Matthias Braun #include #include #include "math/vector.hpp" void Vector::normalize() { float mag = magnitude(); x /= mag; y /= mag; } Vector Vector::unit() const { return *this / magnitude(); } float Vector::magnitude() const { return sqrt(x*x + y*y); } std::ostream& operator<<(std::ostream& s, const Vector& v) { s << "(" << v.x << ", " << v.y << ")"; return s; } Vector Vector::rotate(float angle) const { float len = magnitude(); return Vector(len * cos(angle), len * sin(angle)); } /* EOF */