Rectangle3D.h#
↰ Parent directory (math
)
Contains A 3 dimensional rectangle class.
Includes#
PVRCore/glm.h
PVRCore/types/Types.h
Namespaces#
Classes#
Typedefs#
Source Code#
#pragma once
#include "PVRCore/types/Types.h"
#include "PVRCore/glm.h"
namespace pvr {
template<typename TYPE>
struct Rectangle3D
{
TYPE x;
TYPE y;
TYPE z;
TYPE width;
TYPE height;
TYPE depth;
glm::tvec3<TYPE, glm::highp> offset() const { return glm::tvec3<TYPE, glm::highp>(x, y, z); }
glm::tvec3<TYPE, glm::highp> extent() const { return glm::tvec3<TYPE, glm::highp>(width, height, depth); }
glm::tvec3<TYPE, glm::highp> center() const { return offset() + extent() / TYPE(2); }
Rectangle3D() {}
Rectangle3D(TYPE absoluteX, TYPE absoluteY, TYPE absoluteZ, TYPE width, TYPE height, TYPE depth)
: x(absoluteX), y(absoluteY), z(absoluteZ), width(width), height(height), depth(depth)
{}
Rectangle3D(glm::tvec3<TYPE, glm::precision::defaultp> minimumVertex, glm::tvec3<TYPE, glm::precision::defaultp> dimensions)
: x(minimumVertex.x), y(minimumVertex.y), z(minimumVertex.z), width(dimensions.x), height(dimensions.y), depth(dimensions.z)
{}
bool operator==(const Rectangle3D& rhs) const { return (x == rhs.x) && (y == rhs.y) && (z == rhs.z) && (width == rhs.width) && (height == rhs.height) && (depth == rhs.depth); }
bool operator!=(const Rectangle3D& rhs) const { return !(*this == rhs); }
void expand(const Rectangle3D& rect)
{
auto minx = glm::min(x, rect.x);
auto miny = glm::min(y, rect.y);
auto minz = glm::min(z, rect.z);
auto maxx = glm::max(x + height, rect.x + rect.width);
auto maxy = glm::max(y + height, rect.y + rect.width);
auto maxz = glm::max(z + height, rect.z + rect.width);
x = minx;
y = miny;
z = minz;
width = maxx - minx;
height = maxy - miny;
depth = maxz - minz;
}
};
typedef Rectangle3D<int32_t> Rectangle3Di;
typedef Rectangle3D<float> Rectangle3Df;
} // namespace pvr