fixed copying of library links in install target
[gph-math] / src / vector.cc
index 4af8dab..6861648 100644 (file)
@@ -1,3 +1,12 @@
+/*
+gph-math - math library for graphics programs
+Copyright (C) 2016 John Tsiombikas <nuclear@member.fsf.org>
+
+This program is free software. Feel free to use, modify, and/or redistribute
+it under the terms of the MIT/X11 license. See LICENSE for details.
+If you intend to redistribute parts of the code without the LICENSE file
+replace this paragraph with the full contents of the LICENSE file.
+*/
 #include "vector.h"
 #include "matrix.h"
 
@@ -8,6 +17,8 @@ Vector2::Vector2(const Vector3 &v)
 {
 }
 
+// ---- Vector3 ----
+
 Vector3::Vector3(const Vector4 &v)
        : x(v.x), y(v.y), z(v.z)
 {
@@ -29,9 +40,30 @@ Vector3 operator *(const Matrix4x4 &m, const Vector3 &v)
        return Vector3(x, y, z);
 }
 
+// ---- Vector4 ----
+
 Vector4::Vector4(const Vector3 &v)
        : x(v.x), y(v.y), z(v.z), w(1.0f)
 {
 }
 
+Vector4 operator *(const Vector4 &v, const Matrix4x4 &m)
+{
+       float x = v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + v.w * m[3][0];
+       float y = v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + v.w * m[3][1];
+       float z = v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + v.w * m[3][2];
+       float w = v.x * m[0][3] + v.y * m[1][3] + v.z * m[2][3] + v.w * m[3][3];
+       return Vector4(x, y, z, w);
+}
+
+Vector4 operator *(const Matrix4x4 &m, const Vector4 &v)
+{
+       float x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3] * v.w;
+       float y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3] * v.w;
+       float z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3] * v.w;
+       float w = m[3][0] * v.x + m[3][1] * v.y + m[3][2] * v.z + m[3][3] * v.w;
+       return Vector4(x, y, z, w);
+}
+
+
 }      // namespace gph