Browse Source

Bullet: exposing bounds for single shape and all shapes.

enn0x 11 years ago
parent
commit
d658ba7254

+ 32 - 0
panda/src/bullet/bulletBodyNode.cxx

@@ -668,3 +668,35 @@ set_transform_dirty() {
   transform_changed();
   transform_changed();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: BulletBodyNode::get_shape_bounds
+//       Access: Published
+//  Description: Returns the current bounds of all collision shapes
+//               owned by this body.
+////////////////////////////////////////////////////////////////////
+BoundingSphere BulletBodyNode::
+get_shape_bounds() const {
+
+/*
+  btTransform tr;
+  tr.setIdentity();
+  btVector3 aabbMin,aabbMax;
+  ptr()->getAabb(tr,aabbMin,aabbMax);
+  btVector3 o = tr.getOrigin();
+cout << "aabbMin " << aabbMin.x() << " " << aabbMin.y() << " " << aabbMin.z() << endl;
+cout << "aabbMax " << aabbMax.x() << " " << aabbMax.y() << " " << aabbMax.z() << endl;
+cout << "origin " << aabbMin.x() << " " << aabbMin.y() << " " << aabbMin.z() << endl;
+*/
+
+  btVector3 center;
+  btScalar radius;
+
+  if (_shape) {
+    _shape->getBoundingSphere(center, radius);
+  }
+
+  BoundingSphere bounds(btVector3_to_LPoint3(center), (PN_stdfloat)radius);
+
+  return bounds;
+}
+

+ 2 - 0
panda/src/bullet/bulletBodyNode.h

@@ -24,6 +24,7 @@
 #include "collideMask.h"
 #include "collideMask.h"
 #include "collisionNode.h"
 #include "collisionNode.h"
 #include "transformState.h"
 #include "transformState.h"
+#include "boundingSphere.h"
 
 
 class BulletShape;
 class BulletShape;
 
 
@@ -47,6 +48,7 @@ PUBLISHED:
 
 
   LPoint3 get_shape_pos(int idx) const;
   LPoint3 get_shape_pos(int idx) const;
   LMatrix4 get_shape_mat(int idx) const;
   LMatrix4 get_shape_mat(int idx) const;
+  BoundingSphere get_shape_bounds() const;
 
 
   void add_shapes_from_collision_solids(CollisionNode *cnode);
   void add_shapes_from_collision_solids(CollisionNode *cnode);
 
 

+ 2 - 2
panda/src/bullet/bulletShape.cxx

@@ -74,12 +74,12 @@ set_local_scale(const LVecBase3 &scale) {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: BulletShape::get_bounds
+//     Function: BulletShape::get_shape_bounds
 //       Access: Published
 //       Access: Published
 //  Description: Returns the current bounds of this collision shape.
 //  Description: Returns the current bounds of this collision shape.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 BoundingSphere BulletShape::
 BoundingSphere BulletShape::
-get_bounds() const {
+get_shape_bounds() const {
 
 
 /*
 /*
   btTransform tr;
   btTransform tr;

+ 1 - 1
panda/src/bullet/bulletShape.h

@@ -44,7 +44,7 @@ PUBLISHED:
 
 
   PN_stdfloat get_margin() const;
   PN_stdfloat get_margin() const;
 
 
-  BoundingSphere get_bounds() const;
+  BoundingSphere get_shape_bounds() const;
 
 
 public:
 public:
   virtual btCollisionShape *ptr() const = 0;
   virtual btCollisionShape *ptr() const = 0;