Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/maths/BoundingBoxAligned.h
/* Copyright (C) 2011 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
/* | /* | ||||
* Axis-aligned bounding box | * Axis-aligned bounding box | ||||
*/ | */ | ||||
#ifndef INCLUDED_BOUND | #ifndef INCLUDED_BOUND | ||||
#define INCLUDED_BOUND | #define INCLUDED_BOUND | ||||
// necessary includes | #include "maths/Vector3D.h" | ||||
#include "Vector3D.h" | |||||
#include "graphics/ShaderProgramPtr.h" | #include "graphics/ShaderProgramPtr.h" | ||||
class CFrustum; | class CFrustum; | ||||
class CMatrix3D; | class CMatrix3D; | ||||
class CBoundingBoxOriented; | class CBoundingBoxOriented; | ||||
/////////////////////////////////////////////////////////////////////////////// | // Basic axis aligned bounding box (AABB) class | ||||
// basic axis aligned bounding box (AABB) class | |||||
class CBoundingBoxAligned | class CBoundingBoxAligned | ||||
{ | { | ||||
public: | public: | ||||
static const CBoundingBoxAligned EMPTY; | |||||
CBoundingBoxAligned() { SetEmpty(); } | CBoundingBoxAligned() { SetEmpty(); } | ||||
CBoundingBoxAligned(const CVector3D& min, const CVector3D& max) { | CBoundingBoxAligned(const CVector3D& min, const CVector3D& max) | ||||
{ | |||||
m_Data[0] = min; | m_Data[0] = min; | ||||
m_Data[1] = max; | m_Data[1] = max; | ||||
} | } | ||||
/** | /** | ||||
* Transforms these bounds according to the specified transformation matrix @p m, and writes the axis-aligned bounds | * Transforms these bounds according to the specified transformation matrix @p m, and writes the axis-aligned bounds | ||||
* of that result to @p result. | * of that result to @p result. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | public: | ||||
// return the volume of this bounding box | // return the volume of this bounding box | ||||
float GetVolume() const | float GetVolume() const | ||||
{ | { | ||||
CVector3D v = m_Data[1] - m_Data[0]; | CVector3D v = m_Data[1] - m_Data[0]; | ||||
return (std::max(v.X, 0.0f) * std::max(v.Y, 0.0f) * std::max(v.Z, 0.0f)); | return (std::max(v.X, 0.0f) * std::max(v.Y, 0.0f) * std::max(v.Z, 0.0f)); | ||||
} | } | ||||
// return the centre of this bounding box | // return the center of this bounding box | ||||
void GetCentre(CVector3D& centre) const | void GetCenter(CVector3D& center) const | ||||
{ | { | ||||
centre = (m_Data[0] + m_Data[1]) * 0.5f; | center = (m_Data[0] + m_Data[1]) * 0.5f; | ||||
} | } | ||||
/** | /** | ||||
* Expand the bounding box by the given amount in every direction. | * Expand the bounding box by the given amount in every direction. | ||||
*/ | */ | ||||
void Expand(float amount); | void Expand(float amount); | ||||
/** | /** | ||||
Show All 26 Lines | public: | ||||
/** | /** | ||||
* Render the outline of the bound object as lines. | * Render the outline of the bound object as lines. | ||||
*/ | */ | ||||
void RenderOutline(CShaderProgramPtr& shader) const; | void RenderOutline(CShaderProgramPtr& shader) const; | ||||
private: | private: | ||||
// Holds the minimal and maximal coordinate points in m_Data[0] and m_Data[1], respectively. | // Holds the minimal and maximal coordinate points in m_Data[0] and m_Data[1], respectively. | ||||
CVector3D m_Data[2]; | CVector3D m_Data[2]; | ||||
public: | |||||
static const CBoundingBoxAligned EMPTY; | |||||
}; | }; | ||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
#endif | #endif // INCLUDED_BOUND |
Wildfire Games · Phabricator