scummvm/math/vector2d.h

94 lines
2.4 KiB
C
Raw Normal View History

2011-08-30 18:38:33 +02:00
/* 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 MATH_VECTOR2D_H
#define MATH_VECTOR2D_H
2011-08-30 18:38:33 +02:00
#include "math/vector3d.h"
2011-08-30 18:38:33 +02:00
namespace Math {
2011-08-30 18:38:33 +02:00
class Vector2d {
public:
Vector2d();
Vector2d(float x, float y);
Vector2d(const Vector2d &vec);
inline float getX() const { return _x; }
inline float getY() const { return _y; }
void setX(float x);
void setY(float y);
2011-08-30 18:38:33 +02:00
Vector2d &operator=(const Vector2d &vec);
Vector2d &operator/=(float s);
2011-08-30 18:38:33 +02:00
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:
2011-08-30 18:38:33 +02:00
float _x;
float _y;
};
inline Vector2d operator-(const Vector2d& v1, const Vector2d& v2) {
Vector2d result(v1.getX() - v2.getX(), v1.getY() - v2.getY());
2011-08-30 18:38:33 +02:00
return result;
}
inline Vector2d operator+(const Vector2d &v1, const Vector2d &v2) {
Vector2d result(v1.getX() + v2.getX(), v1.getY() + v2.getY());
2011-08-30 18:38:33 +02:00
return result;
}
inline Vector2d operator*(const Vector2d &v1, float factor) {
Vector2d result(v1.getX() * factor, v1.getY() * factor);
2011-08-30 18:38:33 +02:00
return result;
}
inline Vector2d operator/(const Vector2d &v1, float factor) {
Vector2d result(v1.getX() / factor, v1.getY() / factor);
2011-08-30 18:38:33 +02:00
return result;
}
inline Vector2d operator-(const Vector2d &v) {
return Vector2d(-v.getX(), -v.getY());
2011-08-30 18:38:33 +02:00
}
}
namespace Common {
class Debug;
}
Common::Debug &operator<<(Common::Debug dbg, const Math::Vector2d &v);
2011-08-30 18:38:33 +02:00
#endif