Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class float4 {
- public:
- float x;
- float y;
- float z;
- float w;
- float4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
- float4(float3 const v, float vw) : x(v.x), y(v.y), z(v.z), w(vw) {}
- float4(float const vx, float const vy, float const vz, float const vw) : x(vx), y(vy), z(vz), w(vw) {}
- template <class T>
- float4(T val) : x(val), y(val), z(val), w(val) {}
- float4& operator= (float4 other) {
- x = other.x;
- y = other.y;
- z = other.z;
- w = other.w;
- return *this;
- }
- template <class T>
- float4& operator=(T other) {
- *this = float4(other);
- return *this;
- }
- float4& operator+= (float4 other) {
- x += other.x;
- y += other.y;
- z += other.z;
- w += other.w;
- return *this;
- }
- float4& operator-= (float4 other) {
- x -= other.x;
- y -= other.y;
- z -= other.z;
- w -= other.w;
- return *this;
- }
- float4& operator*= (float4 other) {
- x *= other.x;
- y *= other.y;
- z *= other.z;
- w *= other.w;
- return *this;
- }
- float4& operator/= (float4 other) {
- x /= other.x;
- y /= other.y;
- z /= other.z;
- w /= other.w;
- return *this;
- }
- float4 clamp(float4 const &lo, float4 const &hi) {
- return float4(
- std::max(std::min(x, hi.x),lo.x),
- std::max(std::min(y, hi.y),lo.y),
- std::max(std::min(z, hi.z),lo.z),
- std::max(std::min(w, hi.w),lo.w)
- );
- }
- friend float4 operator+ (float4 lhs, float4 const &rhs) { lhs += rhs; return lhs; }
- friend float4 operator- (float4 lhs, float4 const &rhs) { lhs -= rhs; return lhs; }
- friend float4 operator* (float4 lhs, float4 const &rhs) { lhs *= rhs; return lhs; }
- friend float4 operator/ (float4 lhs, float4 const &rhs) { lhs /= rhs; return lhs; }
- bool operator!= (float4 other) {
- return (x != other.x) || (y != other.y) || (z != other.z) || (w != other.w);
- }
- bool operator== (float4 other) {
- return (x == other.x) && (y == other.y) && (z == other.z) && (w == other.w);
- }
- float3 toFloat3() {
- return float3(x,y,z);
- }
- friend std::ostream & operator << (std::ostream &os, const float4 &v)
- {
- os << "[" << v.x << "," << v.y << "," << v.z << "," << v.w << "]";
- return os;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement