diff --git a/math/quat.cpp b/math/quat.cpp index cc6d2695f1c..324557dd26c 100644 --- a/math/quat.cpp +++ b/math/quat.cpp @@ -87,5 +87,5 @@ Matrix4 Quaternion::toMatrix() { dst.setData(newMat); return dst; } - + } diff --git a/math/quat.h b/math/quat.h index c544d3e1ba3..4e802261bc8 100644 --- a/math/quat.h +++ b/math/quat.h @@ -41,13 +41,15 @@ public: Quaternion() : Vector4d(0, 0, 0, 0) {} Quaternion(float lx, float ly, float lz, float lw) : Vector4d(lx, ly, lz, lw) {} Quaternion(const Quaternion &q) : Vector4d(q.x(), q.y(), q.z(), q.w()) {} - + Quaternion(const Vector4d &vec) : Vector4d(vec.x(), vec.y(), vec.z(), vec.w()) {} + Matrix4 toMatrix(); void slerpQuat(Quaternion dst, const Quaternion from, const Quaternion to, const float t); inline static Quaternion get_quaternion(const char *data) { return Quaternion(get_float(data), get_float(data + 4), get_float(data + 8), get_float(data + 12)); } + Quaternion& operator=(Vector4d &vec); }; } // end of namespace Math diff --git a/math/vector2d.cpp b/math/vector2d.cpp index 3743fe5e782..94d41e311f8 100644 --- a/math/vector2d.cpp +++ b/math/vector2d.cpp @@ -21,7 +21,7 @@ */ #include "math/vector2d.h" - +#include "common/stream.h" #include "common/streamdebug.h" namespace Math { @@ -66,5 +66,12 @@ Vector3d Vector2d::toVector3d() const { Vector3d v(value(0), value(1), 0); return v; } + +void Vector2d::readFromStream(Common::ReadStream *stream) { + char buf[8]; + stream->read(buf, 8); + setX(get_float(buf)); + setY(get_float(buf + 4)); +} } diff --git a/math/vector2d.h b/math/vector2d.h index d48ff8153b6..79b0780b0a4 100644 --- a/math/vector2d.h +++ b/math/vector2d.h @@ -26,6 +26,10 @@ #include "math/vector.h" #include "math/vector3d.h" +namespace Common { +class ReadStream; +} + namespace Math { template<> @@ -45,6 +49,12 @@ public: Angle getAngle() const; Vector3d toVector3d() const; + + /** + * Reads 2 floats from the passed stream, and uses them + * as x and y in chronological order. + */ + void readFromStream(Common::ReadStream *stream); }; typedef Matrix<2, 1> Vector2d; diff --git a/math/vector3d.cpp b/math/vector3d.cpp index 483a63b7e81..0ee456cb1de 100644 --- a/math/vector3d.cpp +++ b/math/vector3d.cpp @@ -21,7 +21,7 @@ */ #include "common/streamdebug.h" - +#include "common/stream.h" #include "math/vector3d.h" namespace Math { @@ -55,5 +55,13 @@ void Vector3d::set(float lx, float ly, float lz) { Angle Vector3d::unitCircleAngle() const { return Angle::arcTangent2(y(), x()); } - + +void Vector3d::readFromStream(Common::ReadStream *stream) { + char buf[12]; + stream->read(buf, 12); + x() = get_float(buf); + y() = get_float(buf + 4); + z() = get_float(buf + 8); } + +} // end of namespace Math diff --git a/math/vector3d.h b/math/vector3d.h index e831c3ad2c5..8eb31e7a6fc 100644 --- a/math/vector3d.h +++ b/math/vector3d.h @@ -29,6 +29,10 @@ #include "math/vector.h" #include "math/angle.h" +namespace Common { +class ReadStream; +} + namespace Math { typedef Matrix<3, 1> Vector3d; @@ -67,7 +71,12 @@ public: inline static Vector3d get_vector3d(const char *data) { return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8)); } - + + /** + * Reads 3 floats from the passed stream, and uses them + * as x,y,z in chronological order. + */ + void readFromStream(Common::ReadStream *stream); }; } // end of namespace Math diff --git a/math/vector4d.cpp b/math/vector4d.cpp index bdaecd07489..14dfa6aab5a 100644 --- a/math/vector4d.cpp +++ b/math/vector4d.cpp @@ -21,7 +21,7 @@ */ #include "common/streamdebug.h" - +#include "common/stream.h" #include "math/vector4d.h" namespace Math { @@ -50,5 +50,14 @@ Vector4d::Matrix(const float *data) : void Vector4d::set(float lx, float ly, float lz, float lw) { x() = lx; y() = ly; z() = lz; w() = lw; } - + +void Vector4d::readFromStream(Common::ReadStream *stream) { + char buf[16]; + stream->read(buf, 16); + x() = get_float(buf); + y() = get_float(buf + 4); + z() = get_float(buf + 8); + w() = get_float(buf + 12); } + +} // end of namespace Math diff --git a/math/vector4d.h b/math/vector4d.h index c58c82e9d1b..425e1a785e7 100644 --- a/math/vector4d.h +++ b/math/vector4d.h @@ -29,6 +29,10 @@ #include "math/vector.h" #include "math/angle.h" +namespace Common { +class ReadStream; +} + namespace Math { typedef Matrix<4, 1> Vector4d; @@ -59,7 +63,12 @@ public: inline static Vector4d get_vector4d(const char *data) { return Vector4d(get_float(data), get_float(data + 4), get_float(data + 8), get_float(data + 12)); } - + + /** + * Reads 4 floats from the passed stream, and uses them + * as x,y,z,w in chronological order. + */ + void readFromStream(Common::ReadStream *stream); }; } // end of namespace Math