scummvm/math/vector2d.cpp

78 lines
1.9 KiB
C++
Raw Normal View History

2012-01-06 23:15:48 +01:00
/* ResidualVM - A 3D game interpreter
2011-08-30 18:38:33 +02:00
*
2012-01-06 23:15:48 +01:00
* ResidualVM is the legal property of its developers, whose names
2011-08-30 18:38:33 +02:00
* 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
*
*/
#include "math/vector2d.h"
#include "common/stream.h"
#include "common/streamdebug.h"
namespace Math {
2011-08-30 18:38:33 +02:00
Vector2d::Matrix() :
MatrixType<2, 1>() {
2011-11-04 15:25:22 +01:00
}
Vector2d::Matrix(float x, float y) :
MatrixType<2, 1>() {
setValue(0, x);
setValue(1, y);
}
Vector2d::Matrix(const MatrixBase<2, 1> &vec) :
MatrixType<2, 1>(vec) {
2011-08-30 18:38:33 +02:00
}
Vector2d::Matrix(const float *data) :
2011-11-04 21:07:07 +01:00
MatrixType<2, 1>(data) {
2011-11-04 15:25:22 +01:00
}
2011-09-18 16:23:55 +02:00
void Vector2d::rotateAround(const Vector2d &point, const Angle &angle) {
*this -= point;
2011-09-18 16:23:55 +02:00
float cosa = angle.getCosine();
float sina = angle.getSine();;
2011-08-30 18:38:33 +02:00
float x = value(0) * cosa - value(1) * sina;
value(1) = value(0) * sina + value(1) * cosa;
value(0) = x;
2011-08-30 18:38:33 +02:00
*this += point;
2011-08-30 18:38:33 +02:00
}
2011-09-18 16:23:55 +02:00
Angle Vector2d::getAngle() const {
return Angle::arcTangent2(getY(), getX());
2011-08-30 18:38:33 +02:00
}
Vector3d Vector2d::toVector3d() const {
Vector3d v(value(0), value(1), 0);
2011-08-30 18:38:33 +02:00
return v;
}
void Vector2d::readFromStream(Common::ReadStream *stream) {
char buf[8];
stream->read(buf, 8);
setX(get_float(buf));
setY(get_float(buf + 4));
}
2011-08-30 18:38:33 +02:00
}