From: Akiko Date: Mon, 28 Oct 2013 13:37:13 +0000 (+0100) Subject: - just some support functions for the Vector class X-Git-Url: http://community.linux-addicted.net/gitweb/?a=commitdiff_plain;h=HEAD;p=qtinns.git - just some support functions for the Vector class --- diff --git a/engine/Object.hxx b/engine/Object.hxx index f7f7dcf..cdbe56b 100644 --- a/engine/Object.hxx +++ b/engine/Object.hxx @@ -8,6 +8,7 @@ enum class ObjectType : uint8_t { None, Camera, Plane, + AABox, Sphere, Mesh }; diff --git a/engine/VectorUtils.hxx b/engine/VectorUtils.hxx new file mode 100644 index 0000000..9237915 --- /dev/null +++ b/engine/VectorUtils.hxx @@ -0,0 +1,83 @@ +#pragma once + +#include +#include "Vector.hxx" + +namespace std +{ + // --- minimum --- + + template + Vector2 min(const Vector2& vec1, const Vector2& vec2) + { + return {std::min(vec1.x, vec2.x), std::min(vec1.y, vec2.y)}; + } + + template + Vector2 min(const Vector2& vec1, const Vector2& vec2, const Vector2& vec3) + { + return std::min(std::min(vec1, vec2), std::min(vec2, vec3)); + } + + template + Vector3 min(const Vector3& vec1, const Vector3& vec2) + { + return {std::min(vec1.x, vec2.x), std::min(vec1.y, vec2.y), std::min(vec1.z, vec2.z)}; + } + + template + Vector3 min(const Vector3& vec1, const Vector3& vec2, const Vector3& vec3) + { + return std::min(std::min(vec1, vec2), std::min(vec2, vec3)); + } + + template + Vector4 min(const Vector4& vec1, const Vector4& vec2) + { + return {std::min(vec1.x, vec2.x), std::min(vec1.y, vec2.y), std::min(vec1.z, vec2.z), std::min(vec1.w, vec2.w)}; + } + + template + Vector4 min(const Vector4& vec1, const Vector4& vec2, const Vector4& vec3) + { + return std::min(std::min(vec1, vec2), std::min(vec2, vec3)); + } + + // --- maximum --- + + template + Vector2 max(const Vector2& vec1, const Vector2& vec2) + { + return {std::max(vec1.x, vec2.x), std::max(vec1.y, vec2.y)}; + } + + template + Vector2 max(const Vector2& vec1, const Vector2& vec2, const Vector2& vec3) + { + return std::max(std::max(vec1, vec2), std::max(vec2, vec3)); + } + + template + Vector3 max(const Vector3& vec1, const Vector3& vec3) + { + return {std::max(vec1.x, vec2.y), std::max(vec1.y, vec2.y), std::max(vec1.z, vec2.z)}; + } + + template + Vector3 max(const Vector3& vec1, const Vector3& vec2, const Vector3& vec3) + { + return std::max(std::max(vec1, vec2), std::max(vec2, vec3)); + } + + template + Vector4 max(const Vector4& vec1, const Vector4& vec2) + { + return {std::max(vec1.x, vec2.x), std::max(vec1.y, vec2.y), std::max(vec1.z, vec2.z), std::max(vec1.w, vec2.w)}; + } + + template + Vector4 max(const Vector4& vec1, const Vector4& vec2, const Vector4& vec3) + { + return std::max(std::max(vec1, vec2), std::max(vec2, vec3)); + } +}