Bullet: exposing bounds for single shape and all shapes.

This commit is contained in:
enn0x 2014-08-06 22:35:15 +00:00
parent aaca66cdc1
commit d658ba7254
4 changed files with 37 additions and 3 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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;