## graphene

### annotate src/gmath/vector.cc @ 4:d30e24132b6e

more gmath
author John Tsiombikas Sat, 25 Jul 2015 07:42:30 +0300 d71b4e899e08 2ce58d5309f0
rev   line source
nuclear@4 1 #include "vector.h"
nuclear@4 2 #include "matrix.h"
nuclear@3 3
nuclear@3 4 namespace gph {
nuclear@3 5
nuclear@3 6 Vector3::Vector3(const Vector4 &v)
nuclear@3 7 : x(v.x), y(v.y), z(v.z)
nuclear@3 8 {
nuclear@3 9 }
nuclear@3 10
nuclear@4 11 Vector3 operator *(const Vector3 &v, const Matrix4x4 &m)
nuclear@4 12 {
nuclear@4 13 float x = v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + m[3][0];
nuclear@4 14 float y = v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + m[3][1];
nuclear@4 15 float z = v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + m[3][2];
nuclear@4 16 return Vector3(x, y, z);
nuclear@4 17 }
nuclear@4 18
nuclear@4 19 Vector3 operator *(const Matrix4x4 &m, const Vector3 &v)
nuclear@4 20 {
nuclear@4 21 float x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3];
nuclear@4 22 float y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3];
nuclear@4 23 float z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3];
nuclear@4 24 return Vector3(x, y, z);
nuclear@4 25 }
nuclear@4 26
nuclear@3 27 Vector4::Vector4(const Vector3 &v)
nuclear@3 28 : x(v.x), y(v.y), z(v.z), w(1.0f)
nuclear@3 29 {
nuclear@3 30 }
nuclear@3 31
nuclear@3 32 } // namespace gph