## graphene

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

swizzling
author John Tsiombikas Sat, 25 Jul 2015 17:19:27 +0300 d30e24132b6e
line source
1 #include "vector.h"
2 #include "matrix.h"
4 namespace gph {
6 Vector2::Vector2(const Vector3 &v)
7 : x(v.x), y(v.y)
8 {
9 }
11 Vector3::Vector3(const Vector4 &v)
12 : x(v.x), y(v.y), z(v.z)
13 {
14 }
16 Vector3 operator *(const Vector3 &v, const Matrix4x4 &m)
17 {
18 float x = v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + m[3][0];
19 float y = v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + m[3][1];
20 float z = v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + m[3][2];
21 return Vector3(x, y, z);
22 }
24 Vector3 operator *(const Matrix4x4 &m, const Vector3 &v)
25 {
26 float x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3];
27 float y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3];
28 float z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3];
29 return Vector3(x, y, z);
30 }
32 Vector4::Vector4(const Vector3 &v)
33 : x(v.x), y(v.y), z(v.z), w(1.0f)
34 {
35 }
37 } // namespace gph