Hi there,
I need to constrain physics in such a way that the user is able to pick an arbitrary box from a stack of boxes and pull it out but without letting the other boxes fall aside. Any box above the picked one shall simply fall straight down and fill the place of the picked one.
Could you please give some advice how to do this?
hd
Constrained physics
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Constrained physics
One option is to use the generic 6DOF constraint, and leave 3 angular constraints free, and only a single linear degree of freedom (the world up axis):
You can store the constraint in the rigid body:
so that once picking, it is easier to remove the constraint:
Then, when picking, just remove the constraint from the rigid body.
Check attached Windows executable, is that what you need?
Thanks,
Erwin
Code: Select all
///create a constraint that limits the motion in X and Z direction, but leaves all other motion free
btTransform localA,localB;
localA.setIdentity();
localB.setIdentity();
localB.setOrigin(startTransform.getOrigin());
bool useLinearReferenceFrameA = false;
static btRigidBody s_fixed(0, 0,0);
btGeneric6DofConstraint* joint6DOF = new btGeneric6DofConstraint(*body, s_fixed, localA, localB, useLinearReferenceFrameA );
joint6DOF->setAngularLowerLimit(btVector3(1,1,1));
joint6DOF->setAngularUpperLimit(btVector3(-1,-1,-1));
joint6DOF->setLinearLowerLimit(btVector3(0,-1e30,0));
joint6DOF->setLinearUpperLimit(btVector3(0,1e30,0));
m_dynamicsWorld->addConstraint(joint6DOF,false);
Code: Select all
body->addConstraintRef(joint6DOF);
Code: Select all
///remove all other constraints from the body
while (pickedBody->getNumConstraintRefs())
{
btTypedConstraint* constraint = pickedBody->getConstraintRef(0);
m_dynamicsWorld->removeConstraint(constraint);
}
Check attached Windows executable, is that what you need?
Thanks,
Erwin
You do not have the required permissions to view the files attached to this post.
-
- Posts: 10
- Joined: Thu Nov 06, 2008 8:19 pm
Re: Constrained physics
Thank you very much for the detailled explanation. It sounds like exactly what I need. I'm currently on Mac so I cannot test your executable, but I'll have a look at the code.
hd
hd
-
- Posts: 10
- Joined: Thu Nov 06, 2008 8:19 pm
Re: Constrained physics
I have one more question. How would I continue if the stack of boxes moves around (i.e. is - at least - visually attached to another object) and I want such behaviour only in "local space"? The problem is that I either overwrite the objects transformation to update it's position or let Bullet do the work, but then I can't move them around.
Hope you get what I mean.
hd
Edit: After looking at it again, it appears like this would work if I simply move the s_fixed rigid body around, i.e. change its world transformation?
Edit: I don't get this to work. Unfortunately, the Basic6DOFDemo is not part of the 2.72 distribution. Is the source code available somewhere else? I don't really get what the useLinearReferenceFrameA is used for and how the pivot points play together. When I set both pivots transformation to identity and useLinearReferenceFrameA to true, my constrained object moves up along the Y axis very quickly. It doesn't even help to set the linear limits on the Y axis to very small values.
Hope you get what I mean.
hd
Edit: After looking at it again, it appears like this would work if I simply move the s_fixed rigid body around, i.e. change its world transformation?
Edit: I don't get this to work. Unfortunately, the Basic6DOFDemo is not part of the 2.72 distribution. Is the source code available somewhere else? I don't really get what the useLinearReferenceFrameA is used for and how the pivot points play together. When I set both pivots transformation to identity and useLinearReferenceFrameA to true, my constrained object moves up along the Y axis very quickly. It doesn't even help to set the linear limits on the Y axis to very small values.
-
- Posts: 10
- Joined: Thu Nov 06, 2008 8:19 pm
Re: Constrained physics
Okay, I got it. But now if I set all limits to zero, the whole thing still looks unstable. When I have several boxes stacked and move the ground quickly, the upper boxes move very slow. This is a cool effect on the one hand, but not exactly what I wanted on the other.
Plus, it takes a huge amount of CPU power (I'm on the iPhone). Is there a faster way to achieve this?
hd
Plus, it takes a huge amount of CPU power (I'm on the iPhone). Is there a faster way to achieve this?
hd
-
- Posts: 10
- Joined: Thu Nov 06, 2008 8:19 pm
Re: Constrained physics
Setting all values to zero at least works somehow, but I cannot get it to work properly with non-zero values. Could you please provide some more detailled insight on how to restrain body movement to an arbitrary line in 3d space given by two points while the "carrying object" still moves around (i.e. the points change)?
hd
hd
-
- Posts: 10
- Joined: Thu Nov 06, 2008 8:19 pm
Re: Constrained physics
From what I've seen in the Bullet code so far, ConstraintDemo.cpp, line 125+, seems to be what I need. But there's also a btSliderConstraint.h available. What should I use?
hd
hd