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_hinge_constraint.h
|
||||
@@ -29,6 +28,7 @@ Modified by Roman Ponomarev <rponom@gmail.com>
|
||||
#ifndef DYN_BT_HINGE_CONSTRAINT_H
|
||||
#define DYN_BT_HINGE_CONSTRAINT_H
|
||||
|
||||
#include "bt_rigid_body.h"
|
||||
#include "bt_constraint.h"
|
||||
#include "hinge_constraint_impl.h"
|
||||
|
||||
@@ -58,42 +58,77 @@ public:
|
||||
}
|
||||
|
||||
//
|
||||
virtual void set_pivot(vec3f const &p) {
|
||||
/* btHingeConstraint* p2pc = static_cast<btHingeConstraint*>(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
|
||||
{
|
||||
btHingeConstraint const* hc = static_cast<btHingeConstraint const*>(m_constraint.get());
|
||||
const btTransform& btxform = hc->getAFrame();
|
||||
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
|
||||
{
|
||||
btHingeConstraint const* hc = static_cast<btHingeConstraint const*>(m_constraint.get());
|
||||
const btTransform& btxform = hc->getBFrame();
|
||||
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
|
||||
{
|
||||
btHingeConstraint const* hc = static_cast<btHingeConstraint const*>(m_constraint.get());
|
||||
const btTransform btxform = hc->getAFrame().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
|
||||
{
|
||||
btHingeConstraint const* hc = static_cast<btHingeConstraint const*>(m_constraint.get());
|
||||
const btTransform btxform = hc->getBFrame().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
|
||||
{
|
||||
btHingeConstraint const* hc = static_cast<btHingeConstraint const*>(m_constraint.get());
|
||||
const btTransform w2a = (hc->getRigidBodyA().getWorldTransform() * hc->getAFrame()).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
|
||||
{
|
||||
btHingeConstraint const* hc = static_cast<btHingeConstraint const*>(m_constraint.get());
|
||||
const btTransform b2w = hc->getRigidBodyB().getWorldTransform() * hc->getBFrame();
|
||||
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 {
|
||||
/* btHingeConstraint const* hc = static_cast<btHingeConstraint 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 {
|
||||
/* btHingeConstraint const* hc = static_cast<btHingeConstraint 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) {
|
||||
virtual void set_world(vec3f const &p, quatf const& r) {
|
||||
btHingeConstraint* hc = static_cast<btHingeConstraint*>(m_constraint.get());
|
||||
btVector3 world(p[0], p[1], p[2]);
|
||||
btVector3 pivotA = hc->getRigidBodyA().getWorldTransform().inverse() (world);
|
||||
hc->getAFrame().getOrigin() = pivotA;
|
||||
hc->getBFrame().getOrigin() = world;
|
||||
// p2pc->buildJacobian();
|
||||
btVector3 worldP(p[0], p[1], p[2]);
|
||||
btQuaternion worldR(r[1], r[2], r[3], r[0]);
|
||||
btTransform frameAinW(worldR, worldP);
|
||||
btTransform frameA = hc->getRigidBodyA().getWorldTransform().inverse() * frameAinW;
|
||||
btTransform frameB = hc->getRigidBodyB().getWorldTransform().inverse() * frameAinW;
|
||||
hc->getAFrame() = frameA;
|
||||
hc->getBFrame() = frameB;
|
||||
}
|
||||
|
||||
virtual void get_world(vec3f &p) const {
|
||||
virtual void get_world(vec3f &p, quatf& r) const {
|
||||
btHingeConstraint const* hc = static_cast<btHingeConstraint const*>(m_constraint.get());
|
||||
p[0] = hc->getBFrame().getOrigin().x();
|
||||
p[1] = hc->getBFrame().getOrigin().y();
|
||||
p[2] = hc->getBFrame().getOrigin().z();
|
||||
btTransform frameAinW = hc->getRigidBodyA().getWorldTransform() * hc->getAFrame();
|
||||
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 enable_motor(bool enable, float velocity, float impulse) {
|
||||
@@ -103,24 +138,53 @@ public:
|
||||
|
||||
virtual void update_constraint(rigid_body_impl_t* rb)
|
||||
{
|
||||
btHingeConstraint* hc = static_cast<btHingeConstraint*>(m_constraint.get());
|
||||
btVector3 world = hc->getBFrame().getOrigin();
|
||||
btVector3 pivotA = hc->getRigidBodyA().getWorldTransform().inverse() (world);
|
||||
hc->getAFrame().getOrigin() = pivotA;
|
||||
btHingeConstraint* hc = static_cast<btHingeConstraint*>(m_constraint.get());
|
||||
btRigidBody* bt_body = static_cast<bt_rigid_body_t*>(rb)->body();
|
||||
btTransform frameW, frameL;
|
||||
if(bt_body == &hc->getRigidBodyA())
|
||||
{
|
||||
frameW = hc->getRigidBodyB().getWorldTransform() * hc->getBFrame();
|
||||
frameL = hc->getRigidBodyA().getWorldTransform().inverse() * frameW;
|
||||
hc->getAFrame() = frameL;
|
||||
}
|
||||
else if(bt_body == &hc->getRigidBodyB())
|
||||
{
|
||||
frameW = hc->getRigidBodyA().getWorldTransform() * hc->getAFrame();
|
||||
frameL = hc->getRigidBodyB().getWorldTransform().inverse() * frameW;
|
||||
hc->getBFrame() = frameL;
|
||||
}
|
||||
setPivotChanged(true);
|
||||
}
|
||||
protected:
|
||||
friend class bt_solver_t;
|
||||
|
||||
bt_hinge_constraint_t(rigid_body_impl_t* rb, vec3f const& pivot):
|
||||
bt_hinge_constraint_t(rigid_body_impl_t* rb, vec3f const& pivot, quatf const& rot):
|
||||
hinge_constraint_impl_t()
|
||||
{
|
||||
btRigidBody& bt_body = *static_cast<bt_rigid_body_t*>(rb)->body();
|
||||
btVector3 pivotA = bt_body.getCenterOfMassPosition();
|
||||
btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis
|
||||
btHingeConstraint * hinge = new btHingeConstraint(bt_body, -pivotA, btAxisA);
|
||||
btVector3 p(pivot[0], pivot[1], pivot[2]);
|
||||
btQuaternion q(rot[1], rot[2], rot[3], rot[0]);
|
||||
btTransform frameInA(q, p);
|
||||
btHingeConstraint* hinge = new btHingeConstraint(bt_body, frameInA, false);
|
||||
m_constraint.reset(hinge);
|
||||
rb->add_constraint(this);
|
||||
}
|
||||
bt_hinge_constraint_t(rigid_body_impl_t* rbA, vec3f const& pivotA, quatf const& rotA, rigid_body_impl_t* rbB, vec3f const& pivotB, quatf const& rotB):
|
||||
hinge_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();
|
||||
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);
|
||||
btHingeConstraint* hinge = new btHingeConstraint(bt_bodyA, bt_bodyB, frameInA, frameInB, false);
|
||||
m_constraint.reset(hinge);
|
||||
rbA->add_constraint(this);
|
||||
rbB->add_constraint(this);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user