From f080abc9e9415e500797cc21ca1a29db9de3ea77 Mon Sep 17 00:00:00 2001 From: neobrain Date: Thu, 25 Jul 2013 15:37:55 +0200 Subject: [PATCH] GPU/Math3D: Add methods for casting vectors. --- GPU/Math3D.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/GPU/Math3D.h b/GPU/Math3D.h index 57ec736474..659f6a202a 100644 --- a/GPU/Math3D.h +++ b/GPU/Math3D.h @@ -34,6 +34,12 @@ public: Vec2(const T a[2]) : x(a[0]), y(a[1]) {} Vec2(const T& _x, const T& _y) : x(_x), y(_y) {} + template + Vec2 Cast() const + { + return Vec2((T2)x, (T2)y); + } + static Vec2 AssignToAll(const T& f) { return Vec2(f, f); @@ -161,6 +167,12 @@ public: Vec3(const T a[3]) : x(a[0]), y(a[1]), z(a[2]) {} Vec3(const T& _x, const T& _y, const T& _z) : x(_x), y(_y), z(_z) {} + template + Vec3 Cast() const + { + return Vec3((T2)x, (T2)y, (T2)z); + } + // Only implemented for T=int and T=float static Vec3 FromRGB(unsigned int rgb); unsigned int ToRGB() const; // alpha bits set to zero @@ -321,6 +333,12 @@ public: Vec4(const T a[4]) : x(a[0]), y(a[1]), z(a[2]), w(a[3]) {} Vec4(const T& _x, const T& _y, const T& _z, const T& _w) : x(_x), y(_y), z(_z), w(_w) {} + template + Vec4 Cast() const + { + return Vec4((T2)x, (T2)y, (T2)z, (T2)w); + } + // Only implemented for T=int and T=float static Vec4 FromRGBA(unsigned int rgba); unsigned int ToRGBA() const;