add support to btHingeConstraint to set/get ERP, example use:
hinge->setParam(BT_CONSTRAINT_ERP,0.5); btScalar erp = hinge->getParam(BT_CONSTRAINT_ERP); Also, preliminary support for status bar messages in demo framework.
This commit is contained in:
@@ -356,6 +356,11 @@ void selectDemo(int demoIndex)
|
|||||||
sCurrentDemo = (*allDemos[demoIndex].m_createFunc)(app);
|
sCurrentDemo = (*allDemos[demoIndex].m_createFunc)(app);
|
||||||
if (sCurrentDemo)
|
if (sCurrentDemo)
|
||||||
{
|
{
|
||||||
|
if (gui)
|
||||||
|
{
|
||||||
|
bool isLeft = true;
|
||||||
|
gui->setStatusBarMessage("Status: OK", false);
|
||||||
|
}
|
||||||
sCurrentDemo->initPhysics();
|
sCurrentDemo->initPhysics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,6 +387,28 @@ void MyComboBoxCallback(int comboId, const char* item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void MyStatusBarPrintf(const char* msg)
|
||||||
|
{
|
||||||
|
printf("b3Printf: %s\n", msg);
|
||||||
|
if (gui)
|
||||||
|
{
|
||||||
|
bool isLeft = true;
|
||||||
|
gui->setStatusBarMessage(msg,isLeft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MyStatusBarWarning(const char* msg)
|
||||||
|
{
|
||||||
|
printf("Warning: %s\n", msg);
|
||||||
|
if (gui)
|
||||||
|
{
|
||||||
|
bool isLeft = false;
|
||||||
|
gui->setStatusBarMessage(msg,isLeft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct MyMenuItemHander :public Gwen::Event::Handler
|
struct MyMenuItemHander :public Gwen::Event::Handler
|
||||||
{
|
{
|
||||||
int m_buttonId;
|
int m_buttonId;
|
||||||
@@ -530,6 +557,10 @@ int main(int argc, char* argv[])
|
|||||||
app->m_renderer->setCameraPitch(0);
|
app->m_renderer->setCameraPitch(0);
|
||||||
app->m_renderer->setCameraTargetPosition(0,0,0);
|
app->m_renderer->setCameraTargetPosition(0,0,0);
|
||||||
|
|
||||||
|
b3SetCustomWarningMessageFunc(MyStatusBarWarning);
|
||||||
|
b3SetCustomPrintfFunc(MyStatusBarPrintf);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SimpleOpenGL3App* app = new SimpleOpenGL3App("AllBullet2Demos",width,height);
|
SimpleOpenGL3App* app = new SimpleOpenGL3App("AllBullet2Demos",width,height);
|
||||||
s_instancingRenderer->setCameraDistance(13);
|
s_instancingRenderer->setCameraDistance(13);
|
||||||
|
|||||||
@@ -19,9 +19,12 @@ void ConstraintPhysicsSetup::stepSimulation(float deltaTime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#include "Bullet3Common/b3Logging.h"
|
||||||
|
|
||||||
void ConstraintPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
|
void ConstraintPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
|
||||||
{
|
{
|
||||||
|
b3Printf(__FILE__);
|
||||||
|
|
||||||
gfxBridge.setUpAxis(1);
|
gfxBridge.setUpAxis(1);
|
||||||
|
|
||||||
createEmptyDynamicsWorld();
|
createEmptyDynamicsWorld();
|
||||||
@@ -51,6 +54,8 @@ slider.m_maxVal=720;
|
|||||||
btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis
|
btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis
|
||||||
|
|
||||||
spDoorHinge = new btHingeAccumulatedAngleConstraint( *pDoorBody, btPivotA, btAxisA );
|
spDoorHinge = new btHingeAccumulatedAngleConstraint( *pDoorBody, btPivotA, btAxisA );
|
||||||
|
spDoorHinge->setParam(BT_CONSTRAINT_ERP,0.5);
|
||||||
|
btScalar erp = spDoorHinge->getParam(BT_CONSTRAINT_ERP);
|
||||||
|
|
||||||
// spDoorHinge->setLimit( 0.0f, SIMD_PI_2 );
|
// spDoorHinge->setLimit( 0.0f, SIMD_PI_2 );
|
||||||
// test problem values
|
// test problem values
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ btHingeConstraint::btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const bt
|
|||||||
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
|
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
|
||||||
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
|
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
|
||||||
m_useReferenceFrameA(useReferenceFrameA),
|
m_useReferenceFrameA(useReferenceFrameA),
|
||||||
m_flags(0)
|
m_flags(0),
|
||||||
|
m_normalCFM(0),
|
||||||
|
m_normalERP(0),
|
||||||
|
m_stopCFM(0),
|
||||||
|
m_stopERP(0)
|
||||||
{
|
{
|
||||||
m_rbAFrame.getOrigin() = pivotInA;
|
m_rbAFrame.getOrigin() = pivotInA;
|
||||||
|
|
||||||
@@ -101,7 +105,11 @@ m_angularOnly(false), m_enableAngularMotor(false),
|
|||||||
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
|
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
|
||||||
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
|
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
|
||||||
m_useReferenceFrameA(useReferenceFrameA),
|
m_useReferenceFrameA(useReferenceFrameA),
|
||||||
m_flags(0)
|
m_flags(0),
|
||||||
|
m_normalCFM(0),
|
||||||
|
m_normalERP(0),
|
||||||
|
m_stopCFM(0),
|
||||||
|
m_stopERP(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
// since no frame is given, assume this to be zero angle and just pick rb transform axis
|
// since no frame is given, assume this to be zero angle and just pick rb transform axis
|
||||||
@@ -151,7 +159,11 @@ m_enableAngularMotor(false),
|
|||||||
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
|
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
|
||||||
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
|
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
|
||||||
m_useReferenceFrameA(useReferenceFrameA),
|
m_useReferenceFrameA(useReferenceFrameA),
|
||||||
m_flags(0)
|
m_flags(0),
|
||||||
|
m_normalCFM(0),
|
||||||
|
m_normalERP(0),
|
||||||
|
m_stopCFM(0),
|
||||||
|
m_stopERP(0)
|
||||||
{
|
{
|
||||||
#ifndef _BT_USE_CENTER_LIMIT_
|
#ifndef _BT_USE_CENTER_LIMIT_
|
||||||
//start with free
|
//start with free
|
||||||
@@ -177,7 +189,11 @@ m_enableAngularMotor(false),
|
|||||||
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
|
m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER),
|
||||||
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
|
m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET),
|
||||||
m_useReferenceFrameA(useReferenceFrameA),
|
m_useReferenceFrameA(useReferenceFrameA),
|
||||||
m_flags(0)
|
m_flags(0),
|
||||||
|
m_normalCFM(0),
|
||||||
|
m_normalERP(0),
|
||||||
|
m_stopCFM(0),
|
||||||
|
m_stopERP(0)
|
||||||
{
|
{
|
||||||
///not providing rigidbody B means implicitly using worldspace for body B
|
///not providing rigidbody B means implicitly using worldspace for body B
|
||||||
|
|
||||||
@@ -331,6 +347,7 @@ void btHingeAccumulatedAngleConstraint::getInfo1(btConstraintInfo1* info)
|
|||||||
m_accumulatedAngle = btShortestAngleUpdate(m_accumulatedAngle,curHingeAngle);
|
m_accumulatedAngle = btShortestAngleUpdate(m_accumulatedAngle,curHingeAngle);
|
||||||
|
|
||||||
btHingeConstraint::getInfo1(info);
|
btHingeConstraint::getInfo1(info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -464,7 +481,9 @@ void btHingeConstraint::getInfo2Internal(btConstraintInfo2* info, const btTransf
|
|||||||
a2.getSkewSymmetricMatrix(angular0,angular1,angular2);
|
a2.getSkewSymmetricMatrix(angular0,angular1,angular2);
|
||||||
}
|
}
|
||||||
// linear RHS
|
// linear RHS
|
||||||
btScalar k = info->fps * info->erp;
|
btScalar normalErp = (m_flags & BT_HINGE_FLAGS_ERP_NORM) ? m_normalERP : info->erp;
|
||||||
|
|
||||||
|
btScalar k = info->fps * normalErp;
|
||||||
if (!m_angularOnly)
|
if (!m_angularOnly)
|
||||||
{
|
{
|
||||||
for(i = 0; i < 3; i++)
|
for(i = 0; i < 3; i++)
|
||||||
@@ -561,7 +580,7 @@ void btHingeConstraint::getInfo2Internal(btConstraintInfo2* info, const btTransf
|
|||||||
powered = 0;
|
powered = 0;
|
||||||
}
|
}
|
||||||
info->m_constraintError[srow] = btScalar(0.0f);
|
info->m_constraintError[srow] = btScalar(0.0f);
|
||||||
btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : info->erp;
|
btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : normalErp;
|
||||||
if(powered)
|
if(powered)
|
||||||
{
|
{
|
||||||
if(m_flags & BT_HINGE_FLAGS_CFM_NORM)
|
if(m_flags & BT_HINGE_FLAGS_CFM_NORM)
|
||||||
@@ -851,7 +870,8 @@ void btHingeConstraint::getInfo2InternalUsingFrameOffset(btConstraintInfo2* info
|
|||||||
for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = tmpA[i];
|
for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = tmpA[i];
|
||||||
for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = -tmpB[i];
|
for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = -tmpB[i];
|
||||||
|
|
||||||
btScalar k = info->fps * info->erp;
|
btScalar normalErp = (m_flags & BT_HINGE_FLAGS_ERP_NORM)? m_normalERP : info->erp;
|
||||||
|
btScalar k = info->fps * normalErp;
|
||||||
|
|
||||||
if (!m_angularOnly)
|
if (!m_angularOnly)
|
||||||
{
|
{
|
||||||
@@ -909,7 +929,8 @@ void btHingeConstraint::getInfo2InternalUsingFrameOffset(btConstraintInfo2* info
|
|||||||
// angular_velocity = (erp*fps) * (ax1 x ax2)
|
// angular_velocity = (erp*fps) * (ax1 x ax2)
|
||||||
// ax1 x ax2 is in the plane space of ax1, so we project the angular
|
// ax1 x ax2 is in the plane space of ax1, so we project the angular
|
||||||
// velocity to p and q to find the right hand side.
|
// velocity to p and q to find the right hand side.
|
||||||
k = info->fps * info->erp;
|
k = info->fps * normalErp;//??
|
||||||
|
|
||||||
btVector3 u = ax1A.cross(ax1B);
|
btVector3 u = ax1A.cross(ax1B);
|
||||||
info->m_constraintError[s3] = k * u.dot(p);
|
info->m_constraintError[s3] = k * u.dot(p);
|
||||||
info->m_constraintError[s4] = k * u.dot(q);
|
info->m_constraintError[s4] = k * u.dot(q);
|
||||||
@@ -954,7 +975,7 @@ void btHingeConstraint::getInfo2InternalUsingFrameOffset(btConstraintInfo2* info
|
|||||||
powered = 0;
|
powered = 0;
|
||||||
}
|
}
|
||||||
info->m_constraintError[srow] = btScalar(0.0f);
|
info->m_constraintError[srow] = btScalar(0.0f);
|
||||||
btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : info->erp;
|
btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : normalErp;
|
||||||
if(powered)
|
if(powered)
|
||||||
{
|
{
|
||||||
if(m_flags & BT_HINGE_FLAGS_CFM_NORM)
|
if(m_flags & BT_HINGE_FLAGS_CFM_NORM)
|
||||||
@@ -1055,6 +1076,10 @@ void btHingeConstraint::setParam(int num, btScalar value, int axis)
|
|||||||
m_normalCFM = value;
|
m_normalCFM = value;
|
||||||
m_flags |= BT_HINGE_FLAGS_CFM_NORM;
|
m_flags |= BT_HINGE_FLAGS_CFM_NORM;
|
||||||
break;
|
break;
|
||||||
|
case BT_CONSTRAINT_ERP:
|
||||||
|
m_normalERP = value;
|
||||||
|
m_flags |= BT_HINGE_FLAGS_ERP_NORM;
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
btAssertConstrParams(0);
|
btAssertConstrParams(0);
|
||||||
}
|
}
|
||||||
@@ -1085,6 +1110,10 @@ btScalar btHingeConstraint::getParam(int num, int axis) const
|
|||||||
btAssertConstrParams(m_flags & BT_HINGE_FLAGS_CFM_NORM);
|
btAssertConstrParams(m_flags & BT_HINGE_FLAGS_CFM_NORM);
|
||||||
retVal = m_normalCFM;
|
retVal = m_normalCFM;
|
||||||
break;
|
break;
|
||||||
|
case BT_CONSTRAINT_ERP:
|
||||||
|
btAssertConstrParams(m_flags & BT_HINGE_FLAGS_ERP_NORM);
|
||||||
|
retVal = m_normalERP;
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
btAssertConstrParams(0);
|
btAssertConstrParams(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ enum btHingeFlags
|
|||||||
{
|
{
|
||||||
BT_HINGE_FLAGS_CFM_STOP = 1,
|
BT_HINGE_FLAGS_CFM_STOP = 1,
|
||||||
BT_HINGE_FLAGS_ERP_STOP = 2,
|
BT_HINGE_FLAGS_ERP_STOP = 2,
|
||||||
BT_HINGE_FLAGS_CFM_NORM = 4
|
BT_HINGE_FLAGS_CFM_NORM = 4,
|
||||||
|
BT_HINGE_FLAGS_ERP_NORM = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -94,6 +95,7 @@ public:
|
|||||||
|
|
||||||
int m_flags;
|
int m_flags;
|
||||||
btScalar m_normalCFM;
|
btScalar m_normalCFM;
|
||||||
|
btScalar m_normalERP;
|
||||||
btScalar m_stopCFM;
|
btScalar m_stopCFM;
|
||||||
btScalar m_stopERP;
|
btScalar m_stopERP;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user