From a343eef6b1e7a1dee1be9cfe054220ffc1a9d7e3 Mon Sep 17 00:00:00 2001 From: enn0x Date: Wed, 14 Aug 2013 23:31:42 +0000 Subject: [PATCH] Adding minkowski sum shape. --- dtool/src/parser-inc/btBulletDynamicsCommon.h | 1 + panda/src/bullet/Sources.pp | 3 + panda/src/bullet/bulletMinkowskiSumShape.I | 128 ++++++++++++++++++ panda/src/bullet/bulletMinkowskiSumShape.cxx | 50 +++++++ panda/src/bullet/bulletMinkowskiSumShape.h | 81 +++++++++++ panda/src/bullet/bullet_includes.h | 1 + panda/src/bullet/config_bullet.cxx | 2 + panda/src/bullet/p3bullet_composite.cxx | 1 + 8 files changed, 267 insertions(+) create mode 100644 panda/src/bullet/bulletMinkowskiSumShape.I create mode 100644 panda/src/bullet/bulletMinkowskiSumShape.cxx create mode 100644 panda/src/bullet/bulletMinkowskiSumShape.h diff --git a/dtool/src/parser-inc/btBulletDynamicsCommon.h b/dtool/src/parser-inc/btBulletDynamicsCommon.h index 7eb3c80cd5..e0086678f2 100644 --- a/dtool/src/parser-inc/btBulletDynamicsCommon.h +++ b/dtool/src/parser-inc/btBulletDynamicsCommon.h @@ -51,6 +51,7 @@ class btManifoldArray; class btManifoldPoint; class btMatrix3x3; class btMotionState; +class btMinkowskiSumShape; class btMultiSphereShape; class btOverlapFilterCallback; class btPairCachingGhostObject; diff --git a/panda/src/bullet/Sources.pp b/panda/src/bullet/Sources.pp index 8ecccf57ea..b45e95395b 100644 --- a/panda/src/bullet/Sources.pp +++ b/panda/src/bullet/Sources.pp @@ -35,6 +35,7 @@ bulletHelper.h bulletHelper.I \ bulletHingeConstraint.h bulletHingeConstraint.I \ bulletManifoldPoint.h bulletManifoldPoint.I \ + bulletMinkowskiSumShape.h bulletMinkowskiSumShape.I \ bulletMultiSphereShape.h bulletMultiSphereShape.I \ bulletPersistentManifold.h bulletPersistentManifold.I \ bulletPlaneShape.h bulletPlaneShape.I \ @@ -84,6 +85,7 @@ bulletHelper.cxx \ bulletHingeConstraint.cxx \ bulletManifoldPoint.cxx \ + bulletMinkowskiSumShape.cxx \ bulletMultiSphereShape.cxx \ bulletPersistentManifold.cxx \ bulletPlaneShape.cxx \ @@ -133,6 +135,7 @@ bulletHelper.h bulletHelper.I \ bulletHingeConstraint.h bulletHingeConstraint.I \ bulletManifoldPoint.h bulletManifoldPoint.I \ + bulletMinkowskiSumShape.h bulletMinkowskiSumShape.I \ bulletMultiSphereShape.h bulletMultiSphereShape.I \ bulletPersistentManifold.h bulletPersistentManifold.I \ bulletPlaneShape.h bulletPlaneShape.I \ diff --git a/panda/src/bullet/bulletMinkowskiSumShape.I b/panda/src/bullet/bulletMinkowskiSumShape.I new file mode 100644 index 0000000000..c0f718fbf9 --- /dev/null +++ b/panda/src/bullet/bulletMinkowskiSumShape.I @@ -0,0 +1,128 @@ +// Filename: bulletMinkowskiSumShape.I +// Created by: enn0x (23Jan10) +// +//////////////////////////////////////////////////////////////////// +// +// 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: BulletMinkowskiSumShape::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE BulletMinkowskiSumShape:: +~BulletMinkowskiSumShape() { + + delete _shape; +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::Copy Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE BulletMinkowskiSumShape:: +BulletMinkowskiSumShape(const BulletMinkowskiSumShape ©) : + _shape(copy._shape), + _shape_a(copy._shape_a), + _shape_b(copy._shape_b) { +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::Copy Assignment Operator +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void BulletMinkowskiSumShape:: +operator = (const BulletMinkowskiSumShape ©) { + _shape = copy._shape; + _shape_a = copy._shape_a; + _shape_b = copy._shape_b; +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::set_transform_a +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void BulletMinkowskiSumShape:: +set_transform_a(const TransformState *ts) { + + nassertv(ts); + _shape->setTransformA(TransformState_to_btTrans(ts)); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::set_transform_b +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void BulletMinkowskiSumShape:: +set_transform_b(const TransformState *ts) { + + nassertv(ts); + _shape->setTransformB(TransformState_to_btTrans(ts)); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::get_transform_a +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletMinkowskiSumShape:: +get_transform_a() const { + + return btTrans_to_TransformState(_shape->getTransformA()); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::get_transform_b +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE CPT(TransformState) BulletMinkowskiSumShape:: +get_transform_b() const { + + return btTrans_to_TransformState(_shape->GetTransformB()); +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::get_shape_a +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE const BulletShape *BulletMinkowskiSumShape:: +get_shape_a() const { + + return _shape_a; +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::get_shape_b +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE const BulletShape *BulletMinkowskiSumShape:: +get_shape_b() const { + + return _shape_b; +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::get_margin +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE PN_stdfloat BulletMinkowskiSumShape:: +get_margin() const { + + return (PN_stdfloat)_shape->getMargin(); +} + diff --git a/panda/src/bullet/bulletMinkowskiSumShape.cxx b/panda/src/bullet/bulletMinkowskiSumShape.cxx new file mode 100644 index 0000000000..0b95ea9736 --- /dev/null +++ b/panda/src/bullet/bulletMinkowskiSumShape.cxx @@ -0,0 +1,50 @@ +// Filename: bulletMinkowskiSumShape.cxx +// Created by: enn0x (15Aug13) +// +//////////////////////////////////////////////////////////////////// +// +// 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 "bulletMinkowskiSumShape.h" + +TypeHandle BulletMinkowskiSumShape::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +BulletMinkowskiSumShape:: +BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b) { + + nassertv(shape_a->is_convex()); + nassertv(shape_b->is_convex()); + + const btConvexShape *ptr_a = (const btConvexShape *)shape_a->ptr(); + const btConvexShape *ptr_b = (const btConvexShape *)shape_b->ptr(); + + _shape = new btMinkowskiSumShape(ptr_a, ptr_b); + _shape->setUserPointer(this); + + _shape_a = shape_a; + _shape_b = shape_b; +} + +//////////////////////////////////////////////////////////////////// +// Function: BulletMinkowskiSumShape::ptr +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +btCollisionShape *BulletMinkowskiSumShape:: +ptr() const { + + return _shape; +} + diff --git a/panda/src/bullet/bulletMinkowskiSumShape.h b/panda/src/bullet/bulletMinkowskiSumShape.h new file mode 100644 index 0000000000..8b0eb0ecbe --- /dev/null +++ b/panda/src/bullet/bulletMinkowskiSumShape.h @@ -0,0 +1,81 @@ +// Filename: bulletMinkowskiSumShape.h +// Created by: enn0x (15Aug13) +// +//////////////////////////////////////////////////////////////////// +// +// 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_MINKOWSKI_SUM_SHAPE_H__ +#define __BULLET_MINKOWSKI_SUM_SHAPE_H__ + +#include "pandabase.h" + +#include "bullet_includes.h" +#include "bullet_utils.h" +#include "bulletShape.h" + +#include "transformState.h" + +//////////////////////////////////////////////////////////////////// +// Class : BulletMinkowskiSumShape +// Description : +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDABULLET BulletMinkowskiSumShape : public BulletShape { + +PUBLISHED: + BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b); + INLINE BulletMinkowskiSumShape(const BulletMinkowskiSumShape ©); + INLINE void operator = (const BulletMinkowskiSumShape ©); + INLINE ~BulletMinkowskiSumShape(); + + INLINE void set_transform_a(const TransformState *ts); + INLINE void set_transform_b(const TransformState *ts); + INLINE CPT(TransformState) get_transform_a() const; + INLINE CPT(TransformState) get_transform_b() const; + + INLINE const BulletShape *get_shape_a() const; + INLINE const BulletShape *get_shape_b() const; + + INLINE PN_stdfloat get_margin() const; + +public: + virtual btCollisionShape *ptr() const; + +private: + btMinkowskiSumShape *_shape; + + CPT(BulletShape) _shape_a; + CPT(BulletShape) _shape_b; + +//////////////////////////////////////////////////////////////////// +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + BulletShape::init_type(); + register_type(_type_handle, "BulletMinkowskiSumShape", + 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 "bulletMinkowskiSumShape.I" + +#endif // __BULLET_MINKOWSKI_SUM_SHAPE_H__ diff --git a/panda/src/bullet/bullet_includes.h b/panda/src/bullet/bullet_includes.h index 5ea9af67f1..14c13c8f21 100644 --- a/panda/src/bullet/bullet_includes.h +++ b/panda/src/bullet/bullet_includes.h @@ -25,6 +25,7 @@ #include "BulletCollision/CollisionDispatch/btManifoldResult.h" #include "BulletCollision/CollisionShapes/btConvexPointCloudShape.h" #include "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h" +#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h" #include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h" #include "BulletCollision/Gimpact/btGImpactShape.h" #include "BulletDynamics/Character/btKinematicCharacterController.h" diff --git a/panda/src/bullet/config_bullet.cxx b/panda/src/bullet/config_bullet.cxx index 8f9c069906..620b7b71e0 100644 --- a/panda/src/bullet/config_bullet.cxx +++ b/panda/src/bullet/config_bullet.cxx @@ -26,6 +26,7 @@ #include "bulletConvexHullShape.h" #include "bulletConvexPointCloudShape.h" #include "bulletCylinderShape.h" +#include "bulletMinkowskiSumShape.h" #include "bulletDebugNode.h" #include "bulletFilterCallbackData.h" #include "bulletGenericConstraint.h" @@ -159,6 +160,7 @@ init_libbullet() { BulletConvexHullShape::init_type(); BulletConvexPointCloudShape::init_type(); BulletCylinderShape::init_type(); + BulletMinkowskiSumShape::init_type(); BulletDebugNode::init_type(); BulletFilterCallbackData::init_type(); BulletGenericConstraint::init_type(); diff --git a/panda/src/bullet/p3bullet_composite.cxx b/panda/src/bullet/p3bullet_composite.cxx index 0a17d1ea29..209bf3c6cf 100644 --- a/panda/src/bullet/p3bullet_composite.cxx +++ b/panda/src/bullet/p3bullet_composite.cxx @@ -24,6 +24,7 @@ #include "bulletHeightfieldShape.cxx" #include "bulletHingeConstraint.cxx" #include "bulletManifoldPoint.cxx" +#include "bulletMinkowskiSumShape.cxx" #include "bulletMultiSphereShape.cxx" #include "bulletPersistentManifold.cxx" #include "bulletPlaneShape.cxx"