Преглед на файлове

Added wrapper for btMultiSphereShape.

enn0x преди 14 години
родител
ревизия
e68cb77e4a

+ 1 - 0
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;

+ 60 - 0
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);
+}
+

+ 58 - 0
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; i<num_spheres; i++) {
+    bt_points[i] = LVecBase3_to_btVector3(points[i]);
+  }
+
+  // Convert radii
+  btScalar *bt_radii = new btScalar[num_spheres];
+  for (int j=0; j<num_spheres; j++) {
+    bt_radii[j] = (PN_stdfloat)radii[j];
+  }
+
+  // Create shape
+  _shape = new btMultiSphereShape(bt_points, bt_radii, num_spheres);
+  _shape->setUserPointer(this);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: BulletMultiSphereShape::ptr
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+btCollisionShape *BulletMultiSphereShape::
+ptr() const {
+
+  return _shape;
+}
+

+ 70 - 0
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__

+ 2 - 0
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();

+ 1 - 0
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"