Panda3D
 All Classes Functions Variables Enumerations
bulletConvexHullShape.cxx
00001 // Filename: bulletConvexHullShape.cxx
00002 // Created by:  enn0x (26Jan10)
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 "bulletConvexHullShape.h"
00016 
00017 #include "nodePathCollection.h"
00018 #include "geomNode.h"
00019 #include "geomVertexReader.h"
00020 
00021 TypeHandle BulletConvexHullShape::_type_handle;
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //     Function: BulletConvexHullShape::Constructor
00025 //       Access: Published
00026 //  Description:
00027 ////////////////////////////////////////////////////////////////////
00028 BulletConvexHullShape::
00029 BulletConvexHullShape() {
00030 
00031   _shape = new btConvexHullShape(NULL, 0);
00032   _shape->setUserPointer(this);
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: BulletConvexHullShape::ptr
00037 //       Access: Public
00038 //  Description:
00039 ////////////////////////////////////////////////////////////////////
00040 btCollisionShape *BulletConvexHullShape::
00041 ptr() const {
00042 
00043   return _shape;
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: BulletConvexHullShape::add_point
00048 //       Access: Published
00049 //  Description:
00050 ////////////////////////////////////////////////////////////////////
00051 void BulletConvexHullShape::
00052 add_point(const LPoint3 &p) {
00053 
00054   _shape->addPoint(LVecBase3_to_btVector3(p));
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: BulletConvexHullShape::Constructor
00059 //       Access: Published
00060 //  Description:
00061 ////////////////////////////////////////////////////////////////////
00062 void BulletConvexHullShape::
00063 add_array(const PTA_LVecBase3 &points) {
00064 
00065   _shape = new btConvexHullShape(NULL, 0);
00066   _shape->setUserPointer(this);
00067 
00068   PTA_LVecBase3::const_iterator it;
00069   for (it=points.begin(); it!=points.end(); it++) {
00070     LVecBase3 v = *it;
00071     _shape->addPoint(LVecBase3_to_btVector3(v));
00072   }
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: BulletConvexHullShape::Constructor
00077 //       Access: Published
00078 //  Description:
00079 ////////////////////////////////////////////////////////////////////
00080 void BulletConvexHullShape::
00081 add_geom(const Geom *geom) {
00082 
00083   // Collect points
00084   pvector<LPoint3> points;
00085 
00086   CPT(GeomVertexData) vdata = geom->get_vertex_data();
00087   GeomVertexReader reader = GeomVertexReader(vdata, InternalName::get_vertex());
00088 
00089   while (!reader.is_at_end()) {
00090     points.push_back(reader.get_data3());
00091   }
00092 
00093   // Create shape
00094   _shape = new btConvexHullShape(NULL, 0);
00095   _shape->setUserPointer(this);
00096 
00097   pvector<LPoint3>::const_iterator it;
00098   for (it=points.begin(); it!=points.end(); it++) {
00099     _shape->addPoint(LVecBase3_to_btVector3(*it));
00100   }
00101 }
00102 
 All Classes Functions Variables Enumerations