mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
bullet: allow creation of BulletCapsuleShape from CollisionTube
This commit is contained in:
parent
d4d582484f
commit
fd227f6492
@ -20,6 +20,7 @@
|
|||||||
#include "collisionPlane.h"
|
#include "collisionPlane.h"
|
||||||
#include "collisionSphere.h"
|
#include "collisionSphere.h"
|
||||||
#include "collisionPolygon.h"
|
#include "collisionPolygon.h"
|
||||||
|
#include "collisionTube.h"
|
||||||
|
|
||||||
TypeHandle BulletBodyNode::_type_handle;
|
TypeHandle BulletBodyNode::_type_handle;
|
||||||
|
|
||||||
@ -804,6 +805,14 @@ add_shapes_from_collision_solids(CollisionNode *cnode) {
|
|||||||
do_add_shape(BulletBoxShape::make_from_solid(box), ts);
|
do_add_shape(BulletBoxShape::make_from_solid(box), ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CollisionTube
|
||||||
|
else if (CollisionTube::get_class_type() == type) {
|
||||||
|
CPT(CollisionTube) tube = DCAST(CollisionTube, solid);
|
||||||
|
CPT(TransformState) ts = TransformState::make_pos((tube->get_point_b() + tube->get_point_a()) / 2.0);
|
||||||
|
|
||||||
|
do_add_shape(BulletCapsuleShape::make_from_solid(tube), ts);
|
||||||
|
}
|
||||||
|
|
||||||
// CollisionPlane
|
// CollisionPlane
|
||||||
else if (CollisionPlane::get_class_type() == type) {
|
else if (CollisionPlane::get_class_type() == type) {
|
||||||
CPT(CollisionPlane) plane = DCAST(CollisionPlane, solid);
|
CPT(CollisionPlane) plane = DCAST(CollisionPlane, solid);
|
||||||
|
@ -82,6 +82,22 @@ ptr() const {
|
|||||||
return _shape;
|
return _shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new BulletCapsuleShape using the information from a
|
||||||
|
* CollisionTube from the builtin collision system.
|
||||||
|
*/
|
||||||
|
BulletCapsuleShape *BulletCapsuleShape::
|
||||||
|
make_from_solid(const CollisionTube *solid) {
|
||||||
|
|
||||||
|
PN_stdfloat radius = solid->get_radius();
|
||||||
|
// CollisionTube height includes the hemispheres, Bullet only wants the cylinder height.
|
||||||
|
PN_stdfloat height = (solid->get_point_b() - solid->get_point_a()).length() - (radius * 2);
|
||||||
|
|
||||||
|
// CollisionTubes are always Z-Up.
|
||||||
|
return new BulletCapsuleShape(radius, height, Z_up);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells the BamReader how to create objects of type BulletShape.
|
* Tells the BamReader how to create objects of type BulletShape.
|
||||||
*/
|
*/
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
#include "bullet_utils.h"
|
#include "bullet_utils.h"
|
||||||
#include "bulletShape.h"
|
#include "bulletShape.h"
|
||||||
|
|
||||||
|
#include "collisionTube.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -33,6 +35,8 @@ PUBLISHED:
|
|||||||
BulletCapsuleShape(const BulletCapsuleShape ©);
|
BulletCapsuleShape(const BulletCapsuleShape ©);
|
||||||
INLINE ~BulletCapsuleShape();
|
INLINE ~BulletCapsuleShape();
|
||||||
|
|
||||||
|
static BulletCapsuleShape *make_from_solid(const CollisionTube *solid);
|
||||||
|
|
||||||
INLINE PN_stdfloat get_radius() const;
|
INLINE PN_stdfloat get_radius() const;
|
||||||
INLINE PN_stdfloat get_half_height() const;
|
INLINE PN_stdfloat get_half_height() const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user