diff --git a/dtool/src/parser-inc/btBulletDynamicsCommon.h b/dtool/src/parser-inc/btBulletDynamicsCommon.h index 44bda05a04..77a0925dc1 100644 --- a/dtool/src/parser-inc/btBulletDynamicsCommon.h +++ b/dtool/src/parser-inc/btBulletDynamicsCommon.h @@ -49,6 +49,7 @@ class btKinematicCharacterController; class btManifoldPoint; class btMatrix3x3; class btMotionState; +class btMultiSphereShape; class btOverlapFilterCallback; class btPairCachingGhostObject; class btParalleSequentialImpulseSolver; diff --git a/panda/src/bullet/bulletMultiSphereShape.I b/panda/src/bullet/bulletMultiSphereShape.I new file mode 100644 index 0000000000..49087c5b63 --- /dev/null +++ b/panda/src/bullet/bulletMultiSphereShape.I @@ -0,0 +1,60 @@ +// Filename: bulletMultiSphereShape.I +// Created by: enn0x (04Jan12) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Function: BulletMultiSphereShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE BulletMultiSphereShape:: +~BulletMultiSphereShape() { + + delete _shape; +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMultiSphereShape::get_sphere_count +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE int BulletMultiSphereShape:: +get_sphere_count() const { + + return _shape->getSphereCount(); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMultiSphereShape::get_sphere_pos +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE LPoint3 BulletMultiSphereShape:: +get_sphere_pos(int index) const { + + nassertr(index >=0 && index <_shape->getSphereCount(), LPoint3::zero()); + return btVector3_to_LPoint3(_shape->getSpherePosition(index)); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMultiSphereShape::get_sphere_radius +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PN_stdfloat BulletMultiSphereShape:: +get_sphere_radius(int index) const { + + nassertr(index >=0 && index <_shape->getSphereCount(), 0.0); + return (PN_stdfloat)_shape->getSphereRadius(index); +} + diff --git a/panda/src/bullet/bulletMultiSphereShape.cxx b/panda/src/bullet/bulletMultiSphereShape.cxx new file mode 100644 index 0000000000..3c6951340e --- /dev/null +++ b/panda/src/bullet/bulletMultiSphereShape.cxx @@ -0,0 +1,58 @@ +// Filename: bulletMultiSphereShape.cxx +// Created by: enn0x (05Jan12) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "bulletMultiSphereShape.h" + +#include "geomVertexReader.h" + +TypeHandle BulletMultiSphereShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: BulletMultiSphereShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +BulletMultiSphereShape:: +BulletMultiSphereShape(const PTA_LVecBase3 &points, const PTA_stdfloat &radii) { + + int num_spheres = min(points.size(), radii.size()); + + // Convert points + btVector3 *bt_points = new btVector3[num_spheres]; + for (int i=0; isetUserPointer(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMultiSphereShape::ptr +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +btCollisionShape *BulletMultiSphereShape:: +ptr() const { + + return _shape; +} + diff --git a/panda/src/bullet/bulletMultiSphereShape.h b/panda/src/bullet/bulletMultiSphereShape.h new file mode 100644 index 0000000000..676877e125 --- /dev/null +++ b/panda/src/bullet/bulletMultiSphereShape.h @@ -0,0 +1,70 @@ +// Filename: bulletMultiSphereShape.h +// Created by: enn0x (04Jan12) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef __BULLET_MULTI_SPHERE_SHAPE_H__ +#define __BULLET_MULTI_SPHERE_SHAPE_H__ + +#include "pandabase.h" + +#include "bullet_includes.h" +#include "bulletShape.h" + +#include "pta_LVecBase3.h" +#include "pta_stdfloat.h" + +//////////////////////////////////////////////////////////////////// +// Class : BulletMultiSphereShape +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDABULLET BulletMultiSphereShape : public BulletShape { + +PUBLISHED: + BulletMultiSphereShape(const PTA_LVecBase3 &points, const PTA_stdfloat &radii); + INLINE ~BulletMultiSphereShape(); + + INLINE int get_sphere_count() const; + INLINE LPoint3 get_sphere_pos(int index) const; + INLINE PN_stdfloat get_sphere_radius(int index) const; + +public: + virtual btCollisionShape *ptr() const; + +private: + btMultiSphereShape *_shape; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + BulletShape::init_type(); + register_type(_type_handle, "BulletMultiSphereShape", + BulletShape::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() { + init_type(); + return get_class_type(); + } + +private: + static TypeHandle _type_handle; +}; + +#include "bulletMultiSphereShape.I" + +#endif // __BULLET_MULTI_SPHERE_SHAPE_H__ diff --git a/panda/src/bullet/config_bullet.cxx b/panda/src/bullet/config_bullet.cxx index b2e8448dfb..d4a4175d43 100644 --- a/panda/src/bullet/config_bullet.cxx +++ b/panda/src/bullet/config_bullet.cxx @@ -29,6 +29,7 @@ #include "bulletGhostNode.h" #include "bulletHeightfieldShape.h" #include "bulletHingeConstraint.h" +#include "bulletMultiSphereShape.h" #include "bulletPlaneShape.h" #include "bulletRigidBodyNode.h" #include "bulletShape.h" @@ -159,6 +160,7 @@ init_libbullet() { BulletGhostNode::init_type(); BulletHeightfieldShape::init_type(); BulletHingeConstraint::init_type(); + BulletMultiSphereShape::init_type(); BulletPlaneShape::init_type(); BulletRigidBodyNode::init_type(); BulletShape::init_type(); diff --git a/panda/src/bullet/p3bullet_composite.cxx b/panda/src/bullet/p3bullet_composite.cxx index 3615829ff4..88de24c4ac 100644 --- a/panda/src/bullet/p3bullet_composite.cxx +++ b/panda/src/bullet/p3bullet_composite.cxx @@ -21,6 +21,7 @@ #include "bulletHeightfieldShape.cxx" #include "bulletHingeConstraint.cxx" #include "bulletManifoldPoint.cxx" +#include "bulletMultiSphereShape.cxx" #include "bulletPersistentManifold.cxx" #include "bulletPlaneShape.cxx" #include "bulletRigidBodyNode.cxx"