Remove scale from TransformStates before converting to Bullet, and some minor changes.

This commit is contained in:
enn0x 2011-08-10 21:36:26 +00:00
parent 427eddc4e3
commit 1bd2bac3ef
14 changed files with 53 additions and 61 deletions

View File

@ -171,9 +171,9 @@ void BulletBodyNode::
transform_changed() {
// Apply scale to collision shape
CPT(TransformState) xform = this->get_transform();
if (xform->has_scale()) {
LVecBase3f scale = xform->get_scale();
CPT(TransformState) ts = this->get_transform();
if (ts->has_scale()) {
LVecBase3f scale = ts->get_scale();
_shape->setLocalScaling(LVecBase3f_to_btVector3(scale));
}
}
@ -184,7 +184,7 @@ transform_changed() {
// Description:
////////////////////////////////////////////////////////////////////
void BulletBodyNode::
add_shape(BulletShape *shape, CPT(TransformState) xform) {
add_shape(BulletShape *shape, CPT(TransformState) ts) {
nassertv(get_object());
@ -192,12 +192,9 @@ add_shape(BulletShape *shape, CPT(TransformState) xform) {
&& ((btConvexHullShape *)shape->ptr())->getNumVertices() == 0));
// Transform
btTransform trans;
if (xform) {
trans = LMatrix4f_to_btTrans(xform->get_mat());
}
else {
trans.setIdentity();
btTransform trans = btTransform::getIdentity();
if (ts) {
trans = LMatrix4f_to_btTrans(ts->get_mat());
}
// Root shape
@ -207,7 +204,7 @@ add_shape(BulletShape *shape, CPT(TransformState) xform) {
if (_shapes.size() == 0) {
nassertv(previous->getShapeType() == EMPTY_SHAPE_PROXYTYPE);
if (xform) {
if (ts) {
// One shape, with transform
next = new btCompoundShape();
((btCompoundShape *)next)->addChildShape(trans, shape->ptr());
@ -361,8 +358,8 @@ get_shape_mat(int idx) const {
if (root->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) {
btCompoundShape *compound = (btCompoundShape *)root;
btTransform xform = compound->getChildTransform(idx);
return btTrans_to_LMatrix4f(xform);
btTransform trans = compound->getChildTransform(idx);
return btTrans_to_LMatrix4f(trans);
// The above code assumes that shape's index in _shapes member
// is the same as the shapes index within the compound. If it
@ -372,8 +369,8 @@ get_shape_mat(int idx) const {
btCollisionShape *shape = get_shape(idx)->ptr();
for (int i=0; i<compound->getNumChildShapes(); i++) {
if (compound->getChildShape(i) == shape) {
btTransform xform = compound->getChildTransform(idx);
return btTrans_to_LMatrix4f(xform);
btTransform trans = compound->getChildTransform(idx);
return btTrans_to_LMatrix4f(trans);
}
}
*/

View File

@ -216,8 +216,7 @@ pre_step(float dt) {
// Linear movement
btVector3 v;
if (_linear_velocity_is_local) {
btTransform xform;
xform = _ghost->getWorldTransform();
btTransform xform = _ghost->getWorldTransform();
xform.setOrigin(btVector3(0.0f, 0.0f, 0.0f));
v = xform(LVecBase3f_to_btVector3(_linear_velocity));
}
@ -239,7 +238,7 @@ pre_step(float dt) {
void BulletCharacterControllerNode::
post_step() {
btTransform& trans = _ghost->getWorldTransform();
btTransform trans = _ghost->getWorldTransform();
CPT(TransformState) ts = btTrans_to_TransformState(trans);
_disable_transform_changed = true;

View File

@ -26,10 +26,10 @@ TypeHandle BulletConeTwistConstraint::_type_handle;
////////////////////////////////////////////////////////////////////
BulletConeTwistConstraint::
BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
const TransformState &frame_a) {
CPT(TransformState) frame_a) {
btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
btTransform trans_a = LMatrix4f_to_btTrans(frame_a.get_mat());
btTransform trans_a = TransformState_to_btTrans(frame_a);
_constraint = new btConeTwistConstraint(*ptr_a, trans_a);
}
@ -42,14 +42,14 @@ BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
BulletConeTwistConstraint::
BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
const BulletRigidBodyNode *node_b,
const TransformState &frame_a,
const TransformState &frame_b) {
CPT(TransformState) frame_a,
CPT(TransformState) frame_b) {
btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
btTransform trans_a = LMatrix4f_to_btTrans(frame_a.get_mat());
btTransform trans_a = TransformState_to_btTrans(frame_a);
btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
btTransform trans_b = LMatrix4f_to_btTrans(frame_b.get_mat());
btTransform trans_b = TransformState_to_btTrans(frame_b);
_constraint = new btConeTwistConstraint(*ptr_a, *ptr_b, trans_a, trans_b);
}

View File

@ -33,11 +33,11 @@ class EXPCL_PANDABULLET BulletConeTwistConstraint : public BulletConstraint {
PUBLISHED:
BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
const TransformState &frame_a);
CPT(TransformState) frame_a);
BulletConeTwistConstraint(const BulletRigidBodyNode *node_a,
const BulletRigidBodyNode *node_b,
const TransformState &frame_a,
const TransformState &frame_b);
CPT(TransformState) frame_a,
CPT(TransformState) frame_b);
INLINE ~BulletConeTwistConstraint();
void set_limit(int index, float value);

View File

@ -24,11 +24,11 @@ TypeHandle BulletGenericConstraint::_type_handle;
////////////////////////////////////////////////////////////////////
BulletGenericConstraint::
BulletGenericConstraint(const BulletRigidBodyNode *node_a,
const TransformState &frame_a,
CPT(TransformState) frame_a,
bool use_frame_a) {
btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
btTransform trans_a = LMatrix4f_to_btTrans(frame_a.get_mat());
btTransform trans_a = TransformState_to_btTrans(frame_a);
_constraint = new btGeneric6DofConstraint(*ptr_a, trans_a, use_frame_a);
}
@ -41,15 +41,15 @@ BulletGenericConstraint(const BulletRigidBodyNode *node_a,
BulletGenericConstraint::
BulletGenericConstraint(const BulletRigidBodyNode *node_a,
const BulletRigidBodyNode *node_b,
const TransformState &frame_a,
const TransformState &frame_b,
CPT(TransformState) frame_a,
CPT(TransformState) frame_b,
bool use_frame_a) {
btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
btTransform trans_a = LMatrix4f_to_btTrans(frame_a.get_mat());
btTransform trans_a = TransformState_to_btTrans(frame_a);
btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
btTransform trans_b = LMatrix4f_to_btTrans(frame_b.get_mat());
btTransform trans_b = TransformState_to_btTrans(frame_b);
_constraint = new btGeneric6DofConstraint(*ptr_a, *ptr_b, trans_a, trans_b, use_frame_a);
}

View File

@ -35,12 +35,12 @@ class EXPCL_PANDABULLET BulletGenericConstraint : public BulletConstraint {
PUBLISHED:
BulletGenericConstraint(const BulletRigidBodyNode *node_a,
const TransformState &frame_a,
CPT(TransformState) frame_a,
bool use_frame_a);
BulletGenericConstraint(const BulletRigidBodyNode *node_a,
const BulletRigidBodyNode *node_b,
const TransformState &frame_a,
const TransformState &frame_b,
CPT(TransformState) frame_a,
CPT(TransformState) frame_b,
bool use_frame_a);
INLINE ~BulletGenericConstraint();

View File

@ -90,7 +90,7 @@ transform_changed() {
if (_disable_transform_changed) return;
btTransform trans;
btTransform trans = btTransform::getIdentity();
get_node_transform(trans, this);
_ghost->setWorldTransform(trans);
_ghost->setInterpolationWorldTransform(trans);

View File

@ -181,7 +181,7 @@ make_geom_from_links(BulletSoftBodyNode *node, const GeomVertexFormat *format) {
PT(Geom) BulletHelper::
make_geom(BulletSoftBodyNode *node, const GeomVertexFormat *format, bool two_sided, bool use_faces) {
btTransform trans;
btTransform trans = btTransform::getIdentity();
get_node_transform(trans, node);
btSoftBody *body = (btSoftBody *)node->get_object();

View File

@ -224,7 +224,7 @@ transform_changed() {
if (_disable_transform_changed) return;
btTransform trans;
btTransform trans = btTransform::getIdentity();
get_node_transform(trans, this);
_body->setWorldTransform(trans);
_body->setInterpolationWorldTransform(trans);
@ -284,7 +284,7 @@ set_center_of_mass_pos(const LPoint3f &pos) {
nassertv_always(!pos.is_nan());
btTransform xform;
btTransform xform = btTransform::getIdentity();
xform.setIdentity();
xform.setOrigin(LVecBase3f_to_btVector3(pos));

View File

@ -26,11 +26,11 @@ TypeHandle BulletSliderConstraint::_type_handle;
////////////////////////////////////////////////////////////////////
BulletSliderConstraint::
BulletSliderConstraint(const BulletRigidBodyNode *node_a,
const TransformState &frame_a,
CPT(TransformState) frame_a,
bool use_frame_a) {
btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
btTransform trans_a = LMatrix4f_to_btTrans(frame_a.get_mat());
btTransform trans_a = TransformState_to_btTrans(frame_a);
_constraint = new btSliderConstraint(*ptr_a, trans_a, use_frame_a);
}
@ -43,15 +43,15 @@ BulletSliderConstraint(const BulletRigidBodyNode *node_a,
BulletSliderConstraint::
BulletSliderConstraint(const BulletRigidBodyNode *node_a,
const BulletRigidBodyNode *node_b,
const TransformState &frame_a,
const TransformState &frame_b,
CPT(TransformState) frame_a,
CPT(TransformState) frame_b,
bool use_frame_a) {
btRigidBody *ptr_a = btRigidBody::upcast(node_a->get_object());
btTransform trans_a = LMatrix4f_to_btTrans(frame_a.get_mat());
btTransform trans_a = TransformState_to_btTrans(frame_a);
btRigidBody *ptr_b = btRigidBody::upcast(node_b->get_object());
btTransform trans_b = LMatrix4f_to_btTrans(frame_b.get_mat());
btTransform trans_b = TransformState_to_btTrans(frame_b);
_constraint = new btSliderConstraint(*ptr_a, *ptr_b, trans_a, trans_b, use_frame_a);
}

View File

@ -33,12 +33,12 @@ class EXPCL_PANDABULLET BulletSliderConstraint : public BulletConstraint {
PUBLISHED:
BulletSliderConstraint(const BulletRigidBodyNode *node_a,
const TransformState &frame_a,
CPT(TransformState) frame_a,
bool useFrame_a);
BulletSliderConstraint(const BulletRigidBodyNode *node_a,
const BulletRigidBodyNode *node_b,
const TransformState &frame_a,
const TransformState &frame_b,
CPT(TransformState) frame_a,
CPT(TransformState) frame_b,
bool use_frame_a);
INLINE ~BulletSliderConstraint();

View File

@ -193,7 +193,7 @@ transform_changed() {
if (_disable_transform_changed) return;
btTransform trans;
btTransform trans = btTransform::getIdentity();
get_node_transform(trans, this);
trans *= _body->m_initialWorldTransform.inverse();
_body->transform(trans);
@ -210,7 +210,7 @@ void BulletSoftBodyNode::
post_step() {
if (_geom) {
btTransform trans;
btTransform trans = btTransform::getIdentity();
get_node_transform(trans, this);
PT(GeomVertexData) vdata = _geom->modify_vertex_data();
@ -284,13 +284,10 @@ get_closest_node_index(LVecBase3f point, bool local) {
btScalar max_dist_sqr = 1e30;
btVector3 point_x = LVecBase3f_to_btVector3(point);
btTransform trans;
btTransform trans = btTransform::getIdentity();
if (local == true) {
get_node_transform(trans, this);
}
else {
trans.setIdentity();
}
btSoftBody::tNodeArray &nodes(_body->m_nodes);
int node_idx = 0;

View File

@ -137,7 +137,7 @@ CPT(TransformState) btTrans_to_TransformState(const btTransform &trans, const LV
// Function: TransformState_to_btTrans
// Description:
////////////////////////////////////////////////////////////////////
btTransform TransformState_to_btTrans(CPT(TransformState) ts) {
btTransform TransformState_to_btTrans(CPT(TransformState) &ts) {
ts = ts->set_scale(1.0);
@ -149,10 +149,7 @@ btTransform TransformState_to_btTrans(CPT(TransformState) ts) {
btQuaternion btq = LQuaternionf_to_btQuat(quat);
btVector3 btv = LVecBase3f_to_btVector3(m.get_row3(3));
btTransform trans;
trans.setRotation(btq);
trans.setOrigin(btv);
return trans;
return btTransform(btq, btv);
}
////////////////////////////////////////////////////////////////////

View File

@ -23,6 +23,7 @@
#include "lvector3.h"
#include "lmatrix.h"
#include "lquaternion.h"
#include "pointerTo.h"
#include "pandaNode.h"
#include "nodePath.h"
@ -44,7 +45,8 @@ EXPCL_PANDABULLET CPT(TransformState) btTrans_to_TransformState(
const btTransform &tf,
const LVecBase3f &scale=LVecBase3f(1.0f, 1.0f, 1.0f));
EXPCL_PANDABULLET btTransform TransformState_to_btTrans(CPT(TransformState) ts);
EXPCL_PANDABULLET btTransform TransformState_to_btTrans(
CPT(TransformState) &ts);
// UpAxis
BEGIN_PUBLISH