Panda3D

physxBounds3.cxx

00001 // Filename: physxBounds3.cxx
00002 // Created by:  enn0x (31Oct09)
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 #include "physxBounds3.h"
00016 #include "physxManager.h"
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //     Function: PhysxBounds3::get_max
00020 //       Access: Published
00021 //  Description: Returns the minimum corner of the bounding box.
00022 ////////////////////////////////////////////////////////////////////
00023 LPoint3f PhysxBounds3::
00024 get_max() const {
00025 
00026   return PhysxManager::nxVec3_to_point3(_bounds.max);
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: PhysxBounds3::get_min
00031 //       Access: Published
00032 //  Description: Returns the maximum corner of the bounding box.
00033 ////////////////////////////////////////////////////////////////////
00034 LPoint3f PhysxBounds3::
00035 get_min() const {
00036 
00037   return PhysxManager::nxVec3_to_point3(_bounds.min);
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: PhysxBounds3::get_center
00042 //       Access: Published
00043 //  Description: Returns the center of the bounding box.
00044 ////////////////////////////////////////////////////////////////////
00045 LPoint3f PhysxBounds3::
00046 get_center() const {
00047 
00048   NxVec3 center;
00049   _bounds.getCenter(center);
00050   return PhysxManager::nxVec3_to_point3(center);
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: PhysxBounds3::get_dimensions
00055 //       Access: Published
00056 //  Description: Returns the extents of the bounding box.
00057 ////////////////////////////////////////////////////////////////////
00058 LVector3f PhysxBounds3::
00059 get_dimensions() const {
00060 
00061   NxVec3 dims;
00062   _bounds.getDimensions(dims);
00063   return PhysxManager::nxVec3_to_vec3(dims);
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: PhysxBounds3::set_max
00068 //       Access: Published
00069 //  Description: Sets the maximum corner of the bounding box.
00070 ////////////////////////////////////////////////////////////////////
00071 void PhysxBounds3::
00072 set_max(LPoint3f value) {
00073 
00074   nassertv(!value.is_nan());
00075 
00076   _bounds.max = PhysxManager::point3_to_nxVec3(value);
00077 }
00078 
00079 ////////////////////////////////////////////////////////////////////
00080 //     Function: PhysxBounds3::set_min
00081 //       Access: Published
00082 //  Description: Sets the minimum corner of the bounding box.
00083 ////////////////////////////////////////////////////////////////////
00084 void PhysxBounds3::
00085 set_min(LPoint3f value) {
00086 
00087   nassertv(!value.is_nan());
00088 
00089   _bounds.min = PhysxManager::point3_to_nxVec3(value);
00090 }
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: PhysxBounds3::bounds_of_obb
00094 //       Access: Published
00095 //  Description: Sets this to the AABB (axis ligned bounding box)
00096 //               of the OBB (oriented bounding box). The OBB is
00097 //               described by orientation, translation and half
00098 //               dimensions.
00099 ////////////////////////////////////////////////////////////////////
00100 void PhysxBounds3::
00101 bounds_of_obb(const LMatrix3f &orientation, const LPoint3f &translation, const LVector3f &half_dims) {
00102 
00103   nassertv(!orientation.is_nan());
00104   nassertv(!translation.is_nan());
00105   nassertv(!half_dims.is_nan());
00106 
00107   _bounds.boundsOfOBB(PhysxManager::mat3_to_nxMat33(orientation),
00108                       PhysxManager::point3_to_nxVec3(translation),
00109                       PhysxManager::vec3_to_nxVec3(half_dims));
00110 }
00111 
00112 ////////////////////////////////////////////////////////////////////
00113 //     Function: PhysxBounds3::combine
00114 //       Access: Published
00115 //  Description: Sets this to the union of this and b2. 
00116 ////////////////////////////////////////////////////////////////////
00117 void PhysxBounds3::
00118 combine(const PhysxBounds3 &b2) {
00119 
00120   _bounds.combine(b2._bounds);
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: PhysxBounds3::contain
00125 //       Access: Published
00126 //  Description: Returns TRUE if these bounds contain the point v.
00127 ////////////////////////////////////////////////////////////////////
00128 bool PhysxBounds3::
00129 contain(const LPoint3f &p) const {
00130 
00131   nassertr(!p.is_nan(), false);
00132 
00133   return _bounds.contain(PhysxManager::point3_to_nxVec3(p));
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: PhysxBounds3::fatten
00138 //       Access: Published
00139 //  Description: Fattens the AABB in all three dimensions by the
00140 //               given distance.
00141 ////////////////////////////////////////////////////////////////////
00142 void PhysxBounds3::
00143 fatten(float distance) {
00144 
00145   _bounds.fatten(distance);
00146 }
00147 
00148 ////////////////////////////////////////////////////////////////////
00149 //     Function: PhysxBounds3::include
00150 //       Access: Published
00151 //  Description: Expands the volume to include the point v.
00152 ////////////////////////////////////////////////////////////////////
00153 void PhysxBounds3::
00154 include(const LPoint3f &p) {
00155 
00156   nassertv(!p.is_nan());
00157   _bounds.include(PhysxManager::point3_to_nxVec3(p));
00158 }
00159 
00160 ////////////////////////////////////////////////////////////////////
00161 //     Function: PhysxBounds3::intersects
00162 //       Access: Published
00163 //  Description: Returns TRUE if the intersection of this and b is
00164 //               is not empty.
00165 ////////////////////////////////////////////////////////////////////
00166 bool PhysxBounds3::
00167 intersects(const PhysxBounds3 &b) const {
00168 
00169   return _bounds.intersects(b._bounds);
00170 }
00171 
00172 ////////////////////////////////////////////////////////////////////
00173 //     Function: PhysxBounds3::intersects2d
00174 //       Access: Published
00175 //  Description: Indicates whether the intersection of this and b
00176 //               is empty or not in the plane orthogonal to the
00177 //               axis passed (X = 0, Y = 1 or Z = 2). 
00178 ////////////////////////////////////////////////////////////////////
00179 bool PhysxBounds3::
00180 intersects2d(const PhysxBounds3 &b, unsigned axis_to_ignore) const {
00181 
00182   return _bounds.intersects2D(b._bounds, axis_to_ignore);
00183 }
00184 
00185 ////////////////////////////////////////////////////////////////////
00186 //     Function: PhysxBounds3::is_empty
00187 //       Access: Published
00188 //  Description: Returns TRUE if the bounding box is empty.
00189 ////////////////////////////////////////////////////////////////////
00190 bool PhysxBounds3::
00191 is_empty() const {
00192 
00193   return _bounds.isEmpty();
00194 }
00195 
00196 ////////////////////////////////////////////////////////////////////
00197 //     Function: PhysxBounds3::scale
00198 //       Access: Published
00199 //  Description: Scales the AABB by the given factor.
00200 ////////////////////////////////////////////////////////////////////
00201 void PhysxBounds3::
00202 scale(float scale) {
00203 
00204   _bounds.scale(scale);
00205 }
00206 
00207 ////////////////////////////////////////////////////////////////////
00208 //     Function: PhysxBounds3::set
00209 //       Access: Published
00210 //  Description: Setup this AABB from minimum corner and maximum
00211 //               corner.
00212 ////////////////////////////////////////////////////////////////////
00213 void PhysxBounds3::
00214 set(const LPoint3f &min, const LPoint3f &max) {
00215 
00216   nassertv(!min.is_nan());
00217   nassertv(!max.is_nan());
00218 
00219   _bounds.set(PhysxManager::point3_to_nxVec3(min),
00220               PhysxManager::point3_to_nxVec3(max));
00221 }
00222 
00223 ////////////////////////////////////////////////////////////////////
00224 //     Function: PhysxBounds3::set_center_extents
00225 //       Access: Published
00226 //  Description: Setup this AABB from center point and extents
00227 //               vector.
00228 ////////////////////////////////////////////////////////////////////
00229 void PhysxBounds3::
00230 set_center_extents(const LPoint3f &center, const LVector3f &extents) {
00231 
00232   nassertv(!center.is_nan());
00233   nassertv(!extents.is_nan());
00234 
00235   _bounds.setCenterExtents(PhysxManager::point3_to_nxVec3(center),
00236                            PhysxManager::vec3_to_nxVec3(extents));
00237 }
00238 
00239 ////////////////////////////////////////////////////////////////////
00240 //     Function: PhysxBounds3::set_empty
00241 //       Access: Published
00242 //  Description: Sets empty to TRUE.
00243 ////////////////////////////////////////////////////////////////////
00244 void PhysxBounds3::
00245 set_empty() {
00246 
00247   _bounds.setEmpty();
00248 }
00249 
00250 ////////////////////////////////////////////////////////////////////
00251 //     Function: PhysxBounds3::set_infinite
00252 //       Access: Published
00253 //  Description: Sets infinite bounds.
00254 ////////////////////////////////////////////////////////////////////
00255 void PhysxBounds3::
00256 set_infinite() {
00257 
00258   _bounds.setInfinite();
00259 }
00260 
00261 ////////////////////////////////////////////////////////////////////
00262 //     Function: PhysxBounds3::transform
00263 //       Access: Published
00264 //  Description: Transforms this volume as if it was an axis aligned
00265 //               bounding box, and then assigns the results' bounds
00266 //               to this. The orientation is applied first, then the
00267 //               translation.
00268 ////////////////////////////////////////////////////////////////////
00269 void PhysxBounds3::
00270 transform(const LMatrix3f &orientation, const LPoint3f &translation) {
00271 
00272   nassertv(!orientation.is_nan());
00273   nassertv(!translation.is_nan());
00274 
00275   _bounds.transform(PhysxManager::mat3_to_nxMat33(orientation),
00276                     PhysxManager::point3_to_nxVec3(translation));
00277 }
00278 
 All Classes Functions Variables Enumerations