Fixed Contraint

Post Reply
AlTerz93
Posts: 2
Joined: Wed Jan 22, 2020 2:45 pm

Fixed Contraint

Post by AlTerz93 » Sat Mar 21, 2020 1:58 pm

Hi to everyone! I'm new with bullet and I'm using BulletSharp. I'm trying to build a simple simulation where objects fall into a box. This box consists of five walls. I would like to lock these walls in order to actually make a box. I tried to make it using both FixedConstraint and Generic6DofSpringConstraint but the constraints are not applied. I'm definitely forgetting something but I don't understand what.
This is the code I used (note that wall is a List of RigidBody and the fourth element of wall is the floor of the box):

Code: Select all

 for (int i = 0; i<4;i++)
            {
                var constraint = new Generic6DofSpringConstraint(wall[i], wall[i], Matrix.Identity, Matrix.Identity, true)
                {
                    LinearLowerLimit = new Vector3(1,1,1),
                    LinearUpperLimit = new Vector3(-1,-1,-1),
                    AngularLowerLimit = new Vector3(1,1,1),
                    AngularUpperLimit = new Vector3(-1,-1,-1)
                };
                //var constraint = new FixedConstraint(wall[4], wall[i], Matrix.Identity, Matrix.Identity)
                //{
                //    LinearLowerLimit = new Vector3(1, 1, 1),
                //    LinearUpperLimit = new Vector3(-1, -1, -1),
                //    AngularLowerLimit = new Vector3(1, 1, 1),
                //    AngularUpperLimit = new Vector3(-1, -1, -1)
                //};
                colWorld.AddConstraint(constraint);
            }
Thanks in advance

User avatar
drleviathan
Posts: 597
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Fixed Contraint

Post by drleviathan » Sun Mar 22, 2020 4:41 pm

If your box walls should never move then make them static instead of dynamic. If you set an object's mass to zero before adding to the world then it will be static by default.

AlTerz93
Posts: 2
Joined: Wed Jan 22, 2020 2:45 pm

Re: Fixed Contraint

Post by AlTerz93 » Sun Mar 22, 2020 4:57 pm

I've already done them static and everything works perfectly. But now I need to make this box dynamic and I can't; I also tried to make the walls kinematic and the floor dynamic but nothing works

User avatar
drleviathan
Posts: 597
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Fixed Contraint

Post by drleviathan » Mon Mar 23, 2020 2:18 pm

To make a concave dynamic object you would use btCompoundShape, which has convex sub-shapes. In your case: five subshapes for the box's walls, each a btBoxShape. In the btCompoundShape's local frame <0,0,0> is its center of mass (COM). So you would give each sub-shape a local offset relative to the COM.

Post Reply