graphene
changeset 6:9fbbc96e6fbe tip
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 31 Jul 2015 04:59:28 +0300 |
parents | 2ce58d5309f0 |
children | |
files | src/gmath/quat.h src/gmath/vector.h src/gmath/vector.inl |
diffstat | 3 files changed, 64 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/gmath/quat.h Fri Jul 31 04:59:28 2015 +0300 1.3 @@ -0,0 +1,19 @@ 1.4 +#ifndef QUATERNION_H_ 1.5 +#define QUATERNION_H_ 1.6 + 1.7 +namespace gph { 1.8 + 1.9 +class Quaternion { 1.10 +public: 1.11 + float x, y, z, w; // w + xi + yj + zk 1.12 + 1.13 + Quaternion() : x(0), y(0), z(0), w(1) {} 1.14 + Quaternion(float x_, float y_, float z_, float w_) : x(x_), y(y_), z(z_), w(w_) {} 1.15 + Quaternion(const Vector3 &v, float s) : x(v.x), y(v.y), z(v.z), w(s) {} 1.16 + 1.17 + // TODO more 1.18 +}; 1.19 + 1.20 +} // namespace gph 1.21 + 1.22 +#endif // QUATERNION_H_
2.1 --- a/src/gmath/vector.h Sat Jul 25 17:19:27 2015 +0300 2.2 +++ b/src/gmath/vector.h Fri Jul 31 04:59:28 2015 +0300 2.3 @@ -13,6 +13,7 @@ 2.4 class Vector3; 2.5 class Vector4; 2.6 class Matrix4x4; 2.7 +class Quaternion; 2.8 2.9 class Vector2 { 2.10 public: 2.11 @@ -96,6 +97,14 @@ 2.12 inline Vector3 distance_sq(const Vector3 &a, const Vector3 &b); 2.13 inline Vector3 faceforward(const Vector3 &n, const Vector3 &vi, const Vector3 &ng); 2.14 2.15 +inline Vector3 major(const Vector3 &v); 2.16 +inline int major_idx(const Vector3 &v); 2.17 +inline Vector3 proj_axis(const Vector3 &v, const Vector3 &axis); 2.18 + 2.19 +inline Vector3 rotate(const Vector3 &v, const Quaternion &q); 2.20 +inline Vector3 rotate(const Vector3 &v, const Vector3 &axis, float angle); 2.21 +inline Vector3 rotate(const Vector3 &v, const Vector3 &euler); 2.22 + 2.23 } 2.24 2.25 #endif /* GMATH_VEC_H_ */
3.1 --- a/src/gmath/vector.inl Sat Jul 25 17:19:27 2015 +0300 3.2 +++ b/src/gmath/vector.inl Fri Jul 31 04:59:28 2015 +0300 3.3 @@ -197,6 +197,42 @@ 3.4 return dot(ng, i) < 0.0f ? n : -n; 3.5 } 3.6 3.7 +inline Vector3 major(const Vector3 &v) 3.8 +{ 3.9 + int m = major_idx(v); 3.10 + Vector3 res; 3.11 + res[m] = v[m]; 3.12 + return res; 3.13 +} 3.14 + 3.15 +inline int major_idx(const Vector3 &v) 3.16 +{ 3.17 + return fabs(v.x) >= fabs(v.y) && fabs(v.x) > fabs(v.z) ? 0 : 3.18 + (fabs(v.y) >= fabs(v.z) ? 1 : 2); 3.19 +} 3.20 + 3.21 +inline Vector3 proj_axis(const Vector3 &v, const Vector3 &axis) 3.22 +{ 3.23 + return axis * dot(v, axis); 3.24 +} 3.25 + 3.26 + 3.27 +inline Vector3 rotate(const Vector3 &v, const Quaternion &q) 3.28 +{ 3.29 + return v; // TODO 3.30 +} 3.31 + 3.32 +inline Vector3 rotate(const Vector3 &v, const Vector3 &axis, float angle) 3.33 +{ 3.34 + return v; // TODO 3.35 +} 3.36 + 3.37 +inline Vector3 rotate(const Vector3 &v, const Vector3 &euler) 3.38 +{ 3.39 + return v; // TODO 3.40 +} 3.41 + 3.42 + 3.43 GPH_VEC3_SWIZZLE 3.44 3.45 // ---- Vector4 ----