82 lines
2.1 KiB
C
82 lines
2.1 KiB
C
|
/* Residual - A 3D game interpreter
|
||
|
*
|
||
|
* Residual is the legal property of its developers, whose names
|
||
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
||
|
* file distributed with this source distribution.
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with this library; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||
|
*
|
||
|
* $URL$
|
||
|
* $Id$
|
||
|
*/
|
||
|
|
||
|
#ifndef GRAPHICS_VECTOR2D_H
|
||
|
#define GRAPHICS_VECTOR2D_H
|
||
|
|
||
|
#include "graphics/vector3d.h"
|
||
|
|
||
|
namespace Graphics {
|
||
|
|
||
|
class Vector2d {
|
||
|
public:
|
||
|
Vector2d();
|
||
|
Vector2d(float x, float y);
|
||
|
Vector2d(const Vector2d &vec);
|
||
|
|
||
|
Vector2d &operator=(const Vector2d &vec);
|
||
|
|
||
|
void normalize();
|
||
|
Vector2d getNormalized() const;
|
||
|
|
||
|
void rotateAround(const Vector2d &point, float angle);
|
||
|
float getAngle() const;
|
||
|
float getMagnitude() const;
|
||
|
float getDistanceTo(const Vector2d &point) const;
|
||
|
|
||
|
Vector3d toVector3d() const;
|
||
|
|
||
|
// private:
|
||
|
float _x;
|
||
|
float _y;
|
||
|
};
|
||
|
|
||
|
inline Vector2d operator-(const Vector2d& v1, const Vector2d& v2) {
|
||
|
Vector2d result(v1._x - v2._x, v1._y - v2._y);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
inline Vector2d operator+(const Vector2d &v1, const Vector2d &v2) {
|
||
|
Vector2d result(v1._x + v2._x, v1._y + v2._y);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
inline Vector2d operator*(const Vector2d &v1, float factor) {
|
||
|
Vector2d result(v1._x * factor, v1._y * factor);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
inline Vector2d operator/(const Vector2d &v1, float factor) {
|
||
|
Vector2d result(v1._x / factor, v1._y / factor);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
inline Vector2d operator-(const Vector2d &v) {
|
||
|
return Vector2d(-v._x, -v._y);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif
|