mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
bullet: add bam serializability of remaining shapes
From #123 with significant changes from rdb. Closes: #123
This commit is contained in:
parent
b8bf8bd641
commit
e13d14fe3d
@ -11,6 +11,15 @@
|
||||
* @date 2010-01-24
|
||||
*/
|
||||
|
||||
/**
|
||||
* Only used by make_from_bam.
|
||||
*/
|
||||
INLINE BulletBoxShape::
|
||||
BulletBoxShape() :
|
||||
_shape(nullptr),
|
||||
_half_extents(LVecBase3::zero()) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -25,7 +34,7 @@ INLINE BulletBoxShape::
|
||||
*/
|
||||
INLINE BulletBoxShape::
|
||||
BulletBoxShape(const BulletBoxShape ©) :
|
||||
_shape(copy._shape) {
|
||||
_shape(copy._shape), _half_extents(copy._half_extents) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,4 +43,5 @@ BulletBoxShape(const BulletBoxShape ©) :
|
||||
INLINE void BulletBoxShape::
|
||||
operator = (const BulletBoxShape ©) {
|
||||
_shape = copy._shape;
|
||||
_half_extents = copy._half_extents;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ TypeHandle BulletBoxShape::_type_handle;
|
||||
*
|
||||
*/
|
||||
BulletBoxShape::
|
||||
BulletBoxShape(const LVecBase3 &halfExtents) {
|
||||
BulletBoxShape(const LVecBase3 &halfExtents) : _half_extents(halfExtents) {
|
||||
|
||||
btVector3 btHalfExtents = LVecBase3_to_btVector3(halfExtents);
|
||||
|
||||
@ -85,8 +85,9 @@ register_with_read_factory() {
|
||||
*/
|
||||
void BulletBoxShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
dg.add_stdfloat(get_margin());
|
||||
get_half_extents_with_margin().write_datagram(dg);
|
||||
_half_extents.write_datagram(dg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,14 +113,14 @@ make_from_bam(const FactoryParams ¶ms) {
|
||||
*/
|
||||
void BulletBoxShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
nassertv(_shape == NULL);
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
|
||||
LVector3 half_extents;
|
||||
half_extents.read_datagram(scan);
|
||||
_half_extents.read_datagram(scan);
|
||||
|
||||
_shape = new btBoxShape(LVecBase3_to_btVector3(half_extents));
|
||||
_shape = new btBoxShape(LVecBase3_to_btVector3(_half_extents));
|
||||
_shape->setUserPointer(this);
|
||||
_shape->setMargin(margin);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
class EXPCL_PANDABULLET BulletBoxShape : public BulletShape {
|
||||
private:
|
||||
// Only used by make_from_bam
|
||||
INLINE BulletBoxShape() : _shape(NULL) {};
|
||||
INLINE BulletBoxShape();
|
||||
|
||||
PUBLISHED:
|
||||
explicit BulletBoxShape(const LVecBase3 &halfExtents);
|
||||
@ -50,6 +50,7 @@ public:
|
||||
|
||||
private:
|
||||
btBoxShape *_shape;
|
||||
LVecBase3 _half_extents;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
|
@ -11,6 +11,16 @@
|
||||
* @date 2010-01-27
|
||||
*/
|
||||
|
||||
/**
|
||||
* Only used by make_from_bam.
|
||||
*/
|
||||
INLINE BulletCapsuleShape::
|
||||
BulletCapsuleShape() :
|
||||
_shape(nullptr),
|
||||
_radius(0),
|
||||
_height(0) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -25,7 +35,9 @@ INLINE BulletCapsuleShape::
|
||||
*/
|
||||
INLINE BulletCapsuleShape::
|
||||
BulletCapsuleShape(const BulletCapsuleShape ©) :
|
||||
_shape(copy._shape) {
|
||||
_shape(copy._shape),
|
||||
_radius(copy._radius),
|
||||
_height(copy._height) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,22 +46,31 @@ BulletCapsuleShape(const BulletCapsuleShape ©) :
|
||||
INLINE void BulletCapsuleShape::
|
||||
operator = (const BulletCapsuleShape ©) {
|
||||
_shape = copy._shape;
|
||||
_radius = copy._radius;
|
||||
_height = copy._height;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns the radius that was used to construct this capsule.
|
||||
*/
|
||||
INLINE PN_stdfloat BulletCapsuleShape::
|
||||
get_radius() const {
|
||||
|
||||
return (PN_stdfloat)_shape->getRadius();
|
||||
return _radius;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns half of get_height().
|
||||
* @deprecated see get_height() instead.
|
||||
*/
|
||||
INLINE PN_stdfloat BulletCapsuleShape::
|
||||
get_half_height() const {
|
||||
|
||||
return (PN_stdfloat)_shape->getHalfHeight();
|
||||
return _height * 0.5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height that was used to construct this capsule.
|
||||
*/
|
||||
INLINE PN_stdfloat BulletCapsuleShape::
|
||||
get_height() const {
|
||||
return _height;
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ TypeHandle BulletCapsuleShape::_type_handle;
|
||||
*
|
||||
*/
|
||||
BulletCapsuleShape::
|
||||
BulletCapsuleShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) {
|
||||
BulletCapsuleShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) :
|
||||
_radius(radius),
|
||||
_height(height) {
|
||||
|
||||
switch (up) {
|
||||
case X_up:
|
||||
@ -47,3 +49,79 @@ ptr() const {
|
||||
|
||||
return _shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the BamReader how to create objects of type BulletShape.
|
||||
*/
|
||||
void BulletCapsuleShape::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void BulletCapsuleShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
dg.add_stdfloat(get_margin());
|
||||
|
||||
// parameters to serialize: radius, height, up
|
||||
dg.add_stdfloat(_radius);
|
||||
dg.add_stdfloat(_height);
|
||||
dg.add_int8((int8_t)_shape->getUpAxis());
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the BamReader's factory when a new object of
|
||||
* type BulletShape is encountered in the Bam file. It should create the
|
||||
* BulletShape and extract its information from the file.
|
||||
*/
|
||||
TypedWritable *BulletCapsuleShape::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
// create a default BulletCapsuleShape
|
||||
BulletCapsuleShape *param = new BulletCapsuleShape;
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
param->fillin(scan, manager);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new BulletShape.
|
||||
*/
|
||||
void BulletCapsuleShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
|
||||
// parameters to serialize: radius, height, up
|
||||
_radius = scan.get_stdfloat();
|
||||
_height = scan.get_stdfloat();
|
||||
int up = (int) scan.get_int8();
|
||||
|
||||
switch (up) {
|
||||
case X_up:
|
||||
_shape = new btCapsuleShapeX(_radius, _height);
|
||||
break;
|
||||
case Y_up:
|
||||
_shape = new btCapsuleShape(_radius, _height);
|
||||
break;
|
||||
case Z_up:
|
||||
_shape = new btCapsuleShapeZ(_radius, _height);
|
||||
break;
|
||||
default:
|
||||
bullet_cat.error() << "invalid up-axis:" << up << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
_shape->setUserPointer(this);
|
||||
_shape->setMargin(margin);
|
||||
}
|
||||
|
@ -24,6 +24,10 @@
|
||||
*
|
||||
*/
|
||||
class EXPCL_PANDABULLET BulletCapsuleShape : public BulletShape {
|
||||
private:
|
||||
// Only used by make_from_bam
|
||||
INLINE BulletCapsuleShape();
|
||||
|
||||
PUBLISHED:
|
||||
explicit BulletCapsuleShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up=Z_up);
|
||||
INLINE BulletCapsuleShape(const BulletCapsuleShape ©);
|
||||
@ -33,14 +37,27 @@ PUBLISHED:
|
||||
INLINE PN_stdfloat get_radius() const;
|
||||
INLINE PN_stdfloat get_half_height() const;
|
||||
|
||||
MAKE_PROPERTY(radius, get_radius);
|
||||
MAKE_PROPERTY(half_height, get_half_height);
|
||||
|
||||
public:
|
||||
INLINE PN_stdfloat get_height() const;
|
||||
|
||||
virtual btCollisionShape *ptr() const;
|
||||
|
||||
PUBLISHED:
|
||||
MAKE_PROPERTY(radius, get_radius);
|
||||
MAKE_PROPERTY(height, get_height);
|
||||
|
||||
private:
|
||||
btCapsuleShape *_shape;
|
||||
PN_stdfloat _radius;
|
||||
PN_stdfloat _height;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
@ -11,6 +11,16 @@
|
||||
* @date 2010-01-24
|
||||
*/
|
||||
|
||||
/**
|
||||
* Only used by make_from_bam.
|
||||
*/
|
||||
INLINE BulletConeShape::
|
||||
BulletConeShape() :
|
||||
_shape(nullptr),
|
||||
_radius(0),
|
||||
_height(0) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -25,7 +35,9 @@ INLINE BulletConeShape::
|
||||
*/
|
||||
INLINE BulletConeShape::
|
||||
BulletConeShape(const BulletConeShape ©) :
|
||||
_shape(copy._shape) {
|
||||
_shape(copy._shape),
|
||||
_radius(copy._radius),
|
||||
_height(copy._height) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,22 +46,22 @@ BulletConeShape(const BulletConeShape ©) :
|
||||
INLINE void BulletConeShape::
|
||||
operator = (const BulletConeShape ©) {
|
||||
_shape = copy._shape;
|
||||
_radius = copy._radius;
|
||||
_height = copy._height;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns the radius that was passed into the constructor.
|
||||
*/
|
||||
INLINE PN_stdfloat BulletConeShape::
|
||||
get_radius() const {
|
||||
|
||||
return (PN_stdfloat)_shape->getRadius();
|
||||
return _radius;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns the height that was passed into the constructor.
|
||||
*/
|
||||
INLINE PN_stdfloat BulletConeShape::
|
||||
get_height() const {
|
||||
|
||||
return (PN_stdfloat)_shape->getHeight();
|
||||
return _height;
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ TypeHandle BulletConeShape::_type_handle;
|
||||
*
|
||||
*/
|
||||
BulletConeShape::
|
||||
BulletConeShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) {
|
||||
BulletConeShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) :
|
||||
_radius(radius),
|
||||
_height(height) {
|
||||
|
||||
switch (up) {
|
||||
case X_up:
|
||||
@ -47,3 +49,79 @@ ptr() const {
|
||||
|
||||
return _shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the BamReader how to create objects of type BulletShape.
|
||||
*/
|
||||
void BulletConeShape::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void BulletConeShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
dg.add_stdfloat(get_margin());
|
||||
|
||||
// parameters to serialize: radius, height, upIndex
|
||||
dg.add_stdfloat(_radius);
|
||||
dg.add_stdfloat(_height);
|
||||
dg.add_int8((int8_t)_shape->getConeUpIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the BamReader's factory when a new object of
|
||||
* type BulletShape is encountered in the Bam file. It should create the
|
||||
* BulletShape and extract its information from the file.
|
||||
*/
|
||||
TypedWritable *BulletConeShape::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
// create a default BulletConeShape
|
||||
BulletConeShape *param = new BulletConeShape;
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
param->fillin(scan, manager);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new BulletShape.
|
||||
*/
|
||||
void BulletConeShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
|
||||
// parameters to serialize: radius, height, up
|
||||
_radius = scan.get_stdfloat();
|
||||
_height = scan.get_stdfloat();
|
||||
|
||||
int up_index = (int) scan.get_int8();
|
||||
switch (up_index) {
|
||||
case 0:
|
||||
_shape = new btConeShapeX((btScalar)_radius, (btScalar)_height);
|
||||
break;
|
||||
case 1:
|
||||
_shape = new btConeShape((btScalar)_radius, (btScalar)_height);
|
||||
break;
|
||||
case 2:
|
||||
_shape = new btConeShapeZ((btScalar)_radius, (btScalar)_height);
|
||||
break;
|
||||
default:
|
||||
bullet_cat.error() << "invalid up-axis:" << up_index << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
_shape->setUserPointer(this);
|
||||
_shape->setMargin(margin);
|
||||
}
|
||||
|
@ -24,6 +24,10 @@
|
||||
*
|
||||
*/
|
||||
class EXPCL_PANDABULLET BulletConeShape : public BulletShape {
|
||||
private:
|
||||
// Only used by make_from_bam
|
||||
INLINE BulletConeShape();
|
||||
|
||||
PUBLISHED:
|
||||
explicit BulletConeShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up=Z_up);
|
||||
INLINE BulletConeShape(const BulletConeShape ©);
|
||||
@ -41,6 +45,16 @@ public:
|
||||
|
||||
private:
|
||||
btConeShape *_shape;
|
||||
PN_stdfloat _radius;
|
||||
PN_stdfloat _height;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
@ -125,6 +125,7 @@ register_with_read_factory() {
|
||||
*/
|
||||
void BulletConvexHullShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
dg.add_stdfloat(get_margin());
|
||||
|
||||
unsigned int num_points = _shape->getNumPoints();
|
||||
@ -161,7 +162,10 @@ make_from_bam(const FactoryParams ¶ms) {
|
||||
*/
|
||||
void BulletConvexHullShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
_shape->setMargin(scan.get_stdfloat());
|
||||
unsigned int num_points = scan.get_uint32();
|
||||
|
||||
#if BT_BULLET_VERSION >= 282
|
||||
|
@ -11,6 +11,15 @@
|
||||
* @date 2010-01-30
|
||||
*/
|
||||
|
||||
/**
|
||||
* Only used by make_from_bam.
|
||||
*/
|
||||
INLINE BulletConvexPointCloudShape::
|
||||
BulletConvexPointCloudShape() :
|
||||
_scale(1),
|
||||
_shape(nullptr) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -25,6 +34,7 @@ INLINE BulletConvexPointCloudShape::
|
||||
*/
|
||||
INLINE BulletConvexPointCloudShape::
|
||||
BulletConvexPointCloudShape(const BulletConvexPointCloudShape ©) :
|
||||
_scale(copy._scale),
|
||||
_shape(copy._shape) {
|
||||
}
|
||||
|
||||
@ -33,6 +43,7 @@ BulletConvexPointCloudShape(const BulletConvexPointCloudShape ©) :
|
||||
*/
|
||||
INLINE void BulletConvexPointCloudShape::
|
||||
operator = (const BulletConvexPointCloudShape ©) {
|
||||
_scale = copy._scale;
|
||||
_shape = copy._shape;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,8 @@ TypeHandle BulletConvexPointCloudShape::_type_handle;
|
||||
*
|
||||
*/
|
||||
BulletConvexPointCloudShape::
|
||||
BulletConvexPointCloudShape(const PTA_LVecBase3 &points, LVecBase3 scale) {
|
||||
BulletConvexPointCloudShape(const PTA_LVecBase3 &points, LVecBase3 scale) :
|
||||
_scale(scale) {
|
||||
|
||||
btVector3 btScale = LVecBase3_to_btVector3(scale);
|
||||
|
||||
@ -56,6 +57,7 @@ BulletConvexPointCloudShape::
|
||||
BulletConvexPointCloudShape(const Geom *geom, LVecBase3 scale) {
|
||||
|
||||
btVector3 btScale = LVecBase3_to_btVector3(scale);
|
||||
_scale = scale;
|
||||
|
||||
// Collect points
|
||||
pvector<LPoint3> points;
|
||||
@ -81,3 +83,71 @@ BulletConvexPointCloudShape(const Geom *geom, LVecBase3 scale) {
|
||||
_shape = new btConvexPointCloudShape(btPoints, points.size(), btScale);
|
||||
_shape->setUserPointer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the BamReader how to create objects of type BulletShape.
|
||||
*/
|
||||
void BulletConvexPointCloudShape::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void BulletConvexPointCloudShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
|
||||
// parameters to serialize: num points, points, scale
|
||||
_scale.write_datagram(dg);
|
||||
|
||||
dg.add_int32(get_num_points());
|
||||
for (int i = 0; i < get_num_points(); ++i){
|
||||
btVector3_to_LVector3(_shape->getUnscaledPoints()[i]).write_datagram(dg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the BamReader's factory when a new object of
|
||||
* type BulletShape is encountered in the Bam file. It should create the
|
||||
* BulletShape and extract its information from the file.
|
||||
*/
|
||||
TypedWritable *BulletConvexPointCloudShape::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
// create a default BulletConvexPointCloudShape
|
||||
BulletConvexPointCloudShape *param = new BulletConvexPointCloudShape;
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
param->fillin(scan, manager);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new BulletShape.
|
||||
*/
|
||||
void BulletConvexPointCloudShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
BulletShape::fillin(scan, manager);
|
||||
|
||||
// parameters to serialize: num points, points, scale
|
||||
_scale.read_datagram(scan);
|
||||
|
||||
unsigned int num_points = scan.get_uint32();
|
||||
|
||||
btVector3 *btPoints = new btVector3[num_points];
|
||||
for (unsigned int i = 0; i < num_points; ++i) {
|
||||
LPoint3 point;
|
||||
point.read_datagram(scan);
|
||||
btPoints[i] = LVecBase3_to_btVector3(point);
|
||||
}
|
||||
|
||||
// Create shape
|
||||
_shape = new btConvexPointCloudShape(btPoints, num_points, LVecBase3_to_btVector3(_scale));
|
||||
_shape->setUserPointer(this);
|
||||
}
|
||||
|
@ -26,6 +26,10 @@
|
||||
*
|
||||
*/
|
||||
class EXPCL_PANDABULLET BulletConvexPointCloudShape : public BulletShape {
|
||||
private:
|
||||
// Only used by make_from_bam
|
||||
INLINE BulletConvexPointCloudShape();
|
||||
|
||||
PUBLISHED:
|
||||
explicit BulletConvexPointCloudShape(const PTA_LVecBase3 &points, LVecBase3 scale=LVecBase3(1.));
|
||||
explicit BulletConvexPointCloudShape(const Geom *geom, LVecBase3 scale=LVecBase3(1.));
|
||||
@ -42,6 +46,15 @@ public:
|
||||
|
||||
private:
|
||||
btConvexPointCloudShape *_shape;
|
||||
LVecBase3 _scale;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
@ -11,6 +11,15 @@
|
||||
* @date 2010-02-17
|
||||
*/
|
||||
|
||||
/**
|
||||
* Only used by make_from_bam.
|
||||
*/
|
||||
INLINE BulletCylinderShape::
|
||||
BulletCylinderShape() :
|
||||
_half_extents(LVector3::zero()),
|
||||
_shape(nullptr) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -25,7 +34,7 @@ INLINE BulletCylinderShape::
|
||||
*/
|
||||
INLINE BulletCylinderShape::
|
||||
BulletCylinderShape(const BulletCylinderShape ©) :
|
||||
_shape(copy._shape) {
|
||||
_shape(copy._shape), _half_extents(copy._half_extents) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,6 +43,7 @@ BulletCylinderShape(const BulletCylinderShape ©) :
|
||||
INLINE void BulletCylinderShape::
|
||||
operator = (const BulletCylinderShape ©) {
|
||||
_shape = copy._shape;
|
||||
_half_extents = copy._half_extents;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,8 @@ TypeHandle BulletCylinderShape::_type_handle;
|
||||
*
|
||||
*/
|
||||
BulletCylinderShape::
|
||||
BulletCylinderShape(const LVector3 &half_extents, BulletUpAxis up) {
|
||||
BulletCylinderShape(const LVector3 &half_extents, BulletUpAxis up) :
|
||||
_half_extents(half_extents){
|
||||
|
||||
btVector3 btHalfExtents = LVecBase3_to_btVector3(half_extents);
|
||||
|
||||
@ -50,12 +51,15 @@ BulletCylinderShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up) {
|
||||
switch (up) {
|
||||
case X_up:
|
||||
_shape = new btCylinderShapeX(btVector3(0.5 * height, radius, radius));
|
||||
_half_extents = btVector3_to_LVector3(btVector3(0.5 * height, radius, radius));
|
||||
break;
|
||||
case Y_up:
|
||||
_shape = new btCylinderShape(btVector3(radius, 0.5 * height, radius));
|
||||
_half_extents = btVector3_to_LVector3(btVector3(radius, 0.5 * height, radius));
|
||||
break;
|
||||
case Z_up:
|
||||
_shape = new btCylinderShapeZ(btVector3(radius, radius, 0.5 * height));
|
||||
_half_extents = btVector3_to_LVector3(btVector3(radius, radius, 0.5 * height));
|
||||
break;
|
||||
default:
|
||||
bullet_cat.error() << "invalid up-axis:" << up << endl;
|
||||
@ -73,3 +77,79 @@ ptr() const {
|
||||
|
||||
return _shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the BamReader how to create objects of type BulletShape.
|
||||
*/
|
||||
void BulletCylinderShape::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void BulletCylinderShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
dg.add_stdfloat(get_margin());
|
||||
|
||||
// parameters to serialize: radius, height, up
|
||||
_half_extents.write_datagram(dg);
|
||||
dg.add_int8((int8_t)_shape->getUpAxis());
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the BamReader's factory when a new object of
|
||||
* type BulletShape is encountered in the Bam file. It should create the
|
||||
* BulletShape and extract its information from the file.
|
||||
*/
|
||||
TypedWritable *BulletCylinderShape::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
// create a default BulletCylinderShape
|
||||
BulletCylinderShape *param = new BulletCylinderShape;
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
param->fillin(scan, manager);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new BulletShape.
|
||||
*/
|
||||
void BulletCylinderShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
|
||||
// parameters to serialize: radius, height, up
|
||||
_half_extents.read_datagram(scan);
|
||||
int up = (int) scan.get_int8();
|
||||
|
||||
btVector3 btHalfExtents = LVecBase3_to_btVector3(_half_extents);
|
||||
|
||||
switch (up) {
|
||||
case X_up:
|
||||
_shape = new btCylinderShapeX(btHalfExtents);
|
||||
break;
|
||||
case Y_up:
|
||||
_shape = new btCylinderShape(btHalfExtents);
|
||||
break;
|
||||
case Z_up:
|
||||
_shape = new btCylinderShapeZ(btHalfExtents);
|
||||
break;
|
||||
default:
|
||||
bullet_cat.error() << "invalid up-axis:" << up << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
_shape->setUserPointer(this);
|
||||
_shape->setMargin(margin);
|
||||
}
|
||||
|
@ -24,6 +24,10 @@
|
||||
*
|
||||
*/
|
||||
class EXPCL_PANDABULLET BulletCylinderShape : public BulletShape {
|
||||
private:
|
||||
// Only used by make_from_bam
|
||||
INLINE BulletCylinderShape();
|
||||
|
||||
PUBLISHED:
|
||||
explicit BulletCylinderShape(PN_stdfloat radius, PN_stdfloat height, BulletUpAxis up=Z_up);
|
||||
explicit BulletCylinderShape(const LVector3 &half_extents, BulletUpAxis up=Z_up);
|
||||
@ -43,8 +47,17 @@ public:
|
||||
virtual btCollisionShape *ptr() const;
|
||||
|
||||
private:
|
||||
LVector3 _half_extents;
|
||||
btCylinderShape *_shape;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
|
@ -11,12 +11,24 @@
|
||||
* @date 2010-02-05
|
||||
*/
|
||||
|
||||
/**
|
||||
* Only used by make_from_bam
|
||||
*/
|
||||
INLINE BulletHeightfieldShape::
|
||||
BulletHeightfieldShape() :
|
||||
_num_rows(0),
|
||||
_num_cols(0),
|
||||
_data(nullptr),
|
||||
_shape(nullptr),
|
||||
_max_height(0.0),
|
||||
_up(Z_up) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
INLINE BulletHeightfieldShape::
|
||||
~BulletHeightfieldShape() {
|
||||
|
||||
delete _shape;
|
||||
delete [] _data;
|
||||
}
|
||||
@ -28,10 +40,13 @@ INLINE BulletHeightfieldShape::
|
||||
BulletHeightfieldShape(const BulletHeightfieldShape ©) :
|
||||
_shape(copy._shape),
|
||||
_num_rows(copy._num_rows),
|
||||
_num_cols(copy._num_cols) {
|
||||
_num_cols(copy._num_cols),
|
||||
_max_height(copy._max_height),
|
||||
_up(copy._up) {
|
||||
|
||||
_data = new btScalar[_num_rows * _num_cols];
|
||||
memcpy(_data, copy._data, _num_rows * _num_cols * sizeof(btScalar));
|
||||
size_t size = (size_t)_num_rows * (size_t)_num_cols;
|
||||
_data = new btScalar[size];
|
||||
memcpy(_data, copy._data, size * sizeof(btScalar));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,11 +54,11 @@ BulletHeightfieldShape(const BulletHeightfieldShape ©) :
|
||||
*/
|
||||
INLINE void BulletHeightfieldShape::
|
||||
operator = (const BulletHeightfieldShape ©) {
|
||||
|
||||
_shape = copy._shape;
|
||||
_num_rows = copy._num_rows;
|
||||
_num_cols = copy._num_cols;
|
||||
|
||||
_data = new btScalar[_num_rows * _num_cols];
|
||||
memcpy(_data, copy._data, _num_rows * _num_cols * sizeof(btScalar));
|
||||
size_t size = (size_t)_num_rows * (size_t)_num_cols;
|
||||
_data = new btScalar[size];
|
||||
memcpy(_data, copy._data, size * sizeof(btScalar));
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ TypeHandle BulletHeightfieldShape::_type_handle;
|
||||
* while rotating it 90 degrees to the right.
|
||||
*/
|
||||
BulletHeightfieldShape::
|
||||
BulletHeightfieldShape(const PNMImage &image, PN_stdfloat max_height, BulletUpAxis up) {
|
||||
BulletHeightfieldShape(const PNMImage &image, PN_stdfloat max_height, BulletUpAxis up) :
|
||||
_max_height(max_height), _up(up) {
|
||||
|
||||
_num_rows = image.get_x_size();
|
||||
_num_cols = image.get_y_size();
|
||||
@ -71,7 +72,8 @@ set_use_diamond_subdivision(bool flag) {
|
||||
* that are non-power-of-two and/or rectangular.
|
||||
*/
|
||||
BulletHeightfieldShape::
|
||||
BulletHeightfieldShape(Texture *tex, PN_stdfloat max_height, BulletUpAxis up) {
|
||||
BulletHeightfieldShape(Texture *tex, PN_stdfloat max_height, BulletUpAxis up) :
|
||||
_max_height(max_height), _up(up) {
|
||||
|
||||
_num_rows = tex->get_x_size() + 1;
|
||||
_num_cols = tex->get_y_size() + 1;
|
||||
@ -101,3 +103,84 @@ BulletHeightfieldShape(Texture *tex, PN_stdfloat max_height, BulletUpAxis up) {
|
||||
true, false);
|
||||
_shape->setUserPointer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the BamReader how to create objects of type BulletShape.
|
||||
*/
|
||||
void BulletHeightfieldShape::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void BulletHeightfieldShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
dg.add_stdfloat(get_margin());
|
||||
|
||||
// parameters to serialize:_num_rows,_num_cols,_data,max_height,up,
|
||||
dg.add_int8((int8_t)_up);
|
||||
dg.add_stdfloat(_max_height);
|
||||
dg.add_int32(_num_rows);
|
||||
dg.add_int32(_num_cols);
|
||||
|
||||
size_t size = (size_t)_num_rows * (size_t)_num_cols;
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
dg.add_stdfloat(_data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the BamReader's factory when a new object of
|
||||
* type BulletShape is encountered in the Bam file. It should create the
|
||||
* BulletShape and extract its information from the file.
|
||||
*/
|
||||
TypedWritable *BulletHeightfieldShape::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
// create a default BulletHeightfieldShape
|
||||
BulletHeightfieldShape *param = new BulletHeightfieldShape;
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
param->fillin(scan, manager);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new BulletShape.
|
||||
*/
|
||||
void BulletHeightfieldShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
|
||||
// parameters to serialize: radius, height, up
|
||||
_up = (BulletUpAxis) scan.get_int8();
|
||||
_max_height = scan.get_stdfloat();
|
||||
_num_rows = scan.get_int32();
|
||||
_num_cols = scan.get_int32();
|
||||
|
||||
size_t size = (size_t)_num_rows * (size_t)_num_cols;
|
||||
delete[] _data;
|
||||
_data = new float[size];
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
_data[i] = scan.get_stdfloat();
|
||||
}
|
||||
|
||||
_shape = new btHeightfieldTerrainShape(_num_rows,
|
||||
_num_cols,
|
||||
_data,
|
||||
_max_height,
|
||||
_up,
|
||||
true, false);
|
||||
_shape->setUserPointer(this);
|
||||
_shape->setMargin(margin);
|
||||
}
|
||||
|
@ -28,6 +28,9 @@
|
||||
*
|
||||
*/
|
||||
class EXPCL_PANDABULLET BulletHeightfieldShape : public BulletShape {
|
||||
private:
|
||||
INLINE BulletHeightfieldShape();
|
||||
|
||||
PUBLISHED:
|
||||
explicit BulletHeightfieldShape(const PNMImage &image, PN_stdfloat max_height, BulletUpAxis up=Z_up);
|
||||
explicit BulletHeightfieldShape(Texture *tex, PN_stdfloat max_height, BulletUpAxis up=Z_up);
|
||||
@ -45,6 +48,16 @@ private:
|
||||
int _num_cols;
|
||||
btScalar *_data;
|
||||
btHeightfieldTerrainShape *_shape;
|
||||
PN_stdfloat _max_height;
|
||||
BulletUpAxis _up;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
|
@ -11,6 +11,16 @@
|
||||
* @date 2010-01-23
|
||||
*/
|
||||
|
||||
/**
|
||||
* Only used by make_from_bam.
|
||||
*/
|
||||
INLINE BulletMinkowskiSumShape::
|
||||
BulletMinkowskiSumShape() :
|
||||
_shape(nullptr),
|
||||
_shape_a(nullptr),
|
||||
_shape_b(nullptr) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -95,12 +105,3 @@ get_shape_b() const {
|
||||
|
||||
return _shape_b;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
INLINE PN_stdfloat BulletMinkowskiSumShape::
|
||||
get_margin() const {
|
||||
|
||||
return (PN_stdfloat)_shape->getMargin();
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ TypeHandle BulletMinkowskiSumShape::_type_handle;
|
||||
*
|
||||
*/
|
||||
BulletMinkowskiSumShape::
|
||||
BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b) {
|
||||
BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b) :
|
||||
_shape_a(shape_a),
|
||||
_shape_b(shape_b) {
|
||||
|
||||
nassertv(shape_a->is_convex());
|
||||
nassertv(shape_b->is_convex());
|
||||
@ -29,9 +31,6 @@ BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b)
|
||||
|
||||
_shape = new btMinkowskiSumShape(ptr_a, ptr_b);
|
||||
_shape->setUserPointer(this);
|
||||
|
||||
_shape_a = shape_a;
|
||||
_shape_b = shape_b;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,3 +41,102 @@ ptr() const {
|
||||
|
||||
return _shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the BamReader how to create objects of type BulletShape.
|
||||
*/
|
||||
void BulletMinkowskiSumShape::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void BulletMinkowskiSumShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
dg.add_stdfloat(get_margin());
|
||||
|
||||
// parameters to serialize: _shape_a, _shape_b, _transform_a, _transform_b
|
||||
manager->write_pointer(dg, _shape_a);
|
||||
manager->write_pointer(dg, _shape_b);
|
||||
manager->write_pointer(dg, get_transform_a());
|
||||
manager->write_pointer(dg, get_transform_b());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives an array of pointers, one for each time manager->read_pointer()
|
||||
* was called in fillin(). Returns the number of pointers processed.
|
||||
*/
|
||||
int BulletMinkowskiSumShape::
|
||||
complete_pointers(TypedWritable **p_list, BamReader *manager) {
|
||||
int pi = BulletShape::complete_pointers(p_list, manager);
|
||||
|
||||
_shape_a = DCAST(BulletShape, p_list[pi++]);
|
||||
_shape_b = DCAST(BulletShape, p_list[pi++]);
|
||||
|
||||
const TransformState *transform_a = DCAST(TransformState, p_list[pi++]);
|
||||
const TransformState *transform_b = DCAST(TransformState, p_list[pi++]);
|
||||
|
||||
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->setMargin(_margin);
|
||||
|
||||
set_transform_a(transform_a);
|
||||
set_transform_b(transform_b);
|
||||
|
||||
return pi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some objects require all of their nested pointers to have been completed
|
||||
* before the objects themselves can be completed. If this is the case,
|
||||
* override this method to return true, and be careful with circular
|
||||
* references (which would make the object unreadable from a bam file).
|
||||
*/
|
||||
bool BulletMinkowskiSumShape::
|
||||
require_fully_complete() const {
|
||||
// We require the shape pointers to be complete before we add them.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the BamReader's factory when a new object of
|
||||
* type BulletShape is encountered in the Bam file. It should create the
|
||||
* BulletShape and extract its information from the file.
|
||||
*/
|
||||
TypedWritable *BulletMinkowskiSumShape::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
// create a default BulletMinkowskiSumShape
|
||||
BulletMinkowskiSumShape *param = new BulletMinkowskiSumShape;
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
param->fillin(scan, manager);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new BulletShape.
|
||||
*/
|
||||
void BulletMinkowskiSumShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
_margin = scan.get_stdfloat();
|
||||
|
||||
// parameters to serialize: _shape_a, _shape_b, _transform_a, _transform_b
|
||||
manager->read_pointer(scan);
|
||||
manager->read_pointer(scan);
|
||||
manager->read_pointer(scan);
|
||||
manager->read_pointer(scan);
|
||||
}
|
||||
|
@ -26,6 +26,10 @@
|
||||
*
|
||||
*/
|
||||
class EXPCL_PANDABULLET BulletMinkowskiSumShape : public BulletShape {
|
||||
private:
|
||||
// Only used by make_from_bam
|
||||
INLINE BulletMinkowskiSumShape();
|
||||
|
||||
PUBLISHED:
|
||||
explicit BulletMinkowskiSumShape(const BulletShape *shape_a, const BulletShape *shape_b);
|
||||
INLINE BulletMinkowskiSumShape(const BulletMinkowskiSumShape ©);
|
||||
@ -40,13 +44,10 @@ PUBLISHED:
|
||||
INLINE const BulletShape *get_shape_a() const;
|
||||
INLINE const BulletShape *get_shape_b() const;
|
||||
|
||||
INLINE PN_stdfloat get_margin() const;
|
||||
|
||||
MAKE_PROPERTY(transform_a, get_transform_a, set_transform_a);
|
||||
MAKE_PROPERTY(transform_b, get_transform_b, set_transform_b);
|
||||
MAKE_PROPERTY(shape_a, get_shape_a);
|
||||
MAKE_PROPERTY(shape_b, get_shape_b);
|
||||
MAKE_PROPERTY(margin, get_margin);
|
||||
|
||||
public:
|
||||
virtual btCollisionShape *ptr() const;
|
||||
@ -57,6 +58,20 @@ private:
|
||||
CPT(BulletShape) _shape_a;
|
||||
CPT(BulletShape) _shape_b;
|
||||
|
||||
// This is stored temporarily during read.
|
||||
PN_stdfloat _margin;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
virtual int complete_pointers(TypedWritable **plist,
|
||||
BamReader *manager);
|
||||
virtual bool require_fully_complete() const;
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
|
@ -50,3 +50,79 @@ ptr() const {
|
||||
|
||||
return _shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the BamReader how to create objects of type BulletShape.
|
||||
*/
|
||||
void BulletMultiSphereShape::
|
||||
register_with_read_factory() {
|
||||
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the contents of this object to the datagram for shipping out to a
|
||||
* Bam file.
|
||||
*/
|
||||
void BulletMultiSphereShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
dg.add_stdfloat(get_margin());
|
||||
|
||||
// parameters to serialize: sphere count, points, radii
|
||||
dg.add_int32(get_sphere_count());
|
||||
for (int i = 0; i < get_sphere_count(); ++i){
|
||||
get_sphere_pos(i).write_datagram(dg);
|
||||
}
|
||||
|
||||
for (int i = 0; i < get_sphere_count(); ++i){
|
||||
dg.add_stdfloat(get_sphere_radius(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the BamReader's factory when a new object of
|
||||
* type BulletShape is encountered in the Bam file. It should create the
|
||||
* BulletShape and extract its information from the file.
|
||||
*/
|
||||
TypedWritable *BulletMultiSphereShape::
|
||||
make_from_bam(const FactoryParams ¶ms) {
|
||||
// create a default BulletMultiSphereShape
|
||||
BulletMultiSphereShape *param = new BulletMultiSphereShape;
|
||||
DatagramIterator scan;
|
||||
BamReader *manager;
|
||||
|
||||
parse_params(params, scan, manager);
|
||||
param->fillin(scan, manager);
|
||||
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* This internal function is called by make_from_bam to read in all of the
|
||||
* relevant data from the BamFile for the new BulletShape.
|
||||
*/
|
||||
void BulletMultiSphereShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
|
||||
// parameters to serialize: sphere count, points, radii
|
||||
int sphereCount = scan.get_int32();
|
||||
btVector3 *positions = new btVector3[sphereCount];
|
||||
for (int i = 0; i < sphereCount; ++i){
|
||||
LVector3 pos;
|
||||
pos.read_datagram(scan);
|
||||
positions[i] = LVecBase3_to_btVector3(pos);
|
||||
}
|
||||
|
||||
btScalar *radii = new btScalar[sphereCount];
|
||||
for (int i = 0; i < sphereCount; ++i){
|
||||
radii[i] = scan.get_stdfloat();
|
||||
}
|
||||
|
||||
_shape = new btMultiSphereShape(positions, radii, sphereCount);
|
||||
_shape->setUserPointer(this);
|
||||
_shape->setMargin(margin);
|
||||
}
|
||||
|
@ -26,6 +26,9 @@
|
||||
*
|
||||
*/
|
||||
class EXPCL_PANDABULLET BulletMultiSphereShape : public BulletShape {
|
||||
private:
|
||||
BulletMultiSphereShape() : _shape(nullptr) {}
|
||||
|
||||
PUBLISHED:
|
||||
explicit BulletMultiSphereShape(const PTA_LVecBase3 &points, const PTA_stdfloat &radii);
|
||||
INLINE BulletMultiSphereShape(const BulletMultiSphereShape ©);
|
||||
@ -46,6 +49,14 @@ public:
|
||||
private:
|
||||
btMultiSphereShape *_shape;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
virtual void write_datagram(BamWriter *manager, Datagram &dg);
|
||||
|
||||
protected:
|
||||
static TypedWritable *make_from_bam(const FactoryParams ¶ms);
|
||||
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
|
@ -62,6 +62,8 @@ register_with_read_factory() {
|
||||
*/
|
||||
void BulletPlaneShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
|
||||
dg.add_stdfloat(get_margin());
|
||||
get_plane_normal().write_datagram(dg);
|
||||
dg.add_stdfloat(get_plane_constant());
|
||||
@ -90,7 +92,8 @@ make_from_bam(const FactoryParams ¶ms) {
|
||||
*/
|
||||
void BulletPlaneShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
nassertv(_shape == NULL);
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
|
||||
|
@ -612,6 +612,9 @@ write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
get_gravity().write_datagram(dg);
|
||||
get_linear_factor().write_datagram(dg);
|
||||
get_angular_factor().write_datagram(dg);
|
||||
// dynamic state (?)
|
||||
get_linear_velocity().write_datagram(dg);
|
||||
get_angular_velocity().write_datagram(dg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,8 @@ INLINE BulletSphereShape::
|
||||
*/
|
||||
INLINE BulletSphereShape::
|
||||
BulletSphereShape(const BulletSphereShape ©) :
|
||||
_shape(copy._shape) {
|
||||
_shape(copy._shape),
|
||||
_radius(copy._radius) {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,13 +35,13 @@ BulletSphereShape(const BulletSphereShape ©) :
|
||||
INLINE void BulletSphereShape::
|
||||
operator = (const BulletSphereShape ©) {
|
||||
_shape = copy._shape;
|
||||
_radius = copy._radius;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns the radius that was used to construct this sphere.
|
||||
*/
|
||||
INLINE PN_stdfloat BulletSphereShape::
|
||||
get_radius() const {
|
||||
|
||||
return _shape->getRadius();
|
||||
return _radius;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ TypeHandle BulletSphereShape::_type_handle;
|
||||
*
|
||||
*/
|
||||
BulletSphereShape::
|
||||
BulletSphereShape(PN_stdfloat radius) {
|
||||
BulletSphereShape(PN_stdfloat radius) : _radius(radius) {
|
||||
|
||||
_shape = new btSphereShape(radius);
|
||||
_shape->setUserPointer(this);
|
||||
@ -57,8 +57,10 @@ register_with_read_factory() {
|
||||
*/
|
||||
void BulletSphereShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
|
||||
dg.add_stdfloat(get_margin());
|
||||
dg.add_stdfloat(get_radius());
|
||||
dg.add_stdfloat(_radius);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,11 +86,13 @@ make_from_bam(const FactoryParams ¶ms) {
|
||||
*/
|
||||
void BulletSphereShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
nassertv(_shape == NULL);
|
||||
BulletShape::fillin(scan, manager);
|
||||
nassertv(_shape == nullptr);
|
||||
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
_radius = scan.get_stdfloat();
|
||||
|
||||
_shape = new btSphereShape(scan.get_stdfloat());
|
||||
_shape = new btSphereShape(_radius);
|
||||
_shape->setUserPointer(this);
|
||||
_shape->setMargin(margin);
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
|
||||
private:
|
||||
btSphereShape *_shape;
|
||||
PN_stdfloat _radius;
|
||||
|
||||
public:
|
||||
static void register_with_read_factory();
|
||||
|
@ -124,6 +124,8 @@ register_with_read_factory() {
|
||||
*/
|
||||
void BulletTriangleMeshShape::
|
||||
write_datagram(BamWriter *manager, Datagram &dg) {
|
||||
BulletShape::write_datagram(manager, dg);
|
||||
|
||||
dg.add_stdfloat(get_margin());
|
||||
|
||||
manager->write_pointer(dg, _mesh);
|
||||
@ -152,9 +154,11 @@ complete_pointers(TypedWritable **p_list, BamReader *manager) {
|
||||
_gimpact_shape = new btGImpactMeshShape(mesh_ptr);
|
||||
_gimpact_shape->updateBound();
|
||||
_gimpact_shape->setUserPointer(this);
|
||||
_gimpact_shape->setMargin(_margin);
|
||||
} else {
|
||||
_bvh_shape = new btBvhTriangleMeshShape(mesh_ptr, _compress, _bvh);
|
||||
_bvh_shape->setUserPointer(this);
|
||||
_bvh_shape->setMargin(_margin);
|
||||
}
|
||||
|
||||
return pi;
|
||||
@ -183,7 +187,9 @@ make_from_bam(const FactoryParams ¶ms) {
|
||||
*/
|
||||
void BulletTriangleMeshShape::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
PN_stdfloat margin = scan.get_stdfloat();
|
||||
BulletShape::fillin(scan, manager);
|
||||
|
||||
_margin = scan.get_stdfloat();
|
||||
|
||||
manager->read_pointer(scan);
|
||||
|
||||
|
@ -53,6 +53,9 @@ private:
|
||||
|
||||
PT(BulletTriangleMesh) _mesh;
|
||||
|
||||
// Stored temporarily during bam read.
|
||||
PN_stdfloat _margin;
|
||||
|
||||
bool _dynamic : 1;
|
||||
bool _compress : 1;
|
||||
bool _bvh : 1;
|
||||
|
@ -188,6 +188,13 @@ init_libbullet() {
|
||||
BulletSphereShape::register_with_read_factory();
|
||||
BulletTriangleMesh::register_with_read_factory();
|
||||
BulletTriangleMeshShape::register_with_read_factory();
|
||||
BulletCylinderShape::register_with_read_factory();
|
||||
BulletCapsuleShape::register_with_read_factory();
|
||||
BulletConeShape::register_with_read_factory();
|
||||
BulletHeightfieldShape::register_with_read_factory();
|
||||
BulletConvexPointCloudShape::register_with_read_factory();
|
||||
BulletMinkowskiSumShape::register_with_read_factory();
|
||||
BulletMultiSphereShape::register_with_read_factory();
|
||||
|
||||
// Custom contact callbacks
|
||||
gContactAddedCallback = contact_added_callback;
|
||||
|
Loading…
x
Reference in New Issue
Block a user