Panda3D

bulletTriangleMeshShape.cxx

00001 // Filename: bulletTriangleMeshShape.cxx
00002 // Created by:  enn0x (09Feb10)
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 "bulletTriangleMeshShape.h"
00016 #include "bulletTriangleMesh.h"
00017 
00018 #include "nodePathCollection.h"
00019 #include "geomNode.h"
00020 #include "geomVertexReader.h"
00021 
00022 TypeHandle BulletTriangleMeshShape::_type_handle;
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: BulletTriangleMeshShape::Constructor
00026 //       Access: Published
00027 //  Description: The parameters 'compress' and 'bvh' are only used
00028 //               if 'dynamic' is set to FALSE.
00029 ////////////////////////////////////////////////////////////////////
00030 BulletTriangleMeshShape::
00031 BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress, bool bvh) {
00032 
00033   // Assert that mesh is not NULL
00034   if (!mesh) {
00035     bullet_cat.warning() << "mesh is NULL! creating new mesh." << endl;
00036     mesh = new BulletTriangleMesh();
00037   }
00038 
00039   // Assert that mesh has at least one triangle
00040   if (mesh->get_num_triangles() == 0) {
00041     bullet_cat.warning() << "mesh has zero triangles! adding degenerated triangle." << endl;
00042     mesh->add_triangle(LPoint3::zero(), LPoint3::zero(), LPoint3::zero());
00043   }
00044 
00045   // Retain a pointer to the mesh, to prevent it from being deleted
00046   _mesh = mesh;
00047 
00048   // Dynamic will create a GImpact mesh shape
00049   if (dynamic) {
00050 
00051     _gimpact_shape = new btGImpactMeshShape(mesh->ptr());
00052     _gimpact_shape->updateBound();
00053     _gimpact_shape->setUserPointer(this);
00054 
00055     _bvh_shape = NULL;
00056   }
00057 
00058   // Static will create a Bvh mesh shape
00059   else {
00060 
00061     _bvh_shape = new btBvhTriangleMeshShape(mesh->ptr(), compress, bvh);
00062     _bvh_shape->setUserPointer(this);
00063 
00064     _gimpact_shape = NULL;
00065   }
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: BulletTriangleMeshShape::ptr
00070 //       Access: Public
00071 //  Description:
00072 ////////////////////////////////////////////////////////////////////
00073 btCollisionShape *BulletTriangleMeshShape::
00074 ptr() const {
00075 
00076   if (_bvh_shape) {
00077     return _bvh_shape;
00078   }
00079 
00080   if (_gimpact_shape) {
00081     return _gimpact_shape;
00082   }
00083 
00084   return NULL;
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: BulletTriangleMeshShape::refit_tree
00089 //       Access: Published
00090 //  Description:
00091 ////////////////////////////////////////////////////////////////////
00092 void BulletTriangleMeshShape::
00093 refit_tree(const LPoint3 &aabb_min, const LPoint3 &aabb_max) {
00094 
00095   nassertv(!aabb_max.is_nan());
00096   nassertv(!aabb_max.is_nan());
00097 
00098   nassertv(this->is_static());
00099 
00100   _bvh_shape->refitTree(LVecBase3_to_btVector3(aabb_min),
00101                         LVecBase3_to_btVector3(aabb_max));
00102 }
00103 
 All Classes Functions Variables Enumerations