20 TypeHandle BulletMultiSphereShape::_type_handle;
25 BulletMultiSphereShape::
26 BulletMultiSphereShape(
const PTA_LVecBase3 &points,
const PTA_stdfloat &radii) {
28 int num_spheres = std::min(points.size(), radii.size());
31 btVector3 *bt_points =
new btVector3[num_spheres];
32 for (
int i=0; i<num_spheres; i++) {
33 bt_points[i] = LVecBase3_to_btVector3(points[i]);
37 btScalar *bt_radii =
new btScalar[num_spheres];
38 for (
int j=0; j<num_spheres; j++) {
39 bt_radii[j] = (PN_stdfloat)radii[j];
43 _shape =
new btMultiSphereShape(bt_points, bt_radii, num_spheres);
44 _shape->setUserPointer(
this);
50 BulletMultiSphereShape::
60 void BulletMultiSphereShape::
70 btCollisionShape *BulletMultiSphereShape::
79 int BulletMultiSphereShape::
80 get_sphere_count()
const {
83 return _shape->getSphereCount();
89 LPoint3 BulletMultiSphereShape::
90 get_sphere_pos(
int index)
const {
93 nassertr(index >=0 && index <_shape->getSphereCount(), LPoint3::zero());
94 return btVector3_to_LPoint3(_shape->getSpherePosition(index));
100 PN_stdfloat BulletMultiSphereShape::
101 get_sphere_radius(
int index)
const {
104 nassertr(index >=0 && index <_shape->getSphereCount(), 0.0);
105 return (PN_stdfloat)_shape->getSphereRadius(index);
127 for (
int i = 0; i < get_sphere_count(); ++i){
128 get_sphere_pos(i).write_datagram(dg);
131 for (
int i = 0; i < get_sphere_count(); ++i){
149 param->fillin(scan, manager);
158 void BulletMultiSphereShape::
161 nassertv(_shape ==
nullptr);
167 btVector3 *positions =
new btVector3[sphereCount];
168 for (
int i = 0; i < sphereCount; ++i){
170 pos.read_datagram(scan);
171 positions[i] = LVecBase3_to_btVector3(pos);
174 btScalar *radii =
new btScalar[sphereCount];
175 for (
int i = 0; i < sphereCount; ++i){
179 _shape =
new btMultiSphereShape(positions, radii, sphereCount);
180 _shape->setUserPointer(
this);
181 _shape->setMargin(margin);