Example #1
0
        internal DigitalRuneDistanceRangeJoint(DistanceRangeJointDescriptor descriptor)
        {
            WrappedDistanceRangeJoint = new DistanceLimit();

            #region set RigidBodies
            if (!(descriptor.RigidBodyA is RigidBody))
            {
                throw new ArgumentException(String.Format("The type of the property 'RigidBodyA' must be '{0}'.", typeof(RigidBody)));
            }
            WrappedDistanceRangeJoint.BodyA = ((RigidBody)descriptor.RigidBodyA).WrappedRigidBody;
            _rigidBodyA = descriptor.RigidBodyA;

            if (!(descriptor.RigidBodyB is RigidBody))
            {
                throw new ArgumentException("The type of the property 'RigidBodyB' must be 'System.Physics.DigitalRune.RigidBody'.");
            }
            WrappedDistanceRangeJoint.BodyB = ((RigidBody)descriptor.RigidBodyB).WrappedRigidBody;
            _rigidBodyB = descriptor.RigidBodyB;
            #endregion
            WrappedDistanceRangeJoint.AnchorPositionALocal = descriptor.AnchorPositionALocal.ToDigitalRune();
            WrappedDistanceRangeJoint.AnchorPositionBLocal = descriptor.AnchorPositionBLocal.ToDigitalRune();
            WrappedDistanceRangeJoint.MinDistance          = descriptor.MinimumDistance;
            WrappedDistanceRangeJoint.MaxDistance          = descriptor.MaximumDistance;

            Descriptor = descriptor;
        }
Example #2
0
        public override SolverUpdateable GetBaseJoint()
        {
            DistanceLimit dl = new DistanceLimit(Ent1.Body, Ent2.Body, (Ent1Pos + Ent1.GetPosition()).ToBVector(), (Ent2Pos + Ent2.GetPosition()).ToBVector(), Min, Max);

            return(dl);
        }
Example #3
0
        public JointLimitTestDemo(DemosGame game)
            : base(game)
        {
            float bounciness = 1;
            float baseMass   = 100;
            float armMass    = 10;
            //DistanceLimit
            Box boxA = new Box(new Vector3(-21, 4, 0), 3, 3, 3, baseMass);
            Box boxB = new Box(boxA.Position + new Vector3(0, 5, 0), 1, 4, 1, armMass);

            CollisionRules.AddRule(boxA, boxB, CollisionRule.NoBroadPhase);
            boxB.ActivityInformation.IsAlwaysActive = true;

            var distanceLimit = new DistanceLimit(boxA, boxB, boxA.Position, boxB.Position - new Vector3(0, 2, 0), 1, 6);

            distanceLimit.Bounciness = bounciness;

            Space.Add(boxA);
            Space.Add(boxB);
            Space.Add(distanceLimit);

            //EllipseSwingLimit
            boxA = new Box(new Vector3(-14, 4, 0), 3, 3, 3, baseMass);
            boxB = new Box(boxA.Position + new Vector3(0, 5, 0), 1, 4, 1, armMass);
            CollisionRules.AddRule(boxA, boxB, CollisionRule.NoBroadPhase);
            boxB.ActivityInformation.IsAlwaysActive = true;

            var ballSocketJoint   = new BallSocketJoint(boxA, boxB, boxB.Position + new Vector3(0, -2, 0));
            var ellipseSwingLimit = new EllipseSwingLimit(boxA, boxB, Vector3.Up, MathHelper.Pi / 1.5f, MathHelper.Pi / 3);

            ellipseSwingLimit.Bounciness = bounciness;

            Space.Add(boxA);
            Space.Add(boxB);
            Space.Add(ballSocketJoint);
            Space.Add(ellipseSwingLimit);

            //LinearAxisLimit
            boxA = new Box(new Vector3(-7, 4, 0), 3, 3, 3, baseMass);
            boxB = new Box(boxA.Position + new Vector3(0, 5, 0), 1, 4, 1, armMass);
            CollisionRules.AddRule(boxA, boxB, CollisionRule.NoBroadPhase);
            boxB.ActivityInformation.IsAlwaysActive = true;

            var pointOnLineJoint = new PointOnLineJoint(boxA, boxB, boxA.Position, Vector3.Up, boxB.Position + new Vector3(0, -2, 0));
            var linearAxisLimit  = new LinearAxisLimit(boxA, boxB, boxA.Position, boxB.Position + new Vector3(0, -2, 0), Vector3.Up, 0, 4);

            linearAxisLimit.Bounciness = bounciness;

            Space.Add(boxA);
            Space.Add(boxB);
            Space.Add(pointOnLineJoint);
            Space.Add(linearAxisLimit);

            //RevoluteLimit
            boxA = new Box(new Vector3(0, 4, 0), 3, 3, 3, baseMass);
            boxB = new Box(boxA.Position + new Vector3(0, 5, 0), 1, 4, 1, armMass);
            CollisionRules.AddRule(boxA, boxB, CollisionRule.NoBroadPhase);
            boxB.ActivityInformation.IsAlwaysActive = true;

            ballSocketJoint = new BallSocketJoint(boxA, boxB, boxB.Position + new Vector3(0, -2, 0));
            var revoluteAngularJoint = new RevoluteAngularJoint(boxA, boxB, Vector3.Forward);
            var revoluteLimit        = new RevoluteLimit(boxA, boxB, Vector3.Forward, Vector3.Up, -MathHelper.PiOver4, MathHelper.PiOver4);

            revoluteLimit.Bounciness = bounciness;

            Space.Add(boxA);
            Space.Add(boxB);
            Space.Add(ballSocketJoint);
            Space.Add(revoluteAngularJoint);
            Space.Add(revoluteLimit);

            //SwingLimit
            boxA = new Box(new Vector3(7, 4, 0), 3, 3, 3, baseMass);
            boxB = new Box(boxA.Position + new Vector3(0, 5, 0), 1, 4, 1, armMass);
            CollisionRules.AddRule(boxA, boxB, CollisionRule.NoBroadPhase);
            boxB.ActivityInformation.IsAlwaysActive = true;

            ballSocketJoint = new BallSocketJoint(boxA, boxB, boxB.Position + new Vector3(0, -2, 0));
            var swingLimit = new SwingLimit(boxA, boxB, Vector3.Up, Vector3.Up, MathHelper.PiOver4);

            swingLimit.Bounciness = bounciness;

            Space.Add(boxA);
            Space.Add(boxB);
            Space.Add(ballSocketJoint);
            Space.Add(swingLimit);

            //TwistLimit
            boxA = new Box(new Vector3(14, 4, 0), 3, 3, 3, baseMass);
            boxB = new Box(boxA.Position + new Vector3(0, 5, 0), 1, 4, 1, armMass);
            CollisionRules.AddRule(boxA, boxB, CollisionRule.NoBroadPhase);
            boxB.ActivityInformation.IsAlwaysActive = true;

            ballSocketJoint      = new BallSocketJoint(boxA, boxB, boxB.Position + new Vector3(0, -2, 0));
            revoluteAngularJoint = new RevoluteAngularJoint(boxA, boxB, Vector3.Up);
            var twistLimit = new TwistLimit(boxA, boxB, Vector3.Up, Vector3.Up, -MathHelper.PiOver4, MathHelper.PiOver4);

            twistLimit.Bounciness = bounciness;

            Space.Add(boxA);
            Space.Add(boxB);
            Space.Add(ballSocketJoint);
            Space.Add(revoluteAngularJoint);
            Space.Add(twistLimit);

            Space.Add(new Box(new Vector3(0, 0, 0), 60, 1, 60));
            game.Camera.Position = new Vector3(0, 6, 15);
        }
Example #4
0
        public override void Update(Window window, Camera camera, Input input, float dt)
        {
            if (input.WasPushed(OpenTK.Input.Key.Z))
            {
                _jointDistance++;
                ChangeLenght(_jointDistance);
            }

            if (input.WasPushed(OpenTK.Input.Key.X))
            {
                _jointDistance--;
                ChangeLenght(_jointDistance);
            }


            if (input.WasPushed(OpenTK.Input.Key.C))
            {
                if (_jointIndex == -1)
                {
                    var baseIndex = _baseReference.Handle;
                    var boxIndex  = _boxReference.Handle;



                    var distanceJoint = new DistanceLimit(Vector3.Zero, new Vector3(0, .51f, 0), 5f, 5f, new SpringSettings(5, 1));
                    _jointIndex = Simulation.Solver.Add(baseIndex, boxIndex, distanceJoint);

                    var angularSwivelHinge = new AngularHinge()
                    {
                        LocalHingeAxisA = Vector3.UnitY, LocalHingeAxisB = Vector3.UnitY, SpringSettings = new SpringSettings(20f, .0001f)
                    };
                    _angularHingeIndex = Simulation.Solver.Add(baseIndex, boxIndex, angularSwivelHinge);


                    var linearMotor = new OneBodyLinearMotor()
                    {
                        TargetVelocity = new Vector3(0, 0, 0), Settings = new MotorSettings(20, 1f)
                    };
                    _linearMotorIndex = Simulation.Solver.Add(boxIndex, linearMotor);

                    _poseIntegrator.CustomAngularDamping(boxIndex, .5f, BufferPool);
                    _poseIntegrator.CustomLinearDamping(boxIndex, .5f, BufferPool);
                }
            }


            if (input.WasPushed(OpenTK.Input.Key.V))
            {
                RemoveContrait(ref _jointIndex);
                RemoveContrait(ref _linearMotorIndex);
                RemoveContrait(ref _angularHingeIndex);
            }


            var hasVelocity = false;

            var newVelocity = Vector3.Zero;

            if (input.WasDown(OpenTK.Input.Key.Left))
            {
                hasVelocity    = true;
                newVelocity.X += 2;
            }

            if (input.WasDown(OpenTK.Input.Key.Right))
            {
                hasVelocity    = true;
                newVelocity.X += -2;
            }

            _baseReference.Velocity.Linear = newVelocity;

            if (hasVelocity)
            {
                Simulation.Awakener.AwakenBody(_baseReference.Handle);
            }



            base.Update(window, camera, input, dt);
        }
Example #5
0
        unsafe void ChangeLenght(float lenght)
        {
            var distanceJoint = new DistanceLimit(Vector3.Zero, Vector3.Zero, lenght, lenght, new SpringSettings(10f, 10f));

            Simulation.Solver.ApplyDescription(_jointIndex, ref distanceJoint);
        }
        void ReleaseDesignerOutlets()
        {
            if (ActionBar != null)
            {
                ActionBar.Dispose();
                ActionBar = null;
            }

            if (AddressOK != null)
            {
                AddressOK.Dispose();
                AddressOK = null;
            }

            if (BottomConstraint != null)
            {
                BottomConstraint.Dispose();
                BottomConstraint = null;
            }

            if (BottomSeparator != null)
            {
                BottomSeparator.Dispose();
                BottomSeparator = null;
            }

            if (DistanceFilters != null)
            {
                DistanceFilters.Dispose();
                DistanceFilters = null;
            }

            if (DistanceFiltersOpenClose != null)
            {
                DistanceFiltersOpenClose.Dispose();
                DistanceFiltersOpenClose = null;
            }

            if (DistanceLimit != null)
            {
                DistanceLimit.Dispose();
                DistanceLimit = null;
            }

            if (DistanceLimitInput != null)
            {
                DistanceLimitInput.Dispose();
                DistanceLimitInput = null;
            }

            if (DistanceSourceAddress != null)
            {
                DistanceSourceAddress.Dispose();
                DistanceSourceAddress = null;
            }

            if (DistanceSourceAddressLabel != null)
            {
                DistanceSourceAddressLabel.Dispose();
                DistanceSourceAddressLabel = null;
            }

            if (DistanceSourceAddressText != null)
            {
                DistanceSourceAddressText.Dispose();
                DistanceSourceAddressText = null;
            }

            if (DistanceSourceCurrent != null)
            {
                DistanceSourceCurrent.Dispose();
                DistanceSourceCurrent = null;
            }

            if (DistanceSourceCurrentLabel != null)
            {
                DistanceSourceCurrentLabel.Dispose();
                DistanceSourceCurrentLabel = null;
            }

            if (DistanceUnitText != null)
            {
                DistanceUnitText.Dispose();
                DistanceUnitText = null;
            }

            if (FilterLayout != null)
            {
                FilterLayout.Dispose();
                FilterLayout = null;
            }

            if (ListType != null)
            {
                ListType.Dispose();
                ListType = null;
            }

            if (ListView != null)
            {
                ListView.Dispose();
                ListView = null;
            }

            if (ListViewMap != null)
            {
                ListViewMap.Dispose();
                ListViewMap = null;
            }

            if (LoaderCircle != null)
            {
                LoaderCircle.Dispose();
                LoaderCircle = null;
            }

            if (LoaderCircleLeftConstraint != null)
            {
                LoaderCircleLeftConstraint.Dispose();
                LoaderCircleLeftConstraint = null;
            }

            if (LoadNext != null)
            {
                LoadNext.Dispose();
                LoadNext = null;
            }

            if (LoadPrevious != null)
            {
                LoadPrevious.Dispose();
                LoadPrevious = null;
            }

            if (MapSatellite != null)
            {
                MapSatellite.Dispose();
                MapSatellite = null;
            }

            if (MapStreet != null)
            {
                MapStreet.Dispose();
                MapStreet = null;
            }

            if (MapView != null)
            {
                MapView.Dispose();
                MapView = null;
            }

            if (MenuAbout != null)
            {
                MenuAbout.Dispose();
                MenuAbout = null;
            }

            if (MenuChatList != null)
            {
                MenuChatList.Dispose();
                MenuChatList = null;
            }

            if (MenuChatListBg != null)
            {
                MenuChatListBg.Dispose();
                MenuChatListBg = null;
            }

            if (MenuChatListBgCorner != null)
            {
                MenuChatListBgCorner.Dispose();
                MenuChatListBgCorner = null;
            }

            if (MenuContainer != null)
            {
                MenuContainer.Dispose();
                MenuContainer = null;
            }

            if (MenuHelpCenter != null)
            {
                MenuHelpCenter.Dispose();
                MenuHelpCenter = null;
            }

            if (MenuIcon != null)
            {
                MenuIcon.Dispose();
                MenuIcon = null;
            }

            if (MenuLayer != null)
            {
                MenuLayer.Dispose();
                MenuLayer = null;
            }

            if (MenuLocation != null)
            {
                MenuLocation.Dispose();
                MenuLocation = null;
            }

            if (MenuLogIn != null)
            {
                MenuLogIn.Dispose();
                MenuLogIn = null;
            }

            if (MenuLogOut != null)
            {
                MenuLogOut.Dispose();
                MenuLogOut = null;
            }

            if (MenuRegister != null)
            {
                MenuRegister.Dispose();
                MenuRegister = null;
            }

            if (MenuSettings != null)
            {
                MenuSettings.Dispose();
                MenuSettings = null;
            }

            if (NoResult != null)
            {
                NoResult.Dispose();
                NoResult = null;
            }

            if (OpenFilters != null)
            {
                OpenFilters.Dispose();
                OpenFilters = null;
            }

            if (OpenSearch != null)
            {
                OpenSearch.Dispose();
                OpenSearch = null;
            }

            if (OrderBy != null)
            {
                OrderBy.Dispose();
                OrderBy = null;
            }

            if (RefreshDistance != null)
            {
                RefreshDistance.Dispose();
                RefreshDistance = null;
            }

            if (ResultSet != null)
            {
                ResultSet.Dispose();
                ResultSet = null;
            }

            if (RippleMain != null)
            {
                RippleMain.Dispose();
                RippleMain = null;
            }

            if (RippleRefreshDistance != null)
            {
                RippleRefreshDistance.Dispose();
                RippleRefreshDistance = null;
            }

            if (RoundBottom != null)
            {
                RoundBottom.Dispose();
                RoundBottom = null;
            }

            if (SearchIn != null)
            {
                SearchIn.Dispose();
                SearchIn = null;
            }

            if (SearchLayout != null)
            {
                SearchLayout.Dispose();
                SearchLayout = null;
            }

            if (SearchTerm != null)
            {
                SearchTerm.Dispose();
                SearchTerm = null;
            }

            if (Snackbar != null)
            {
                Snackbar.Dispose();
                Snackbar = null;
            }

            if (SnackBottomConstraint != null)
            {
                SnackBottomConstraint.Dispose();
                SnackBottomConstraint = null;
            }

            if (SnackTopConstraint != null)
            {
                SnackTopConstraint.Dispose();
                SnackTopConstraint = null;
            }

            if (SortBy_LastActiveDate != null)
            {
                SortBy_LastActiveDate.Dispose();
                SortBy_LastActiveDate = null;
            }

            if (SortBy_RegisterDate != null)
            {
                SortBy_RegisterDate.Dispose();
                SortBy_RegisterDate = null;
            }

            if (SortBy_ResponseRate != null)
            {
                SortBy_ResponseRate.Dispose();
                SortBy_ResponseRate = null;
            }

            if (SortByCaption != null)
            {
                SortByCaption.Dispose();
                SortByCaption = null;
            }

            if (StatusBar != null)
            {
                StatusBar.Dispose();
                StatusBar = null;
            }

            if (StatusImage != null)
            {
                StatusImage.Dispose();
                StatusImage = null;
            }

            if (StatusText != null)
            {
                StatusText.Dispose();
                StatusText = null;
            }

            if (UseGeoContainer != null)
            {
                UseGeoContainer.Dispose();
                UseGeoContainer = null;
            }

            if (UseGeoNo != null)
            {
                UseGeoNo.Dispose();
                UseGeoNo = null;
            }

            if (UseGeoNoLabel != null)
            {
                UseGeoNoLabel.Dispose();
                UseGeoNoLabel = null;
            }

            if (UseGeoYes != null)
            {
                UseGeoYes.Dispose();
                UseGeoYes = null;
            }

            if (UseGeoYesLabel != null)
            {
                UseGeoYesLabel.Dispose();
                UseGeoYesLabel = null;
            }

            if (UserSearchList != null)
            {
                UserSearchList.Dispose();
                UserSearchList = null;
            }
        }
Example #7
0
        public ConstraintSample2(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Add basic force effects.
            Simulation.ForceEffects.Add(new Gravity());
            Simulation.ForceEffects.Add(new Damping());

            // Add a ground plane.
            RigidBody groundPlane = new RigidBody(new PlaneShape(Vector3F.UnitY, 0))
            {
                Name       = "GroundPlane", // Names are not required but helpful for debugging.
                MotionType = MotionType.Static,
            };

            Simulation.RigidBodies.Add(groundPlane);

            // ----- PointOnLineConstraint
            RigidBody box0 = new RigidBody(new BoxShape(0.1f, 0.5f, 6))
            {
                Pose       = new Pose(new Vector3F(-4, 3, 0)),
                MotionType = MotionType.Static,
            };

            Simulation.RigidBodies.Add(box0);
            RigidBody sphere0 = new RigidBody(new SphereShape(0.5f))
            {
                Pose = new Pose(new Vector3F(-4, 2, 0))
            };

            Simulation.RigidBodies.Add(sphere0);
            PointOnLineConstraint pointOnLineConstraint = new PointOnLineConstraint
            {
                BodyA = box0,
                // The line goes through this point:
                AnchorPositionALocal = new Vector3F(0, -0.25f, 0),
                BodyB = sphere0,
                AnchorPositionBLocal = new Vector3F(0, 0.5f, 0),
                // The line axis:
                AxisALocal = Vector3F.UnitZ,
                // The movement on the line axis:
                Minimum          = -3,
                Maximum          = +3,
                CollisionEnabled = false,
            };

            Simulation.Constraints.Add(pointOnLineConstraint);

            // ----- PointOnPlaneConstraint
            RigidBody box1 = new RigidBody(new BoxShape(2f, 0.5f, 6))
            {
                Pose       = new Pose(new Vector3F(-1, 3, 0)),
                MotionType = MotionType.Static,
            };

            Simulation.RigidBodies.Add(box1);
            RigidBody sphere1 = new RigidBody(new SphereShape(0.5f))
            {
                Pose = new Pose(new Vector3F(-1, 2, 0))
            };

            Simulation.RigidBodies.Add(sphere1);
            PointOnPlaneConstraint pointOnPlaneConstraint = new PointOnPlaneConstraint
            {
                BodyA = box1,
                // The plane goes through this point:
                AnchorPositionALocal = new Vector3F(0, -0.25f, 0),
                BodyB = sphere1,
                AnchorPositionBLocal = new Vector3F(0, 0.5f, 0),
                // Two orthonormal vectors that define the plane:
                XAxisALocal = Vector3F.UnitX,
                YAxisALocal = Vector3F.UnitZ,
                // Limits for the x axis and y axis movement:
                Minimum          = new Vector2F(-1, -3),
                Maximum          = new Vector2F(1, 3),
                CollisionEnabled = false,
            };

            Simulation.Constraints.Add(pointOnPlaneConstraint);

            // ----- NoRotationConstraint
            // This constraint keeps two rotations synchronized.
            RigidBody box2 = new RigidBody(new BoxShape(1, 1, 1))
            {
                Pose = new Pose(new Vector3F(2, 3, 0)),
            };

            Simulation.RigidBodies.Add(box2);
            RigidBody box3 = new RigidBody(new BoxShape(1, 1, 1))
            {
                Pose = new Pose(new Vector3F(2.5f, 2, 0))
            };

            Simulation.RigidBodies.Add(box3);
            NoRotationConstraint noRotationConstraint = new NoRotationConstraint
            {
                BodyA            = box2,
                BodyB            = box3,
                CollisionEnabled = true,
            };

            Simulation.Constraints.Add(noRotationConstraint);

            // ----- Distance limit.
            // Here, the distance of two cone tips is kept at a constant distance.
            RigidBody cone0 = new RigidBody(new ConeShape(0.5f, 1f))
            {
                Pose       = new Pose(new Vector3F(4, 3, 0), Matrix33F.CreateRotationZ(ConstantsF.Pi)),
                MotionType = MotionType.Static,
            };

            Simulation.RigidBodies.Add(cone0);
            RigidBody cone1 = new RigidBody(new ConeShape(0.5f, 1f))
            {
                Pose = new Pose(new Vector3F(4, 0, 0))
            };

            Simulation.RigidBodies.Add(cone1);
            DistanceLimit distanceLimit = new DistanceLimit
            {
                BodyA = cone0,
                BodyB = cone1,
                // The attachment points are the tips of the cones.
                AnchorPositionALocal = new Vector3F(0, 1, 0),
                AnchorPositionBLocal = new Vector3F(0, 1, 0),
                // The tips should always have a distance of 0.5 units.
                MinDistance = 0.5f,
                MaxDistance = 0.5f,
            };

            Simulation.Constraints.Add(distanceLimit);
        }