graphene

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

more gmath
author John Tsiombikas Sat, 25 Jul 2015 07:42:30 +0300 d71b4e899e08 2ce58d5309f0
line diff
```     1.1 --- a/src/gmath/vector.cc	Sat Jul 25 05:52:39 2015 +0300
1.2 +++ b/src/gmath/vector.cc	Sat Jul 25 07:42:30 2015 +0300
1.3 @@ -1,4 +1,5 @@
1.4 -#include "vec.h"
1.5 +#include "vector.h"
1.6 +#include "matrix.h"
1.7
1.8  namespace gph {
1.9
1.10 @@ -7,6 +8,22 @@
1.11  {
1.12  }
1.13
1.14 +Vector3 operator *(const Vector3 &v, const Matrix4x4 &m)
1.15 +{
1.16 +	float x = v.x * m[0][0] + v.y * m[1][0] + v.z * m[2][0] + m[3][0];
1.17 +	float y = v.x * m[0][1] + v.y * m[1][1] + v.z * m[2][1] + m[3][1];
1.18 +	float z = v.x * m[0][2] + v.y * m[1][2] + v.z * m[2][2] + m[3][2];
1.19 +	return Vector3(x, y, z);
1.20 +}
1.21 +
1.22 +Vector3 operator *(const Matrix4x4 &m, const Vector3 &v)
1.23 +{
1.24 +	float x = m[0][0] * v.x + m[0][1] * v.y + m[0][2] * v.z + m[0][3];
1.25 +	float y = m[1][0] * v.x + m[1][1] * v.y + m[1][2] * v.z + m[1][3];
1.26 +	float z = m[2][0] * v.x + m[2][1] * v.y + m[2][2] * v.z + m[2][3];
1.27 +	return Vector3(x, y, z);
1.28 +}
1.29 +
1.30  Vector4::Vector4(const Vector3 &v)
1.31  	: x(v.x), y(v.y), z(v.z), w(1.0f)
1.32  {
```