mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 18:03:56 -04:00
Added methods for getting and setting (overriding) inertia.
This commit is contained in:
parent
bee0fa5a7f
commit
66ace2c235
@ -77,12 +77,14 @@ transform_changed() {
|
|||||||
|
|
||||||
if (ts->has_scale()) {
|
if (ts->has_scale()) {
|
||||||
LVecBase3f scale = ts->get_scale();
|
LVecBase3f scale = ts->get_scale();
|
||||||
|
if (!scale.almost_equal(LVecBase3f(1.0f, 1.0f, 1.0f))) {
|
||||||
for (int i=0; i<get_num_shapes(); i++) {
|
for (int i=0; i<get_num_shapes(); i++) {
|
||||||
PT(BulletShape) shape = _shapes[i];
|
PT(BulletShape) shape = _shapes[i];
|
||||||
shape->set_local_scale(scale);
|
shape->set_local_scale(scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -97,13 +97,14 @@ shape_changed() {
|
|||||||
void BulletRigidBodyNode::
|
void BulletRigidBodyNode::
|
||||||
set_mass(float mass) {
|
set_mass(float mass) {
|
||||||
|
|
||||||
btVector3 inertia(0.0f, 0.0f, 0.0f);
|
btScalar bt_mass = mass;
|
||||||
|
btVector3 bt_inertia(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
if (mass > 0.0f) {
|
if (bt_mass > 0.0) {
|
||||||
_rigid->getCollisionShape()->calculateLocalInertia(mass, inertia);
|
_rigid->getCollisionShape()->calculateLocalInertia(bt_mass, bt_inertia);
|
||||||
}
|
}
|
||||||
|
|
||||||
_rigid->setMassProps(mass, inertia);
|
_rigid->setMassProps(bt_mass, bt_inertia);
|
||||||
_rigid->updateInertiaTensor();
|
_rigid->updateInertiaTensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,14 +116,46 @@ set_mass(float mass) {
|
|||||||
float BulletRigidBodyNode::
|
float BulletRigidBodyNode::
|
||||||
get_mass() const {
|
get_mass() const {
|
||||||
|
|
||||||
btScalar invMass = _rigid->getInvMass();
|
btScalar inv_mass = _rigid->getInvMass();
|
||||||
|
btScalar mass = inv_mass == btScalar(0.0) ? btScalar(0.0) : btScalar(1.0) / inv_mass;
|
||||||
|
|
||||||
if (invMass == 0.0f) {
|
return mass;
|
||||||
return 0.0f;
|
}
|
||||||
}
|
|
||||||
else {
|
////////////////////////////////////////////////////////////////////
|
||||||
return 1.0f / invMass;
|
// Function: BulletRigidBodyNode::set_inertia
|
||||||
}
|
// Access: Published
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void BulletRigidBodyNode::
|
||||||
|
set_inertia(const LVecBase3f &inertia) {
|
||||||
|
|
||||||
|
btVector3 inv_inertia(
|
||||||
|
inertia.get_x() == 0.0 ? btScalar(0.0) : btScalar(1.0 / inertia.get_x()),
|
||||||
|
inertia.get_y() == 0.0 ? btScalar(0.0) : btScalar(1.0 / inertia.get_y()),
|
||||||
|
inertia.get_z() == 0.0 ? btScalar(0.0) : btScalar(1.0 / inertia.get_z())
|
||||||
|
);
|
||||||
|
|
||||||
|
_rigid->setInvInertiaDiagLocal(inv_inertia);
|
||||||
|
_rigid->updateInertiaTensor();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: BulletRigidBodyNode::get_inertia
|
||||||
|
// Access: Published
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
LVector3f BulletRigidBodyNode::
|
||||||
|
get_inertia() const {
|
||||||
|
|
||||||
|
btVector3 inv_inertia = _rigid->getInvInertiaDiagLocal();
|
||||||
|
LVector3f inertia(
|
||||||
|
inv_inertia.x() == btScalar(0.0) ? 0.0 : 1.0 / inv_inertia.x(),
|
||||||
|
inv_inertia.y() == btScalar(0.0) ? 0.0 : 1.0 / inv_inertia.y(),
|
||||||
|
inv_inertia.z() == btScalar(0.0) ? 0.0 : 1.0 / inv_inertia.z()
|
||||||
|
);
|
||||||
|
|
||||||
|
return inertia;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -231,10 +264,14 @@ transform_changed() {
|
|||||||
|
|
||||||
if (ts->has_scale()) {
|
if (ts->has_scale()) {
|
||||||
LVecBase3f scale = ts->get_scale();
|
LVecBase3f scale = ts->get_scale();
|
||||||
|
if (!scale.almost_equal(LVecBase3f(1.0f, 1.0f, 1.0f))) {
|
||||||
for (int i=0; i<get_num_shapes(); i++) {
|
for (int i=0; i<get_num_shapes(); i++) {
|
||||||
PT(BulletShape) shape = _shapes[i];
|
PT(BulletShape) shape = _shapes[i];
|
||||||
shape->set_local_scale(scale);
|
shape->set_local_scale(scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shape_changed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate the body if it has been sleeping
|
// Activate the body if it has been sleeping
|
||||||
|
@ -36,9 +36,11 @@ PUBLISHED:
|
|||||||
BulletRigidBodyNode(const char *name="rigid");
|
BulletRigidBodyNode(const char *name="rigid");
|
||||||
INLINE ~BulletRigidBodyNode();
|
INLINE ~BulletRigidBodyNode();
|
||||||
|
|
||||||
// Mass
|
// Mass & inertia
|
||||||
float get_mass() const;
|
|
||||||
void set_mass(float mass);
|
void set_mass(float mass);
|
||||||
|
float get_mass() const;
|
||||||
|
void set_inertia(const LVecBase3f &inertia);
|
||||||
|
LVector3f get_inertia() const;
|
||||||
|
|
||||||
// Velocity
|
// Velocity
|
||||||
LVector3f get_linear_velocity() const;
|
LVector3f get_linear_velocity() const;
|
||||||
|
@ -52,7 +52,7 @@ set_margin(float margin) {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: BulletShape::get_local_scale
|
// Function: BulletShape::get_local_scale
|
||||||
// Access: Published
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
LVecBase3f BulletShape::
|
LVecBase3f BulletShape::
|
||||||
@ -63,7 +63,7 @@ get_local_scale() const {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: BulletShape::set_local_scale
|
// Function: BulletShape::set_local_scale
|
||||||
// Access: Published
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void BulletShape::
|
void BulletShape::
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include "bullet_includes.h"
|
#include "bullet_includes.h"
|
||||||
|
|
||||||
#include "typedReferenceCount.h"
|
#include "typedReferenceCount.h"
|
||||||
//#include "lvector3.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Class : BulletShape
|
// Class : BulletShape
|
||||||
@ -40,15 +39,16 @@ PUBLISHED:
|
|||||||
INLINE bool is_soft_body() const;
|
INLINE bool is_soft_body() const;
|
||||||
|
|
||||||
void set_margin(float margin);
|
void set_margin(float margin);
|
||||||
void set_local_scale(const LVecBase3f &scaling);
|
|
||||||
|
|
||||||
const char *get_name() const;
|
const char *get_name() const;
|
||||||
|
|
||||||
float get_margin() const;
|
float get_margin() const;
|
||||||
LVecBase3f get_local_scale() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual btCollisionShape *ptr() const = 0;
|
virtual btCollisionShape *ptr() const = 0;
|
||||||
|
|
||||||
|
LVecBase3f get_local_scale() const;
|
||||||
|
void set_local_scale(const LVecBase3f &scale);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
|
@ -202,12 +202,14 @@ transform_changed() {
|
|||||||
|
|
||||||
if (ts->has_scale()) {
|
if (ts->has_scale()) {
|
||||||
LVecBase3f scale = ts->get_scale();
|
LVecBase3f scale = ts->get_scale();
|
||||||
|
if (!scale.almost_equal(LVecBase3f(1.0f, 1.0f, 1.0f))) {
|
||||||
for (int i=0; i<get_num_shapes(); i++) {
|
for (int i=0; i<get_num_shapes(); i++) {
|
||||||
PT(BulletShape) shape = _shapes[i];
|
PT(BulletShape) shape = _shapes[i];
|
||||||
shape->set_local_scale(scale);
|
shape->set_local_scale(scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user