Panda3D
finiteBoundingVolume.cxx
1 // Filename: finiteBoundingVolume.cxx
2 // Created by: drose (02Oct99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "finiteBoundingVolume.h"
16 #include "boundingBox.h"
17 #include "config_mathutil.h"
18 
19 TypeHandle FiniteBoundingVolume::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: FiniteBoundingVolume::get_volume
23 // Access: Public, Virtual
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 PN_stdfloat FiniteBoundingVolume::
27 get_volume() const {
28  nassertr(!is_infinite(), 0.0f);
29  if (is_empty()) {
30  return 0.0f;
31  }
32 
33  mathutil_cat.warning()
34  << get_type() << "::get_volume() called\n";
35 
36  // We don't know how to compute the volume of this shape correctly;
37  // just calculate the volume of its containing box.
38  BoundingBox box(get_min(), get_max());
39  box.local_object();
40  return box.get_volume();
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: FiniteBoundingVolume::as_finite_bounding_volume
45 // Access: Public, Virtual
46 // Description: Virtual downcast method. Returns this object as a
47 // pointer of the indicated type, if it is in fact that
48 // type. Returns NULL if it is not that type.
49 ////////////////////////////////////////////////////////////////////
52  return this;
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: FiniteBoundingVolume::around_lines
57 // Access: Protected, Virtual
58 // Description: Double-dispatch support: called by around_other()
59 // when the type of the first element in the list is
60 // known to be a nonempty line.
61 ////////////////////////////////////////////////////////////////////
62 bool FiniteBoundingVolume::
63 around_lines(const BoundingVolume **, const BoundingVolume **) {
64  _flags = F_infinite;
65 
66  // Since it's a FiniteBoundingVolume, we can't do any better than
67  // making it infinite. So we return true.
68  return true;
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: FiniteBoundingVolume::around_planes
73 // Access: Protected, Virtual
74 // Description: Double-dispatch support: called by around_other()
75 // when the type of the first element in the list is
76 // known to be a nonempty plane.
77 ////////////////////////////////////////////////////////////////////
78 bool FiniteBoundingVolume::
79 around_planes(const BoundingVolume **, const BoundingVolume **) {
80  _flags = F_infinite;
81 
82  // Since it's a FiniteBoundingVolume, we can't do any better than
83  // making it infinite. So we return true.
84  return true;
85 }
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
Definition: boundingBox.h:31
bool is_empty() const
Any kind of volume might be empty.
bool is_infinite() const
The other side of the empty coin is an infinite volume.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A special kind of GeometricBoundingVolume that is known to be finite.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual const FiniteBoundingVolume * as_finite_bounding_volume() const
Virtual downcast method.