Crash bug when "mesh" applied twice fixed
Constraints reworked - all of them could now work with one or two bodies Modification of constraint frames and initial positions of rigid bodies now allowed at start frame only Plugin version is set to 2.76
This commit is contained in:
@@ -20,8 +20,7 @@ not be misrepresented as being the original software.
|
||||
Written by: Herbert Law <Herbert.Law@gmail.com>
|
||||
|
||||
Modified by Roman Ponomarev <rponom@gmail.com>
|
||||
12/24/2009 : Nail constraint improvements
|
||||
|
||||
01/22/2010 : Constraints reworked
|
||||
*/
|
||||
|
||||
//bt_sixdof_constraint.h
|
||||
@@ -29,6 +28,7 @@ Modified by Roman Ponomarev <rponom@gmail.com>
|
||||
#ifndef DYN_BT_SIXDOF_CONSTRAINT_H
|
||||
#define DYN_BT_SIXDOF_CONSTRAINT_H
|
||||
|
||||
#include "bt_rigid_body.h"
|
||||
#include "bt_constraint.h"
|
||||
#include "sixdof_constraint_impl.h"
|
||||
|
||||
@@ -40,16 +40,20 @@ public:
|
||||
// p2pc->m_setting.m_damping = d;
|
||||
}
|
||||
|
||||
virtual void set_LinLimit(float lower, float upper) {
|
||||
virtual void set_LinLimit(vec3f& lower, vec3f& upper) {
|
||||
btGeneric6DofConstraint* sixdof = static_cast<btGeneric6DofConstraint*>(m_constraint.get());
|
||||
// sixdof->setLowerLinLimit(lower);
|
||||
// sixdof->setUpperLinLimit(upper);
|
||||
btVector3 btlow(lower[0], lower[1], lower[2]);
|
||||
btVector3 btupp(upper[0], upper[1], upper[2]);
|
||||
sixdof->setLinearLowerLimit(btlow);
|
||||
sixdof->setLinearUpperLimit(btupp);
|
||||
}
|
||||
|
||||
virtual void set_AngLimit(float lower, float upper) {
|
||||
virtual void set_AngLimit(vec3f& lower, vec3f& upper) {
|
||||
btGeneric6DofConstraint* sixdof = static_cast<btGeneric6DofConstraint*>(m_constraint.get());
|
||||
// sixdof->setLowerAngLimit(lower);
|
||||
// sixdof->setUpperAngLimit(upper);
|
||||
btVector3 btlow(lower[0], lower[1], lower[2]);
|
||||
btVector3 btupp(upper[0], upper[1], upper[2]);
|
||||
sixdof->setAngularLowerLimit(btlow);
|
||||
sixdof->setAngularUpperLimit(btupp);
|
||||
}
|
||||
|
||||
virtual float damping() const {
|
||||
@@ -58,66 +62,130 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
virtual void set_pivot(vec3f const &p) {
|
||||
/* btGeneric6DofConstraint* p2pc = static_cast<btGeneric6DofConstraint*>(m_constraint.get());
|
||||
btVector3 bt_pivot(p[0], p[1], p[2]);
|
||||
p2pc->setPivotA(bt_pivot);
|
||||
p2pc->setPivotB(m_constraint->getRigidBodyA().getCenterOfMassTransform()(bt_pivot));
|
||||
// p2pc->buildJacobian();
|
||||
*/ }
|
||||
virtual void get_frameA(vec3f& p, quatf& r) const
|
||||
{
|
||||
btGeneric6DofConstraint const* sc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
const btTransform& btxform = sc->getFrameOffsetA();
|
||||
btQuaternion bq = btxform.getRotation();
|
||||
btVector3 bp = btxform.getOrigin();
|
||||
p = vec3f(bp.x(), bp.y(), bp.z());
|
||||
r = quatf(bq.w(), bq.x(), bq.y(), bq.z());
|
||||
}
|
||||
virtual void get_frameB(vec3f& p, quatf& r) const
|
||||
{
|
||||
btGeneric6DofConstraint const* sc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
const btTransform& btxform = sc->getFrameOffsetB();
|
||||
btQuaternion bq = btxform.getRotation();
|
||||
btVector3 bp = btxform.getOrigin();
|
||||
p = vec3f(bp.x(), bp.y(), bp.z());
|
||||
r = quatf(bq.w(), bq.x(), bq.y(), bq.z());
|
||||
}
|
||||
virtual void get_invFrameA(vec3f& p, quatf& r) const
|
||||
{
|
||||
btGeneric6DofConstraint const* sc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
const btTransform btxform = sc->getFrameOffsetA().inverse();
|
||||
btQuaternion bq = btxform.getRotation();
|
||||
btVector3 bp = btxform.getOrigin();
|
||||
p = vec3f(bp.x(), bp.y(), bp.z());
|
||||
r = quatf(bq.w(), bq.x(), bq.y(), bq.z());
|
||||
}
|
||||
virtual void get_invFrameB(vec3f& p, quatf& r) const
|
||||
{
|
||||
btGeneric6DofConstraint const* sc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
const btTransform btxform = sc->getFrameOffsetB().inverse();
|
||||
btQuaternion bq = btxform.getRotation();
|
||||
btVector3 bp = btxform.getOrigin();
|
||||
p = vec3f(bp.x(), bp.y(), bp.z());
|
||||
r = quatf(bq.w(), bq.x(), bq.y(), bq.z());
|
||||
}
|
||||
virtual void worldToA(vec3f& w, vec3f& p) const
|
||||
{
|
||||
btGeneric6DofConstraint const* sc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
const btTransform w2a = (sc->getRigidBodyA().getWorldTransform() * sc->getFrameOffsetA()).inverse();
|
||||
btVector3 bw(w[0], w[1], w[2]);
|
||||
btVector3 bp = w2a * bw;
|
||||
p = vec3f(bp[0], bp[1], bp[2]);
|
||||
}
|
||||
virtual void worldFromB(vec3f& p, vec3f& w) const
|
||||
{
|
||||
btGeneric6DofConstraint const* sc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
const btTransform b2w = sc->getRigidBodyB().getWorldTransform() * sc->getFrameOffsetB();
|
||||
btVector3 bp(p[0], p[1], p[2]);
|
||||
btVector3 bw = b2w * bp;
|
||||
w = vec3f(bw[0], bw[1], bw[2]);
|
||||
}
|
||||
|
||||
virtual void get_pivot(vec3f &p) const {
|
||||
/* btGeneric6DofConstraint const* hc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
p[0] = hc->getPivotInA().x();
|
||||
p[1] = hc->getPivotInA().y();
|
||||
p[2] = hc->getPivotInA().z();
|
||||
*/ }
|
||||
|
||||
virtual void get_world_pivot(vec3f &p) const {
|
||||
/* btGeneric6DofConstraint const* hc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
p[0] = hc->getPivotInB().x();
|
||||
p[1] = hc->getPivotInB().y();
|
||||
p[2] = hc->getPivotInB().z();
|
||||
*/ }
|
||||
|
||||
virtual void set_world(vec3f const &p) {
|
||||
btGeneric6DofConstraint* constraint = static_cast<btGeneric6DofConstraint*>(m_constraint.get());
|
||||
btTransform framInA = constraint->getRigidBodyA().getCenterOfMassTransform().inverse();
|
||||
btTransform framInB = constraint->getRigidBodyB().getCenterOfMassTransform().inverse();
|
||||
constraint->getFrameOffsetA() = framInA;
|
||||
constraint->getFrameOffsetB() = framInB;
|
||||
world = p;
|
||||
virtual void set_world(vec3f const &p, quatf const& r) {
|
||||
btGeneric6DofConstraint* sc = static_cast<btGeneric6DofConstraint*>(m_constraint.get());
|
||||
btVector3 worldP(p[0], p[1], p[2]);
|
||||
btQuaternion worldR(r[1], r[2], r[3], r[0]);
|
||||
btTransform frameAinW(worldR, worldP);
|
||||
btTransform frameA = sc->getRigidBodyA().getWorldTransform().inverse() * frameAinW;
|
||||
btTransform frameB = sc->getRigidBodyB().getWorldTransform().inverse() * frameAinW;
|
||||
sc->getFrameOffsetA() = frameA;
|
||||
sc->getFrameOffsetB() = frameB;
|
||||
}
|
||||
|
||||
virtual void get_world(vec3f &p) const {
|
||||
/* btGeneric6DofConstraint const* hc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
p[0] = hc->getFrameOffsetB().getOrigin().x();
|
||||
p[1] = hc->getFrameOffsetB().getOrigin().y();
|
||||
p[2] = hc->getFrameOffsetB().getOrigin().z();
|
||||
*/ p = world;
|
||||
}
|
||||
virtual void get_world(vec3f &p, quatf& r) const {
|
||||
btGeneric6DofConstraint const* sc = static_cast<btGeneric6DofConstraint const*>(m_constraint.get());
|
||||
btTransform frameAinW = sc->getRigidBodyA().getWorldTransform() * sc->getFrameOffsetA();
|
||||
btQuaternion bq = frameAinW.getRotation();
|
||||
btVector3 bp = frameAinW.getOrigin();
|
||||
p = vec3f(bp.x(), bp.y(), bp.z());
|
||||
r = quatf(bq.w(), bq.x(), bq.y(), bq.z());
|
||||
}
|
||||
|
||||
virtual void update_constraint(rigid_body_impl_t* rb)
|
||||
{
|
||||
btGeneric6DofConstraint* constraint = static_cast<btGeneric6DofConstraint*>(m_constraint.get());
|
||||
constraint->getFrameOffsetA() = constraint->getRigidBodyA().getCenterOfMassTransform().inverse();
|
||||
constraint->getFrameOffsetB() = constraint->getRigidBodyB().getCenterOfMassTransform().inverse();
|
||||
btGeneric6DofConstraint* sc = static_cast<btGeneric6DofConstraint*>(m_constraint.get());
|
||||
btRigidBody* bt_body = static_cast<bt_rigid_body_t*>(rb)->body();
|
||||
btTransform frameW, frameL;
|
||||
if(bt_body == &sc->getRigidBodyA())
|
||||
{
|
||||
frameW = sc->getRigidBodyB().getWorldTransform() * sc->getFrameOffsetB();
|
||||
frameL = sc->getRigidBodyA().getWorldTransform().inverse() * frameW;
|
||||
sc->getFrameOffsetA() = frameL;
|
||||
}
|
||||
else if(bt_body == &sc->getRigidBodyB())
|
||||
{
|
||||
frameW = sc->getRigidBodyA().getWorldTransform() * sc->getFrameOffsetA();
|
||||
frameL = sc->getRigidBodyB().getWorldTransform().inverse() * frameW;
|
||||
sc->getFrameOffsetB() = frameL;
|
||||
}
|
||||
setPivotChanged(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
friend class bt_solver_t;
|
||||
vec3f world;
|
||||
|
||||
bt_sixdof_constraint_t(rigid_body_impl_t* rbA, vec3f const& pivotA, rigid_body_impl_t* rbB, vec3f const& pivotB):
|
||||
bt_sixdof_constraint_t(rigid_body_impl_t* rb, vec3f const& pivot, quatf const& rot):
|
||||
sixdof_constraint_impl_t()
|
||||
{
|
||||
btRigidBody& bt_body = *static_cast<bt_rigid_body_t*>(rb)->body();
|
||||
btVector3 p(pivot[0], pivot[1], pivot[2]);
|
||||
btQuaternion q(rot[1], rot[2], rot[3], rot[0]);
|
||||
btTransform frameInA(q, p);
|
||||
btGeneric6DofConstraint* sixdof = new btGeneric6DofConstraint(bt_body, frameInA, false);
|
||||
m_constraint.reset(sixdof);
|
||||
rb->add_constraint(this);
|
||||
}
|
||||
bt_sixdof_constraint_t(rigid_body_impl_t* rbA, vec3f const& pivotA, quatf const& rotA, rigid_body_impl_t* rbB, vec3f const& pivotB, quatf const& rotB):
|
||||
sixdof_constraint_impl_t()
|
||||
{
|
||||
btRigidBody& bt_bodyA = *static_cast<bt_rigid_body_t*>(rbA)->body();
|
||||
btRigidBody& bt_bodyB = *static_cast<bt_rigid_body_t*>(rbB)->body();
|
||||
btTransform framInA = bt_bodyA.getCenterOfMassTransform().inverse();
|
||||
btTransform framInB = bt_bodyB.getCenterOfMassTransform().inverse();
|
||||
btGeneric6DofConstraint * sixdof = new btGeneric6DofConstraint(bt_bodyA, bt_bodyB, framInA, framInB, true);
|
||||
m_constraint.reset(sixdof);
|
||||
btVector3 pA(pivotA[0], pivotA[1], pivotA[2]);
|
||||
btQuaternion qA(rotA[1], rotA[2], rotA[3], rotA[0]);
|
||||
btTransform frameInA(qA, pA);
|
||||
btVector3 pB(pivotB[0], pivotB[1], pivotB[2]);
|
||||
btQuaternion qB(rotB[1], rotB[2], rotB[3], rotB[0]);
|
||||
btTransform frameInB(qB, pB);
|
||||
btGeneric6DofConstraint* sixdof = new btGeneric6DofConstraint(bt_bodyA, bt_bodyB, frameInA, frameInB, false);
|
||||
m_constraint.reset(sixdof);
|
||||
rbA->add_constraint(this);
|
||||
rbB->add_constraint(this);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user