4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef SUPERTUX_VECTOR_H
21 #define SUPERTUX_VECTOR_H
23 /** Simple two dimensional vector. */
27 Vector(float nx, float ny)
30 Vector(const Vector& other)
31 : x(other.x), y(other.y)
37 bool operator ==(const Vector& other) const
39 return x == other.x && y == other.y;
42 bool operator !=(const Vector& other) const
44 return !(x == other.x && y == other.y);
47 const Vector& operator=(const Vector& other)
54 Vector operator+(const Vector& other) const
56 return Vector(x + other.x, y + other.y);
59 Vector operator-(const Vector& other) const
61 return Vector(x - other.x, y - other.y);
64 Vector operator*(float s) const
66 return Vector(x * s, y * s);
69 Vector operator/(float s) const
71 return Vector(x / s, y / s);
74 Vector operator-() const
76 return Vector(-x, -y);
79 const Vector& operator +=(const Vector& other)
86 const Vector& operator -=(const Vector& other)
93 const Vector& operator *=(float val)
100 const Vector& operator /=(float val)
107 /// Scalar product of 2 vectors
108 float operator*(const Vector& other) const
110 return x*other.x + y*other.y;
116 // ... add the other operators as needed, I'm too lazy now ...
118 float x, y; // leave this public, get/set methods just give me headaches
119 // for such simple stuff :)