## graphene

### annotate src/gmath/vector.cc @ 5:2ce58d5309f0

swizzling
author John Tsiombikas Sat, 25 Jul 2015 17:19:27 +0300 d30e24132b6e
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@5 6 Vector2::Vector2(const Vector3 &v)
nuclear@5 7 : x(v.x), y(v.y)
nuclear@5 8 {
nuclear@5 9 }
nuclear@5 10
nuclear@3 11 Vector3::Vector3(const Vector4 &v)
nuclear@3 12 : x(v.x), y(v.y), z(v.z)
nuclear@3 13 {
nuclear@3 14 }
nuclear@3 15
nuclear@4 16 Vector3 operator *(const Vector3 &v, const Matrix4x4 &m)
nuclear@4 17 {
nuclear@4 18 float x = v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + m[3][0];
nuclear@4 19 float y = v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + m[3][1];
nuclear@4 20 float z = v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + m[3][2];
nuclear@4 21 return Vector3(x, y, z);
nuclear@4 22 }
nuclear@4 23
nuclear@4 24 Vector3 operator *(const Matrix4x4 &m, const Vector3 &v)
nuclear@4 25 {
nuclear@4 26 float x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3];
nuclear@4 27 float y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3];
nuclear@4 28 float z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3];
nuclear@4 29 return Vector3(x, y, z);
nuclear@4 30 }
nuclear@4 31
nuclear@3 32 Vector4::Vector4(const Vector3 &v)
nuclear@3 33 : x(v.x), y(v.y), z(v.z), w(1.0f)
nuclear@3 34 {
nuclear@3 35 }
nuclear@3 36
nuclear@3 37 } // namespace gph