Constrains a point on one body to be on a plane defined by another body.
Inheritance: BEPUphysics.Constraints.TwoEntity.Joints.Joint, I1DImpulseConstraintWithError, I1DJacobianConstraint
Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a new constraint which restricts one linear degree of freedom between two entities.
        /// This constructs the internal constraints, but does not configure them.  Before using a constraint constructed in this manner,
        /// ensure that its active constituent constraints are properly configured.  The entire group as well as all internal constraints are initially inactive (IsActive = false).
        /// </summary>
        public PlaneSliderJoint()
        {
            IsActive = false;
            PointOnPlaneJoint = new PointOnPlaneJoint();
            LimitX = new LinearAxisLimit();
            MotorX = new LinearAxisMotor();
            LimitY = new LinearAxisLimit();
            MotorY = new LinearAxisMotor();

            Add(PointOnPlaneJoint);
            Add(LimitX);
            Add(MotorX);
            Add(LimitY);
            Add(MotorY);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructs a new constraint which restricts one linear degree of freedom between two entities.
 /// </summary>
 /// <param name="connectionA">First entity of the constraint pair.</param>
 /// <param name="connectionB">Second entity of the constraint pair.</param>
 /// <param name="planeAnchor">Location of the anchor for the plane to be attached to connectionA in world space.</param>
 /// <param name="planeNormal">Normal of the plane constraint in world space.</param>
 /// <param name="xAxis">Direction in world space along which the X axis LinearAxisLimit and LinearAxisMotor work.
 /// This is usually chosen to be perpendicular to the planeNormal and the yAxis.</param>
 /// <param name="yAxis">Direction in world space along which the Y axis LinearAxisLimit and LinearAxisMotor work.
 /// This is usually chosen to be perpendicular to the planeNormal and the xAxis.</param>
 /// <param name="pointAnchor">Location of the anchor for the point to be attached to connectionB in world space.</param>
 public PlaneSliderJoint(Entity connectionA, Entity connectionB, Vector3 planeAnchor, Vector3 planeNormal, Vector3 xAxis, Vector3 yAxis, Vector3 pointAnchor)
 {
     if (connectionA == null)
         connectionA = TwoEntityConstraint.WorldEntity;
     if (connectionB == null)
         connectionB = TwoEntityConstraint.WorldEntity;
     PointOnPlaneJoint = new PointOnPlaneJoint(connectionA, connectionB, planeAnchor, planeNormal, pointAnchor);
     LimitX = new LinearAxisLimit(connectionA, connectionB, planeAnchor, pointAnchor, xAxis, 0, 0);
     MotorX = new LinearAxisMotor(connectionA, connectionB, planeAnchor, pointAnchor, xAxis);
     LimitY = new LinearAxisLimit(connectionA, connectionB, planeAnchor, pointAnchor, yAxis, 0, 0);
     MotorY = new LinearAxisMotor(connectionA, connectionB, planeAnchor, pointAnchor, yAxis);
     LimitX.IsActive = false;
     MotorX.IsActive = false;
     LimitY.IsActive = false;
     MotorY.IsActive = false;
     Add(PointOnPlaneJoint);
     Add(LimitX);
     Add(MotorX);
     Add(LimitY);
     Add(MotorY);
 }
        void BuildJointTest(Vector3 position)
        {
            Bone a, b;
            a = new Bone(position + new Vector3(0, 5, 0), Quaternion.Identity, .5f, 1);
            b = new Bone(position + new Vector3(0, 7, 0), Quaternion.Identity, .5f, 1);
            //var ikJoint = new IKBallSocketJoint(a, b, (a.Position + b.Position) * 0.5f);
            //var ikLimit = new IKSwingLimit(a, b, Vector3.Up, Vector3.Up, MathHelper.PiOver2);
            //var ikRevolute = new IKRevoluteJoint(a, b, Vector3.Right);
            //var ikSwivelHingeJoint = new IKSwivelHingeJoint(a, b, Vector3.Right, Vector3.Up);
            //var ikAngularJoint = new IKAngularJoint(a, b);
            //var ikTwistLimit = new IKTwistLimit(a, b, Vector3.Up, Vector3.Up, MathHelper.PiOver2);
            //var ikDistanceLimit = new IKDistanceLimit(a, b, a.Position + new Vector3(0, 0.5f, 0), b.Position + new Vector3(0, -0.5f, 0), 1f, 4);
            //var ikLinearAxisLimit = new IKLinearAxisLimit(a, b, a.Position + new Vector3(0, 0.5f, 0), Vector3.Up, b.Position + new Vector3(0, -0.5f, 0), 0, 4);
            //var ikTwistJoint = new IKTwistJoint(a, b, Vector3.Up, Vector3.Up);
            //var ikPointOnLineJoint = new IKPointOnLineJoint(a, b, a.Position + new Vector3(0, 0.5f, 0), Vector3.Up, b.Position - new Vector3(0, 0.5f, 0));
            var ikPointOnPlaneJoint = new IKPointOnPlaneJoint(a, b, a.Position + new Vector3(0, 1f, 0), Vector3.Up, b.Position - new Vector3(0, 1f, 0));

            //ikPointOnLineJoint.Softness = 0;
            //ikPointOnLineJoint.ErrorCorrectionFactor = 0;
            //solver.VelocitySubiterationCount = 10;

            var entityA = new Cylinder(a.Position, 1, 0.5f, 10);
            var entityB = new Cylinder(b.Position, 1, 0.5f, 10);
            entityB.Orientation = b.Orientation;
            //var joint = new BallSocketJoint(entityA, entityB, (a.Position + b.Position) * 0.5f);
            //var limit = new SwingLimit(entityA, entityB, Vector3.Up, Vector3.Up, MathHelper.PiOver2);
            //var revolute = new RevoluteAngularJoint(entityA, entityB, Vector3.Right);
            //var swivelHingeJoint = new SwivelHingeAngularJoint(entityA, entityB, Vector3.Right, Vector3.Up);
            //var angularJoint = new NoRotationJoint(entityA, entityB);
            //var twistLimit = new TwistLimit(entityA, entityB, Vector3.Up, Vector3.Up, -MathHelper.PiOver2, MathHelper.PiOver2);
            //var distanceLimit = new DistanceLimit(entityA, entityB, ikDistanceLimit.AnchorA, ikDistanceLimit.AnchorB, ikDistanceLimit.MinimumDistance, ikDistanceLimit.MaximumDistance);
            //var linearAxisLimit = new LinearAxisLimit(entityA, entityB, ikLinearAxisLimit.LineAnchor, ikLinearAxisLimit.AnchorB, ikLinearAxisLimit.LineDirection, ikLinearAxisLimit.MinimumDistance, ikLinearAxisLimit.MaximumDistance);
            //var twistJoint = new TwistJoint(entityA, entityB, Vector3.Up, Vector3.Up);
            //var pointOnLineJoint = new PointOnLineJoint(entityA, entityB, ikPointOnLineJoint.LineAnchor, ikPointOnLineJoint.LineDirection, ikPointOnLineJoint.AnchorB);
            var pointOnPlaneJoint = new PointOnPlaneJoint(entityA, entityB, ikPointOnPlaneJoint.PlaneAnchor, ikPointOnPlaneJoint.PlaneNormal, ikPointOnPlaneJoint.AnchorB);

            Space.Add(entityA);
            Space.Add(entityB);
            //Space.Add(joint);
            //Space.Add(limit);
            //Space.Add(revolute);
            //Space.Add(swivelHingeJoint);
            //Space.Add(angularJoint);
            //Space.Add(twistLimit);
            //Space.Add(distanceLimit);
            //Space.Add(linearAxisLimit);
            //Space.Add(twistJoint);
            //Space.Add(pointOnLineJoint);
            Space.Add(pointOnPlaneJoint);
            bones.Add(new BoneRelationship(a, entityA));
            bones.Add(new BoneRelationship(b, entityB));
        }