AxisAlignedBoundingBox.cpp

Go to the documentation of this file.
00001 
00005 /* Copyright © 2009 James Legg.
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 */
00011 
00012 #include "AxisAlignedBoundingBox.h"
00013 
00014 #include <limits>
00015 
00016 namespace Track{
00017 
00018 const btScalar max_scalar = std::numeric_limits<btScalar>::max();
00019 
00020 AxisAlignedBoundingBox::AxisAlignedBoundingBox()
00021     :   min(max_scalar, max_scalar, max_scalar)
00022     ,   max(-max_scalar, -max_scalar, -max_scalar)
00023 {
00024     
00025 }
00026 
00027 
00028 AxisAlignedBoundingBox::~AxisAlignedBoundingBox()
00029 {
00030     
00031 }
00032 
00033 void AxisAlignedBoundingBox::operator|=(const btVector3 & point)
00034 {
00035     min.setMin(point);
00036     max.setMax(point);
00037 }
00038 
00039 void AxisAlignedBoundingBox::operator|=(const AxisAlignedBoundingBox & other)
00040 {
00041     min.setMin(other.min);
00042     max.setMax(other.max);
00043 }
00044 
00045 void AxisAlignedBoundingBox::add_border(btScalar size)
00046 {
00047     btVector3 pad(size, size, size);
00048     min -= pad;
00049     max += pad;
00050 }
00051 
00052 bool AxisAlignedBoundingBox::valid() const
00053 {
00054     return (    min.x() <= max.x()
00055              && min.y() <= max.y()
00056              && min.z() <= max.z()
00057             );
00058 }
00059 
00060 btScalar AxisAlignedBoundingBox::get_max_x() const
00061 {
00062     return max.x();
00063 }
00064 
00065 btScalar AxisAlignedBoundingBox::get_max_y() const
00066 {
00067     return max.y();
00068 }
00069 
00070 btScalar AxisAlignedBoundingBox::get_max_z() const
00071 {
00072     return max.z();
00073 }
00074 
00075 btScalar AxisAlignedBoundingBox::get_min_x() const
00076 {
00077     return min.x();
00078 }
00079 
00080 btScalar AxisAlignedBoundingBox::get_min_y() const
00081 {
00082     return min.y();
00083 }
00084 
00085 btScalar AxisAlignedBoundingBox::get_min_z() const
00086 {
00087     return min.z();
00088 }
00089 
00090 btVector3 AxisAlignedBoundingBox::get_min() const
00091 {
00092     return min;
00093 }
00094 
00095 btVector3 AxisAlignedBoundingBox::get_max() const
00096 {
00097     return max;
00098 }
00099 
00100 btVector3 AxisAlignedBoundingBox::get_extent() const
00101 {
00102     return max - min;
00103 }
00104 
00105 AxisAlignedBoundingBox AxisAlignedBoundingBox::transform(btTransform transform) const
00106 {
00107     // find the AABB of the 8 transoformed corners of the original AABB.
00108     AxisAlignedBoundingBox result;
00109     for (unsigned int i = 0; i < 2; i++)
00110     {
00111         for (unsigned int j = 0; j < 2; j++)
00112         {
00113             for (unsigned int k = 0; k < 2; k++)
00114             {
00115                 result |= transform(btVector3(i ? min.x() : max.x(),
00116                                               j ? min.y() : max.y(),
00117                                               k ? min.z() : max.z()));
00118             }
00119         }
00120     }
00121     return result;
00122 }
00123 
00124 }

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:11 2010 by Doxygen version 1.4.7 for Racer version svn335.