Add support to lock individual axis during rigid body simulation, for translation and rotation. This makes it easier to do 1D or 2D physics (tetris, blockout)
todo: create some example/demo.blend.
This commit is contained in:
parent
6e85d00055
commit
06d455f428
@ -440,6 +440,12 @@ extern Object workob;
|
||||
|
||||
/* ob->gameflag2 */
|
||||
#define OB_NEVER_DO_ACTIVITY_CULLING 1
|
||||
#define OB_LOCK_RIGID_BODY_X_AXIS 4
|
||||
#define OB_LOCK_RIGID_BODY_Y_AXIS 8
|
||||
#define OB_LOCK_RIGID_BODY_Z_AXIS 16
|
||||
#define OB_LOCK_RIGID_BODY_X_ROT_AXIS 32
|
||||
#define OB_LOCK_RIGID_BODY_Y_ROT_AXIS 64
|
||||
#define OB_LOCK_RIGID_BODY_Z_ROT_AXIS 128
|
||||
|
||||
#define OB_LIFE (OB_PROP|OB_DYNAMIC|OB_ACTOR|OB_MAINACTOR|OB_CHILD)
|
||||
|
||||
|
@ -3058,12 +3058,14 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
|
||||
|
||||
block= uiNewBlock(&curarea->uiblocks, "advanced_bullet_options", UI_EMBOSS, UI_HELV, curarea->win);
|
||||
/* use this for a fake extra empy space around the buttons */
|
||||
uiDefBut(block, LABEL, 0, "", -10, -10, 380, 60, NULL, 0, 0, 0, 0, "");
|
||||
|
||||
|
||||
if (ob->gameflag & OB_SOFT_BODY) {
|
||||
uiDefBut(block, LABEL, 0, "", -10, -10, 380, 60, NULL, 0, 0, 0, 0, "");
|
||||
|
||||
if (ob->bsoft)
|
||||
{
|
||||
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButBitI(block, TOG, OB_BSB_COL_CL_RS, 0, "Cluster Collision RS",
|
||||
@ -3106,16 +3108,78 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
|
||||
|
||||
|
||||
xco = 0;
|
||||
|
||||
|
||||
if (ob->gameflag & OB_DYNAMIC) {
|
||||
|
||||
yco = 100;
|
||||
uiDefBut(block, LABEL, 0, "", -10, -10, 380, 120, NULL, 0, 0, 0, 0, "");
|
||||
uiBlockBeginAlign(block);
|
||||
if (ob->margin < 0.001f)
|
||||
ob->margin = 0.06f;
|
||||
uiDefButF(block, NUM, 0, "Margin",
|
||||
xco, yco, 170, 19, &ob->margin, 0.001, 1.0, 1, 0,
|
||||
xco, yco, 180, 19, &ob->margin, 0.001, 1.0, 1, 0,
|
||||
"Collision margin");
|
||||
yco -= 20;
|
||||
|
||||
uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_X_AXIS, 0, "Lock X Axis",
|
||||
xco, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0,
|
||||
"Disable simulation of linear motion along the X axis");
|
||||
uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_X_ROT_AXIS, 0, "Lock X Rot Xxis",
|
||||
xco+=180, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0,
|
||||
"Disable simulation of angular motion along the X axis");
|
||||
yco -= 20;
|
||||
xco=0;
|
||||
uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_Y_AXIS, 0, "Lock Y Axis",
|
||||
xco, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0,
|
||||
"Disable simulation of linear motion along the Y axis");
|
||||
uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_Y_ROT_AXIS, 0, "Lock Y Rot Axis",
|
||||
xco+=180, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0,
|
||||
"Disable simulation of angular motion along the Y axis");
|
||||
|
||||
yco -= 20;
|
||||
xco=0;
|
||||
uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_Z_AXIS, 0, "Lock Z Axis",
|
||||
xco, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0,
|
||||
"Disable simulation of linear motion along the Z axis");
|
||||
uiDefButBitI(block, TOG, OB_LOCK_RIGID_BODY_Z_ROT_AXIS, 0, "Lock Z Rot Axis",
|
||||
xco+=180, yco, 180, 19, &ob->gameflag2, 0, 0, 0, 0,
|
||||
"Disable simulation of angular motion along the Z axis");
|
||||
|
||||
/*
|
||||
uiDefButBitI(block, TOG, OB_BSB_COL_CL_RS, 0, "Cluster Collision RS",
|
||||
xco, yco, 180, 19, &ob->bsoft->collisionflags, 0, 0, 0, 0,
|
||||
"Enable cluster collision between soft and rigid body");
|
||||
uiDefButBitI(block, TOG, OB_BSB_COL_CL_SS, 0, "Cluster Collision SS",
|
||||
xco+=180, yco, 180, 19, &ob->bsoft->collisionflags, 0, 0, 0, 0,
|
||||
"Enable cluster collision between soft and soft body");
|
||||
yco -= 20;
|
||||
xco = 0;
|
||||
uiDefButI(block, NUM, 0, "Cluster Iter.",
|
||||
xco, yco, 180, 19, &ob->bsoft->numclusteriterations, 1.0, 128.,
|
||||
0, 0, "Specify the number of cluster iterations");
|
||||
uiDefButI(block, NUM, 0, "Position Iter.",
|
||||
xco+=180, yco, 180, 19, &ob->bsoft->piterations, 0, 10,
|
||||
0, 0, "Position solver iterations");
|
||||
#define OB_LOCK_RIGID_BODY_X_AXIS 4
|
||||
#define OB_LOCK_RIGID_BODY_Y_AXIS 8
|
||||
#define OB_LOCK_RIGID_BODY_Z_AXIS 16
|
||||
#define OB_LOCK_RIGID_BODY_X_ROT_AXIS 32
|
||||
#define OB_LOCK_RIGID_BODY_Y_ROT_AXIS 64
|
||||
#define OB_LOCK_RIGID_BODY_Z_ROT_AXIS 128
|
||||
*/
|
||||
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
uiDefBut(block, LABEL, 0, "", -10, -10, 380, 60, NULL, 0, 0, 0, 0, "");
|
||||
uiDefButF(block, NUM, 0, "Margin",
|
||||
xco, yco, 170, 19, &ob->margin, 0.0, 1.0, 1, 0,
|
||||
xco, yco, 180, 19, &ob->margin, 0.0, 1.0, 1, 0,
|
||||
"Collision margin");
|
||||
}
|
||||
yco -= 20;
|
||||
|
@ -1315,6 +1315,12 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
|
||||
CreateMaterialFromBlenderObject(blenderobject, kxscene);
|
||||
|
||||
KX_ObjectProperties objprop;
|
||||
objprop.m_lockXaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_AXIS) !=0;
|
||||
objprop.m_lockYaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_AXIS) !=0;
|
||||
objprop.m_lockZaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_AXIS) !=0;
|
||||
objprop.m_lockXRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_ROT_AXIS) !=0;
|
||||
objprop.m_lockYRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_ROT_AXIS) !=0;
|
||||
objprop.m_lockZRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_ROT_AXIS) !=0;
|
||||
|
||||
objprop.m_isCompoundChild = isCompoundChild;
|
||||
objprop.m_hasCompoundChildren = (blenderobject->gameflag & OB_CHILD) != 0;
|
||||
|
@ -127,6 +127,14 @@ struct KX_ObjectProperties
|
||||
|
||||
/////////////////////////
|
||||
|
||||
bool m_lockXaxis;
|
||||
bool m_lockYaxis;
|
||||
bool m_lockZaxis;
|
||||
bool m_lockXRotaxis;
|
||||
bool m_lockYRotaxis;
|
||||
bool m_lockZRotaxis;
|
||||
|
||||
/////////////////////////
|
||||
double m_margin;
|
||||
KX_BoundBoxClass m_boundclass;
|
||||
union {
|
||||
|
@ -1101,8 +1101,24 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
|
||||
{
|
||||
btRigidBody* rbody = physicscontroller->GetRigidBody();
|
||||
|
||||
if (rbody && objprop->m_disableSleeping)
|
||||
rbody->setActivationState(DISABLE_DEACTIVATION);
|
||||
if (rbody)
|
||||
{
|
||||
btVector3 linearFactor(
|
||||
objprop->m_lockXaxis? 0 : 1,
|
||||
objprop->m_lockYaxis? 0 : 1,
|
||||
objprop->m_lockZaxis? 0 : 1);
|
||||
btVector3 angularFactor(
|
||||
objprop->m_lockXRotaxis? 0 : 1,
|
||||
objprop->m_lockYRotaxis? 0 : 1,
|
||||
objprop->m_lockZRotaxis? 0 : 1);
|
||||
rbody->setLinearFactor(linearFactor);
|
||||
rbody->setAngularFactor(angularFactor);
|
||||
|
||||
if (rbody && objprop->m_disableSleeping)
|
||||
{
|
||||
rbody->setActivationState(DISABLE_DEACTIVATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CcdPhysicsController* parentCtrl = objprop->m_dynamic_parent ? (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController() : 0;
|
||||
|
Loading…
Reference in New Issue
Block a user