Panda3D
 All Classes Functions Variables Enumerations
boundingBox.I
00001 // Filename: boundingBox.I
00002 // Created by:  drose (31May07)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: BoundingBox::Constructor
00018 //       Access: Published
00019 //  Description: Constructs an empty box object.
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE_MATHUTIL BoundingBox::
00022 BoundingBox() {
00023 }
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: BoundingBox::Constructor
00027 //       Access: Published
00028 //  Description: Constructs a specific box object.
00029 ////////////////////////////////////////////////////////////////////
00030 INLINE_MATHUTIL BoundingBox::
00031 BoundingBox(const LPoint3 &min, const LPoint3 &max) :
00032   _min(min), _max(max)
00033 {
00034 #ifdef NDEBUG
00035   _flags = F_empty;
00036   nassertv(!_min.is_nan() && !_max.is_nan());
00037   nassertv(_min[0] <= _max[0] && _min[1] <= _max[1] && _min[2] <= _max[2]);
00038 #endif  // NDEBUG
00039   _flags = 0;
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: BoundingBox::get_minq
00044 //       Access: Public
00045 //  Description: An inline accessor for the minimum value.  get_min()
00046 //               would also work, but it is a virtual non-inline
00047 //               method.
00048 ////////////////////////////////////////////////////////////////////
00049 INLINE_MATHUTIL const LPoint3 &BoundingBox::
00050 get_minq() const {
00051   nassertr(!is_empty(), _min);
00052   nassertr(!is_infinite(), _min);
00053   return _min;
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: BoundingBox::get_maxq
00058 //       Access: Public
00059 //  Description: An inline accessor for the maximum value.  get_max()
00060 //               would also work, but it is a virtual non-inline
00061 //               method.
00062 ////////////////////////////////////////////////////////////////////
00063 INLINE_MATHUTIL const LPoint3 &BoundingBox::
00064 get_maxq() const {
00065   nassertr(!is_empty(), _max);
00066   nassertr(!is_infinite(), _max);
00067   return _max;
00068 }
00069 
00070 ////////////////////////////////////////////////////////////////////
00071 //     Function: BoundingBox::get_num_points
00072 //       Access: Published
00073 //  Description: Returns 8: the number of vertices of a rectangular solid.
00074 ////////////////////////////////////////////////////////////////////
00075 INLINE_MATHUTIL int BoundingBox::
00076 get_num_points() const {
00077   return 8;
00078 }
00079 
00080 ////////////////////////////////////////////////////////////////////
00081 //     Function: BoundingBox::get_point
00082 //       Access: Published
00083 //  Description: Returns the nth vertex of the rectangular solid.
00084 ////////////////////////////////////////////////////////////////////
00085 INLINE_MATHUTIL LPoint3 BoundingBox::
00086 get_point(int n) const {
00087   nassertr(n >= 0 && n < 8, LPoint3::zero());
00088   
00089   // We do some trickery assuming that _min and _max are consecutive
00090   // in memory.
00091   const LPoint3 *a = &_min;
00092   return LPoint3(a[(n>>2)&1][0], a[(n>>1)&1][1], a[(n)&1][2]);
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: BoundingBox::get_num_planes
00097 //       Access: Published
00098 //  Description: Returns 6: the number of faces of a rectangular solid.
00099 ////////////////////////////////////////////////////////////////////
00100 INLINE_MATHUTIL int BoundingBox::
00101 get_num_planes() const {
00102   return 6;
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: BoundingBox::get_plane
00107 //       Access: Published
00108 //  Description: Returns the nth face of the rectangular solid.
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE_MATHUTIL LPlane BoundingBox::
00111 get_plane(int n) const {
00112   nassertr(n >= 0 && n < 6, LPlane());
00113   return LPlane(get_point(plane_def[n][0]),
00114                 get_point(plane_def[n][1]),
00115                 get_point(plane_def[n][2]));
00116 }
 All Classes Functions Variables Enumerations