Page 1 of 1

Sliding on one axis Joint

Posted: Mon May 28, 2012 4:50 am
by ole_92
Hi Norbo :D

I need to implement something like drawer sliding approach, but I don't know which Joint to choose and how to use it.
In other words, I want to stop any movement along Y or Z axes.
Could you give me a hint on that one, and which demo I should look at?

Thanks very much

Re: Sliding on one axis Joint

Posted: Mon May 28, 2012 2:47 pm
by Norbo
Check out the Joints and Constraints documentation for visualizations of all the different joint types. It sounds like the PrimsaticJoint would do what you want (restricts 2DOF linear, 3DOF angular):

Code: Select all

            var a = new Box(new Vector3(0, 5, 5), 1, 1, 1, 10);
            var b = new Box(new Vector3(4, 5, 5), 1, 1, 1, 10);
            PrismaticJoint prismaticJoint = new PrismaticJoint(a, b, a.Position, Vector3.Right, b.Position);

            //Activate the limit so that the boxes can't fly infinitely far apart.
            prismaticJoint.Limit.IsActive = true;
            prismaticJoint.Limit.Minimum = 0;
            prismaticJoint.Limit.Maximum = 4;
            
            Space.Add(a);
            Space.Add(b);
            Space.Add(prismaticJoint);

Re: Sliding on one axis Joint

Posted: Wed May 30, 2012 2:36 am
by ole_92
Ok, so what can I use as the second entity? The room is static, and isn't an Entity.
Also, I'm a little bit confused, as to which object is A and which object is B? Which one is stationary, and which moves along right axis?

Great documentation by the way, I don't know how I didn't see it before!

Thanks again

Re: Sliding on one axis Joint

Posted: Wed May 30, 2012 2:43 am
by Norbo
Also, I'm a little bit confused, as to which object is A and which object is B? Which one is stationary, and which moves along right axis?
The line is attached to entity A, and a point which is held on that line is attached to entity B. If both entities are dynamic, both can move along the line relative to each other. Actually watching the simulation makes this more understandable.
Ok, so what can I use as the second entity? The room is static, and isn't an Entity.
Passing in null to a constraint constructor will make it connect to a special kinematic 'world' entity. Be careful about which connection is null, though; in this case, since the line is attached to entity A, it is probably most intuitive to pass null for entity A. So:

Code: Select all

            var b = new Box(new Vector3(4, 5, 5), 1, 1, 1, 10);
            PrismaticJoint prismaticJoint = new PrismaticJoint(null, b, b.Position, Vector3.Right, b.Position);

            //Activate the limit so that the boxes can't fly infinitely far apart.
            prismaticJoint.Limit.IsActive = true;
            prismaticJoint.Limit.Minimum = 0;
            prismaticJoint.Limit.Maximum = 4;

            Space.Add(b);
            Space.Add(prismaticJoint);
Try plopping it into a BEPUphysicsDemos demo :)