graphene

diff src/gmath/vector.h @ 5:2ce58d5309f0

swizzling
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 25 Jul 2015 17:19:27 +0300
parents d30e24132b6e
children 9fbbc96e6fbe
line diff
     1.1 --- a/src/gmath/vector.h	Sat Jul 25 07:42:30 2015 +0300
     1.2 +++ b/src/gmath/vector.h	Sat Jul 25 17:19:27 2015 +0300
     1.3 @@ -2,12 +2,33 @@
     1.4  #define GMATH_VEC_H_
     1.5  
     1.6  #include <math.h>
     1.7 +#include "swizzle.h"
     1.8  
     1.9  namespace gph {
    1.10  
    1.11 +#define GPH_SWIZZLE2(T, a, b)		inline Vector2 a##b() const;
    1.12 +#define GPH_SWIZZLE3(T, a, b, c)	inline Vector3 a##b##c() const;
    1.13 +#define GPH_SWIZZLE4(T, a, b, c, d)	inline Vector4 a##b##c##d() const;
    1.14 +
    1.15 +class Vector3;
    1.16  class Vector4;
    1.17  class Matrix4x4;
    1.18  
    1.19 +class Vector2 {
    1.20 +public:
    1.21 +	float x, y;
    1.22 +
    1.23 +	Vector2() : x(0), y(0) {}
    1.24 +	Vector2(float x_, float y_) : x(x_), y(y_) {}
    1.25 +	Vector2(const Vector3 &v);
    1.26 +
    1.27 +	inline void normalize();
    1.28 +	inline float &operator[] (int idx);
    1.29 +	inline const float &operator[] (int idx) const;
    1.30 +
    1.31 +	GPH_VEC2_SWIZZLE
    1.32 +};
    1.33 +
    1.34  class Vector3 {
    1.35  public:
    1.36  	float x, y, z;
    1.37 @@ -19,6 +40,8 @@
    1.38  	inline void normalize();
    1.39  	inline float &operator[] (int idx);
    1.40  	inline const float &operator[] (int idx) const;
    1.41 +
    1.42 +	GPH_VEC3_SWIZZLE
    1.43  };
    1.44  
    1.45  
    1.46 @@ -33,6 +56,8 @@
    1.47  	inline void normalize();
    1.48  	inline float &operator[] (int idx);
    1.49  	inline const float &operator[] (int idx) const;
    1.50 +
    1.51 +	GPH_VEC4_SWIZZLE
    1.52  };
    1.53  
    1.54  // ---- Vector3 functions ----