Page 1 of 1

Fixed Contraint

Posted: Sat Mar 21, 2020 1:58 pm
by AlTerz93
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

Re: Fixed Contraint

Posted: Sun Mar 22, 2020 4:41 pm
by drleviathan
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.

Re: Fixed Contraint

Posted: Sun Mar 22, 2020 4:57 pm
by AlTerz93
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

Re: Fixed Contraint

Posted: Mon Mar 23, 2020 2:18 pm
by drleviathan
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.