graphene

view src/gmath/vector.cc @ 4:d30e24132b6e

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