Re-enabled upright constraint.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/switch_coordinate_system@4968 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-03-10 10:17:32 +00:00
parent b691445f15
commit 706984c1c8
3 changed files with 71 additions and 97 deletions

View File

@ -173,6 +173,9 @@ btTransform Kart::getKartHeading(const float customPitch)
} // getKartHeading
// ----------------------------------------------------------------------------
/** Created the physical representation of this kart. Atm it uses the actual
* extention of the kart model to determine the size of the collision body.
*/
void Kart::createPhysics()
{
// First: Create the chassis of the kart
@ -632,9 +635,9 @@ void Kart::update(float dt)
}
// When really on air, free fly, when near ground, try to glide / adjust for landing
//if(!isNearGround())
//FIXME m_uprightConstraint->setLimit(M_PI);
//else
if(!isNearGround())
m_uprightConstraint->setLimit(M_PI);
else
m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance());
m_zipper_time_left = m_zipper_time_left>0.0f ? m_zipper_time_left-dt : 0.0f;

View File

@ -24,6 +24,7 @@ subject to the following restrictions:
#include "LinearMath/btTransformUtil.h"
#include "karts/kart.hpp"
//!
//!
//!
@ -84,31 +85,31 @@ void btUprightConstraint::solveAngularLimit(
btVector3 motorImp = clippedMotorImpulse * limit->m_axis;
body0->applyTorqueImpulse(motorImp);
}
} // solveAngularLimit
//!
//!
//!
btUprightConstraint::btUprightConstraint(const Kart *kart,
btUprightConstraint::btUprightConstraint(const Kart* kart,
const btTransform& frameInA)
: btTypedConstraint(D6_CONSTRAINT_TYPE, *(kart->getBody()))
, m_frameInA(frameInA)
{
m_kart = kart;
m_ERP = 1.0f;
m_bounce = 0.0f;
m_damping = 1.0f;
m_limitSoftness = 1.0f;
m_maxLimitForce = 3000.0f;
m_disable_time = 0.0f;
m_limit[0].m_accumulatedImpulse = 0.0f;
m_limit[1].m_accumulatedImpulse = 0.0f;
m_limit[ 0 ].m_axis = btVector3( 1, 0, 0 );
m_limit[ 1 ].m_axis = btVector3( 0, 0, 1 );
setLimit( SIMD_PI * 0.4f );
}
m_kart = kart;
m_ERP = 1.0f;
m_bounce = 0.0f;
m_damping = 1.0f;
m_limitSoftness = 1.0f;
m_maxLimitForce = 3000.0f;
m_disable_time = 0.0f;
m_limit[0].m_accumulatedImpulse = 0.0f;
m_limit[1].m_accumulatedImpulse = 0.0f;
m_limit[ 0 ].m_axis = btVector3( 1, 0, 0 );
m_limit[ 1 ].m_axis = btVector3( 0, 1, 0 );
setLimit( SIMD_PI * 0.4f );
} // btUprightConstraint
//!
//!
@ -116,30 +117,26 @@ btUprightConstraint::btUprightConstraint(const Kart *kart,
void btUprightConstraint::buildJacobian()
{
btTransform worldTransform = m_rbA.getCenterOfMassTransform() * m_frameInA;
btVector3 upAxis = worldTransform.getBasis().getColumn(1);
m_limit[ 0 ].m_angle = m_kart->getHPR().getPitch();
m_limit[ 1 ].m_angle = m_kart->getHPR().getRoll();
for ( int i = 0; i < 2; i++ )
{
if ( m_limit[ i ].m_angle < -SIMD_PI )
m_limit[ i ].m_angle += 2 * SIMD_PI;
if ( m_limit[ i ].m_angle > SIMD_PI )
m_limit[ i ].m_angle -= 2 * SIMD_PI;
btTransform worldTransform = m_rbA.getCenterOfMassTransform() * m_frameInA;
btVector3 upAxis = worldTransform.getBasis().getColumn(2);
m_limit[ 0 ].m_angle = m_kart->getPitch();
m_limit[ 1 ].m_angle = m_kart->getHPR().getRoll();
new (&m_jacAng[ i ]) btJacobianEntry( m_limit[ i ].m_axis,
m_rbA.getCenterOfMassTransform().getBasis().transpose(),
m_rbB.getCenterOfMassTransform().getBasis().transpose(),
m_rbA.getInvInertiaDiagLocal(),
m_rbB.getInvInertiaDiagLocal());
}
}
for ( int i = 0; i < 2; i++ )
{
new (&m_jacAng[ i ]) btJacobianEntry( m_limit[ i ].m_axis,
m_rbA.getCenterOfMassTransform().getBasis().transpose(),
m_rbB.getCenterOfMassTransform().getBasis().transpose(),
m_rbA.getInvInertiaDiagLocal(),
m_rbB.getInvInertiaDiagLocal());
}
} // buildJacobian
//!
//!
//!
void btUprightConstraint::solveConstraint(btScalar timeStep)
void btUprightConstraint::solveConstraint(btScalar timeStep)
{
m_timeStep = timeStep;
@ -150,9 +147,7 @@ void btUprightConstraint::solveConstraint(btScalar timeStep)
if(m_disable_time>0.0f) return;
}
solveAngularLimit( &m_limit[ 0 ], m_timeStep,
btScalar(1.) / m_jacAng[ 0 ].getDiagonal(), &m_rbA );
solveAngularLimit( &m_limit[ 1 ],
m_timeStep, btScalar(1.) / m_jacAng[ 1 ].getDiagonal(), &m_rbA );
}
solveAngularLimit( &m_limit[ 0 ], m_timeStep, btScalar(1.) / m_jacAng[ 0 ].getDiagonal(), &m_rbA );
solveAngularLimit( &m_limit[ 1 ], m_timeStep, btScalar(1.) / m_jacAng[ 1 ].getDiagonal(), &m_rbA );
} // solveConstraint

View File

@ -24,46 +24,46 @@ subject to the following restrictions:
class btRigidBody;
class Kart;
class btUprightConstraintLimit
{
public:
btVector3 m_axis;
btScalar m_angle;
btScalar m_accumulatedImpulse;
btScalar m_currentLimitError;
};
class btUprightConstraint : public btTypedConstraint
{
protected:
private:
class btUprightConstraintLimit
{
public:
btVector3 m_axis;
btScalar m_angle;
btScalar m_accumulatedImpulse;
btScalar m_currentLimitError;
};
//! relative_frames
//!@{
btTransform m_frameInA;//!< the constraint space w.r.t body A
btTransform m_frameInA;//!< the constraint space w.r.t body A
//!@}
//! Jacobians
//!@{
btJacobianEntry m_jacAng[ 2 ];//!< angular constraint
btJacobianEntry m_jacAng[ 2 ];//!< angular constraint
//!@}
const Kart *m_kart;
protected:
//! temporal variables
//!@{
btScalar m_timeStep;
btScalar m_ERP;
btScalar m_bounce;
btScalar m_damping;
btScalar m_maxLimitForce;
btScalar m_limitSoftness;
btScalar m_hiLimit;
btScalar m_loLimit;
btScalar m_disable_time;
const Kart* m_kart;
btScalar m_timeStep;
btScalar m_ERP;
btScalar m_bounce;
btScalar m_damping;
btScalar m_maxLimitForce;
btScalar m_limitSoftness;
btScalar m_hiLimit;
btScalar m_loLimit;
btScalar m_disable_time;
btUprightConstraintLimit m_limit[2];
btUprightConstraintLimit m_limit[ 2 ];
//!@}
@ -83,47 +83,23 @@ protected:
public:
btUprightConstraint(const Kart *kart, const btTransform& frameInA );
btUprightConstraint(const Kart* kart, const btTransform& frameInA);
// -PI,+PI is the full range
// 0,0 is no rotation around x or z
// -PI*0.2,+PI*0.2 is a nice bit of tilt
void setLimit( btScalar range )
{
m_loLimit = -range;
m_hiLimit = +range;
}
void setLimit( btScalar range ) { m_loLimit = -range;
m_hiLimit = +range; }
// Error correction scaling
// 0 - 1
//
void setErp( btScalar erp )
{
m_ERP = erp;
}
void setBounce( btScalar bounce )
{
m_bounce = bounce;
}
void setMaxLimitForce( btScalar force )
{
m_maxLimitForce = force;
}
void setLimitSoftness( btScalar softness )
{
m_limitSoftness = softness;
}
void setDamping( btScalar damping )
{
m_damping = damping;
}
void setDisableTime( btScalar t )
{
m_disable_time = t;
}
void setErp( btScalar erp ) { m_ERP = erp; }
void setBounce( btScalar bounce ) { m_bounce = bounce; }
void setMaxLimitForce( btScalar force ) { m_maxLimitForce = force; }
void setLimitSoftness( btScalar softness ) { m_limitSoftness = softness; }
void setDamping( btScalar damping ) { m_damping = damping; }
void setDisableTime( btScalar t ) { m_disable_time = t; }
virtual void buildJacobian();
virtual void solveConstraint(btScalar timeStep);
virtual void solveConstraint(btScalar timeStep);
};