ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

aabb.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "math/aabb.h"
00024 
00025 namespace Math {
00026 
00027 AABB::AABB() : _valid(false) {
00028 }
00029 
00030 AABB::AABB(const Math::Vector3d &min, const Math::Vector3d &max) : _valid(true), _min(min), _max(max) {
00031 }
00032 
00033 void AABB::reset() {
00034     _valid = false;
00035 }
00036 
00037 void AABB::expand(const Math::Vector3d &v) {
00038     if (!_valid) {
00039         _min = v;
00040         _max = v;
00041         _valid = true;
00042     } else {
00043         if (v.x() < _min.x())
00044             _min.x() = v.x();
00045         if (v.y() < _min.y())
00046             _min.y() = v.y();
00047         if (v.z() < _min.z())
00048             _min.z() = v.z();
00049 
00050         if (v.x() > _max.x())
00051             _max.x() = v.x();
00052         if (v.y() > _max.y())
00053             _max.y() = v.y();
00054         if (v.z() > _max.z())
00055             _max.z() = v.z();
00056     }
00057 }
00058 
00059 void AABB::transform(const Math::Matrix4 &matrix) {
00060     Math::Vector3d min = _min;
00061     Math::Vector3d max = _max;
00062 
00063     reset();
00064 
00065     Math::Vector3d verts[8];
00066     verts[0].set(min.x(), min.y(), min.z());
00067     verts[1].set(max.x(), min.y(), min.z());
00068     verts[2].set(min.x(), max.y(), min.z());
00069     verts[3].set(min.x(), min.y(), max.z());
00070     verts[4].set(max.x(), max.y(), min.z());
00071     verts[5].set(max.x(), min.y(), max.z());
00072     verts[6].set(min.x(), max.y(), max.z());
00073     verts[7].set(max.x(), max.y(), max.z());
00074 
00075     for (int i = 0; i < 8; ++i) {
00076         matrix.transform(&verts[i], true);
00077         expand(verts[i]);
00078     }
00079 }
00080 
00081 }


Generated on Sat Oct 12 2019 05:01:11 for ResidualVM by doxygen 1.7.1
curved edge   curved edge