コード例 #1
0
        public override void Update(float deltaTime, Camera cam)
        {
            ApplyStatusEffects(ActionType.OnActive, deltaTime, null);

            if (stickJoint != null && stickJoint.JointTranslation < 0.01f)
            {
                if (stickTarget != null)
                {
                    try
                    {
                        item.body.FarseerBody.RestoreCollisionWith(stickTarget);
                    }
                    catch
                    {
                        //the body that the projectile was stuck to has been removed
                    }

                    stickTarget = null;
                }

                try
                {
                    GameMain.World.RemoveJoint(stickJoint);
                }
                catch
                {
                    //the body that the projectile was stuck to has been removed
                }

                stickJoint = null;

                IsActive = false;
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a prismatic joint and adds it to the world
        /// </summary>
        /// <param name="world"></param>
        /// <param name="bodyA"></param>
        /// <param name="bodyB"></param>
        /// <param name="anchor"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public static PrismaticJoint CreatePrismaticJoint(World world, Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis)
        {
            PrismaticJoint joint = new PrismaticJoint(bodyA, bodyB, anchor, axis);

            world.AddJoint(joint);
            return(joint);
        }
コード例 #3
0
        private PrismaticTest()
        {
            Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            PolygonShape shape = new PolygonShape(5);

            shape.Vertices = PolygonTools.CreateRectangle(2.0f, 0.5f);

            Body body = BodyFactory.CreateBody(World);

            body.BodyType = BodyType.Dynamic;
            body.Position = new Vector2(-10.0f, 10.0f);
            body.Rotation = 0.5f * Settings.Pi;
            body.CreateFixture(shape);

            // Bouncy limit
            Vector2 axis = new Vector2(2.0f, 1.0f);

            axis.Normalize();
            _joint = new PrismaticJoint(ground, body, Vector2.Zero, Vector2.Zero, axis, true);

            // Non-bouncy limit
            //_joint = new PrismaticJoint(ground, body2, body2.Position, new Vector2(-10.0f, 10.0f), new Vector2(1.0f, 0.0f));

            _joint.MotorSpeed    = 5.0f;
            _joint.MaxMotorForce = 1000.0f;
            _joint.MotorEnabled  = true;
            _joint.LowerLimit    = -10.0f;
            _joint.UpperLimit    = 20.0f;
            _joint.LimitEnabled  = true;

            World.AddJoint(_joint);
        }
コード例 #4
0
        /// <summary>
        /// Creates a prsimatic joint
        /// </summary>
        /// <param name="bodyA"></param>
        /// <param name="bodyB"></param>
        /// <param name="localanchorB"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public static PrismaticJoint CreatePrismaticJoint(Body bodyA, Body bodyB, Vector2 localanchorB, Vector2 axis)
        {
            Vector2        localanchorA = bodyA.GetLocalPoint(bodyB.GetWorldPoint(localanchorB));
            PrismaticJoint joint        = new PrismaticJoint(bodyA, bodyB, localanchorA, localanchorB, axis);

            return(joint);
        }
コード例 #5
0
        public Paddle(PlayerIndex playerIndex, GameplayManager gm, Vector2 position, float width, float height, float maxTranslation, World world) : base(world)
        {
            this.playerIndex    = playerIndex;
            this.gm             = gm;
            this.width          = width;
            this.height         = height;
            this.maxTranslation = maxTranslation;
            startPos            = new Vector2(position.X, position.Y);

            body                     = BodyFactory.CreateRectangle(world, width, height, 1, position);
            body.BodyType            = BodyType.Dynamic;
            body.CollidesWith        = Category.Cat1 | Category.Cat3;
            body.CollisionCategories = Category.Cat2;
            body.Restitution         = 1.0f;
            body.Friction            = 0.0f;
            body.UserData            = this;

            ground = BodyFactory.CreateRectangle(world, 1, 1, 1);


            joint              = JointFactory.CreatePrismaticJoint(world, ground, body, position, new Vector2(1, 0), true);
            joint.LowerLimit   = -maxTranslation + width / 2.0f;
            joint.UpperLimit   = maxTranslation - width / 2.0f;
            joint.LimitEnabled = true;
            body.LinearDamping = 7.0f;
        }
コード例 #6
0
        internal DigitalRunePrismaticJoint(PrismaticJointDescriptor descriptor)
        {
            WrappedPrismaticJoint = new PrismaticJoint();

            #region set RigidBodies
            if (!(descriptor.RigidBodyA is RigidBody))
            {
                throw new ArgumentException(String.Format("The type of the property 'RigidBodyA' must be '{0}'.", typeof(RigidBody)));
            }
            WrappedPrismaticJoint.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'.");
            }
            WrappedPrismaticJoint.BodyB = ((RigidBody)descriptor.RigidBodyB).WrappedRigidBody;
            _rigidBodyB = descriptor.RigidBodyB;
            #endregion
            WrappedPrismaticJoint.AnchorPoseALocal = descriptor.AnchorPoseALocal.ToDigitalRune();
            WrappedPrismaticJoint.AnchorPoseBLocal = descriptor.AnchorPoseBLocal.ToDigitalRune();
            WrappedPrismaticJoint.Maximum          = descriptor.MaximumDistance;
            WrappedPrismaticJoint.Minimum          = descriptor.MinimumDistance;



            Descriptor = descriptor;
        }
コード例 #7
0
        private void DoLaunch(Vector2 impulse)
        {
            hits.Clear();

            if (item.AiTarget != null)
            {
                item.AiTarget.SightRange = item.AiTarget.MaxSightRange;
                item.AiTarget.SoundRange = item.AiTarget.MaxSoundRange;
            }

            item.Drop(null);

            launchPos = item.SimPosition;

            item.body.Enabled = true;
            item.body.ApplyLinearImpulse(impulse, maxVelocity: NetConfig.MaxPhysicsBodyVelocity * 0.9f);

            item.body.FarseerBody.OnCollision += OnProjectileCollision;
            item.body.FarseerBody.IsBullet     = true;

            item.body.CollisionCategories = Physics.CollisionProjectile;
            item.body.CollidesWith        = Physics.CollisionCharacter | Physics.CollisionWall | Physics.CollisionLevel;

            IsActive = true;

            if (stickJoint == null)
            {
                return;
            }

            StickTarget = null;
            GameMain.World.Remove(stickJoint);
            stickJoint = null;
        }
コード例 #8
0
        public static PrismaticJoint CreatePrismaticJoint(World world, Body bodyA, Body bodyB, Vector2 anchor, Vector2 axis, bool useWorldCoordinates = false)
        {
            PrismaticJoint joint = new PrismaticJoint(bodyA, bodyB, anchor, axis, useWorldCoordinates);

            world.addJoint(joint);
            return(joint);
        }
コード例 #9
0
        private void StickToTarget(Body targetBody, Vector2 axis)
        {
            if (stickJoint != null)
            {
                return;
            }

            stickJoint = new PrismaticJoint(targetBody, item.body.FarseerBody, item.body.SimPosition, axis, true)
            {
                MotorEnabled  = true,
                MaxMotorForce = 30.0f,
                LimitEnabled  = true
            };
            if (item.Sprite != null)
            {
                stickJoint.LowerLimit = ConvertUnits.ToSimUnits(item.Sprite.size.X * -0.3f);
                stickJoint.UpperLimit = ConvertUnits.ToSimUnits(item.Sprite.size.X * 0.3f);
            }

            persistentStickJointTimer = PersistentStickJointDuration;

            item.body.FarseerBody.IgnoreCollisionWith(targetBody);
            stickTarget = targetBody;
            GameMain.World.AddJoint(stickJoint);

            IsActive = true;
        }
コード例 #10
0
        public override void Build()
        {
            AddGround();

            RigidBody body1 = new RigidBody(new BoxShape(1, 1, 1));
            RigidBody body2 = new RigidBody(new BoxShape(1, 1, 1));

            body1.Position = new JVector(0, 7, 0);
            body2.Position = new JVector(0, 4, 0);

            // add a prismatic joint.
            // the minimum allowed distance is 3
            // the maximum allowed distance is also 3
            // => the body should be fixed on the slider
            PrismaticJoint pj = new PrismaticJoint(Demo.World, body1, body2, 3, 3);

            // but we set very heigh softness (1.0f) to the minimum distance
            // so we have something like a suspension effect.
            pj.MaximumDistanceConstraint.Softness = 0.0f;
            pj.MinimumDistanceConstraint.Softness = 1.0f;
            pj.Activate();

            Demo.World.AddBody(body1);
            Demo.World.AddBody(body2);
        }
コード例 #11
0
ファイル: PhysicWorld.cs プロジェクト: JKVX/J-Gzimo
        private void addBaffleX(Body body)
        {
            try
            {
                if (body.GetUserData() == null)
                {
                    return;
                }
                GizmoComponents myGizmo = (GizmoComponents)body.GetUserData();
                //添加Shape
                addPolygon(body);

                BodyDef kinematicBodyDef = new BodyDef();
                kinematicBodyDef.Position.Set(0, myGizmo.PositionY);
                Body kinematicBody = myWorld.CreateBody(kinematicBodyDef);

                PrismaticJointDef jointDef = new PrismaticJointDef();
                Vec2 worldAxis             = new Vec2(1, 0);
                jointDef.Initialize(body, kinematicBody, kinematicBody.GetWorldCenter(), worldAxis);
                jointDef.LowerTranslation = -100f;
                jointDef.UpperTranslation = 100f;
                jointDef.EnableLimit      = true;
                PrismaticJoint joint = (PrismaticJoint)myWorld.CreateJoint(jointDef);
            }
            catch (Exception e)
            {
                MessageBox.Show("PhysicalWorld-addBaffleX函数出错");
            }
        }
コード例 #12
0
        /// <summary>
        /// Creates a prismatic joint and adds it to the world
        /// </summary>
        /// <param name="world"></param>
        /// <param name="bodyA"></param>
        /// <param name="bodyB"></param>
        /// <param name="localanchorB"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public static PrismaticJoint CreatePrismaticJoint(World world, Body bodyA, Body bodyB, FVector2 localanchorB,
                                                          FVector2 axis)
        {
            PrismaticJoint joint = CreatePrismaticJoint(bodyA, bodyB, localanchorB, axis);

            world.AddJoint(joint);
            return(joint);
        }
コード例 #13
0
        public override PhysicsJoint CreateLineJoint(PhysicsBody bodyA, PhysicsBody bodyB,
                                                     Vector2D axis)
        {
            PrismaticJoint farseerJoint = JointFactory.CreatePrismaticJoint(((FarseerBody)bodyA).Body,
                                                                            ((FarseerBody)bodyB).Body, ((FarseerBody)bodyB).Body.Position, unitConverter.Convert(axis));

            world.AddJoint(farseerJoint);
            return(new FarseerJoint(farseerJoint, bodyA, bodyB));
        }
コード例 #14
0
        public override void Update(float deltaTime, Camera cam)
        {
            ApplyStatusEffects(ActionType.OnActive, deltaTime, null);

            if (item.body != null && item.body.FarseerBody.IsBullet)
            {
                if (item.body.LinearVelocity.LengthSquared() < ContinuousCollisionThreshold * ContinuousCollisionThreshold)
                {
                    item.body.FarseerBody.IsBullet = false;
                    //projectiles with a stickjoint don't become inactive until the stickjoint is detached
                    if (stickJoint == null)
                    {
                        IsActive = false;
                    }
                }
            }

            if (stickJoint == null)
            {
                return;
            }

            if (persistentStickJointTimer > 0.0f)
            {
                persistentStickJointTimer -= deltaTime;
                return;
            }

            if (stickJoint.JointTranslation < stickJoint.LowerLimit * 0.9f || stickJoint.JointTranslation > stickJoint.UpperLimit * 0.9f)
            {
                if (stickTarget != null)
                {
                    if (GameMain.World.BodyList.Contains(stickTarget))
                    {
                        item.body.FarseerBody.RestoreCollisionWith(stickTarget);
                    }

                    stickTarget = null;
                }

                if (stickJoint != null)
                {
                    if (GameMain.World.JointList.Contains(stickJoint))
                    {
                        GameMain.World.RemoveJoint(stickJoint);
                    }

                    stickJoint = null;
                }

                if (!item.body.FarseerBody.IsBullet)
                {
                    IsActive = false;
                }
            }
        }
コード例 #15
0
 private PrismaticJoint CreateJoint()
 {
     if (useDistances)
     {
         var j = new PrismaticJoint(JPhysics.World, Body1.Body, Body2.Body, minDistance, maxDistance);
         j.MinimumDistanceConstraint.Softness = minDistanceSoftness;
         j.MaximumDistanceConstraint.Softness = maxDistanceSoftness;
         return(j);
     }
     return(new PrismaticJoint(JPhysics.World, Body1.Body, Body2.Body));
 }
コード例 #16
0
        private PrismaticTest()
        {
            Body ground;
            {
                ground = BodyFactory.CreateBody(World);

                EdgeShape shape3 = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                ground.CreateFixture(shape3);
            }

            PolygonShape shape = new PolygonShape(5);

            shape.SetAsBox(2.0f, 0.5f);

            Body body = BodyFactory.CreateBody(World);

            body.BodyType = BodyType.Dynamic;
            body.Position = new Vector2(0.0f, 10.0f);

            body.CreateFixture(shape);

            _fixedJoint               = new FixedPrismaticJoint(body, body.Position, new Vector2(0.5f, 1.0f));
            _fixedJoint.MotorSpeed    = 5.0f;
            _fixedJoint.MaxMotorForce = 1000.0f;
            _fixedJoint.MotorEnabled  = true;
            _fixedJoint.LowerLimit    = -10.0f;
            _fixedJoint.UpperLimit    = 20.0f;
            _fixedJoint.LimitEnabled  = true;

            World.AddJoint(_fixedJoint);

            PolygonShape shape2 = new PolygonShape(5);

            shape2.SetAsBox(2.0f, 0.5f);

            Body body2 = BodyFactory.CreateBody(World);

            body2.BodyType = BodyType.Dynamic;
            body2.Position = new Vector2(10.0f, 10.0f);

            body2.CreateFixture(shape2);

            _joint = new PrismaticJoint(ground, body2, ground.GetLocalPoint(body2.Position), Vector2.Zero,
                                        new Vector2(0.5f, 1.0f));
            _joint.MotorSpeed    = 5.0f;
            _joint.MaxMotorForce = 1000.0f;
            _joint.MotorEnabled  = true;
            _joint.LowerLimit    = -10.0f;
            _joint.UpperLimit    = 20.0f;
            _joint.LimitEnabled  = true;

            World.AddJoint(_joint);
        }
コード例 #17
0
        /// <summary>
        /// Creates a distance joint between two bodies
        /// </summary>
        /// <param name="b1"></param>
        /// <param name="b2"></param>
        /// <param name="anchor"></param>
        /// <param name="axis"></param>
        public void joinBodies_Prismatic(Body b1, Body b2, Vector2 anchor, Vector2 axis)
        {
            PrismaticJointDef pjd = new PrismaticJointDef();

            pjd.upperTranslation = 1;
            pjd.lowerTranslation = -1;
            pjd.enableMotor      = true;
            pjd.maxMotorForce    = 1000;
            pjd.motorSpeed       = 1;
            pjd.Initialize(b1, b2, anchor, axis);
            PrismaticJoint pj = physicsWorld.CreateJoint(pjd) as PrismaticJoint;
        }
コード例 #18
0
        public override Joint CreateJoint()
        {
            var joint = new PrismaticJoint(BodyA, BodyB, OwnerBodyAnchor * FSConvert.DisplayToSim, OtherBodyAnchor * FSConvert.DisplayToSim);

            joint.CollideConnected = CollideConnected;
            joint.Axis             = Axis;
            joint.LimitEnabled     = LimitEnabled;
            joint.LowerLimit       = LowerLimit;
            joint.UpperLimit       = UpperLimit;
            joint.MotorEnabled     = MotorEnabled;
            joint.MotorSpeed       = MotorSpeed;
            joint.MaxMotorForce    = MaxMotorForce;
            joint.MotorImpulse     = MotorImpulse;
            return(joint);
        }
コード例 #19
0
        private void CreatePrismaticJoint(JitterPhysics physicsManager)
        {
            Joint = new PrismaticJoint(physicsManager.jitterWorld, RigidBodyA, RigidBodyB,
                                       ArrayExtensions.GetWithDefault <PropertyType, float>(Properties,
                                                                                            PropertyType.MinimumDistance),
                                       ArrayExtensions.GetWithDefault <PropertyType, float>(Properties,
                                                                                            PropertyType.MaximumDistance));
            float minimumSoftness = ArrayExtensions.GetWithDefault <PropertyType, float>(Properties,
                                                                                         PropertyType.MinimumSoftness);
            float maximumSoftness = ArrayExtensions.GetWithDefault <PropertyType, float>(Properties,
                                                                                         PropertyType.MaximumSoftness);

            (Joint as PrismaticJoint).MaximumDistanceConstraint.Softness = maximumSoftness;
            (Joint as PrismaticJoint).MinimumDistanceConstraint.Softness = minimumSoftness;
        }
コード例 #20
0
        /// <summary>
        /// Creates a distance joint between two bodies
        /// </summary>
        /// <param name="b1"></param>
        /// <param name="b2"></param>
        /// <param name="anchor"></param>
        /// <param name="axis"></param>
        /// <param name="uppertranslation"></param>
        /// <param name="lowertranslation"></param>
        /// <param name="motorspeed"></param>
        public void joinBodies_Prismatic(Body b1, Body b2, Vector2 anchor, Vector2 axis, float uppertranslation, float lowertranslation, float motorspeed)
        {
            PrismaticJointDef pjd = new PrismaticJointDef();

            pjd.Initialize(b1, b2, anchor, axis);
            if (motorspeed != 0)
            {
                pjd.enableMotor = true;
            }
            pjd.motorSpeed       = motorspeed;
            pjd.lowerTranslation = lowertranslation;
            pjd.upperTranslation = uppertranslation;

            PrismaticJoint pj = physicsWorld.CreateJoint(pjd) as PrismaticJoint;
        }
コード例 #21
0
        public override Joint createJoint()
        {
            var joint = new PrismaticJoint(bodyA, bodyB, ownerBodyAnchor * FSConvert.displayToSim, otherBodyAnchor * FSConvert.displayToSim);

            joint.collideConnected = collideConnected;
            joint.axis             = axis;
            joint.limitEnabled     = limitEnabled;
            joint.lowerLimit       = lowerLimit;
            joint.upperLimit       = upperLimit;
            joint.motorEnabled     = motorEnabled;
            joint.motorSpeed       = motorSpeed;
            joint.maxMotorForce    = maxMotorForce;
            joint.motorImpulse     = motorImpulse;
            return(joint);
        }
コード例 #22
0
        protected override void RemoveComponentSpecific()
        {
            if (stickJoint != null)
            {
                try
                {
                    GameMain.World.RemoveJoint(stickJoint);
                }
                catch
                {
                    //the body that the projectile was stuck to has been removed
                }

                stickJoint = null;
            }
        }
コード例 #23
0
 public override void Update(GameTime dt)
 {
     if (Entity != null)
     {
         if (_permanent && _activatedOnce)
         {
             return;
         }
         PrismaticJoint j = Entity.PhysicsEntity.GetJoint(_jointName) as PrismaticJoint;
         ButtonState = _inversed;
         if (j.JointTranslation < (j.UpperLimit - j.LowerLimit) / 2f)
         {
             _activatedOnce = true;
             ButtonState    = !_inversed;
         }
     }
 }
コード例 #24
0
        private void Launch(Vector2 impulse)
        {
            if (item.AiTarget != null)
            {
                item.AiTarget.SightRange = item.AiTarget.MaxSightRange;
                item.AiTarget.SoundRange = item.AiTarget.MaxSoundRange;
            }

            item.Drop(null);

            item.body.Enabled = true;
            item.body.ApplyLinearImpulse(impulse, maxVelocity: NetConfig.MaxPhysicsBodyVelocity);

            item.body.FarseerBody.OnCollision += OnProjectileCollision;
            item.body.FarseerBody.IsBullet     = true;

            item.body.CollisionCategories = Physics.CollisionProjectile;
            item.body.CollidesWith        = Physics.CollisionCharacter | Physics.CollisionWall | Physics.CollisionLevel;

            IsActive = true;

            if (stickJoint == null)
            {
                return;
            }

            if (stickTarget != null)
            {
#if DEBUG
                try
                {
#endif
                item.body.FarseerBody.RestoreCollisionWith(stickTarget);
#if DEBUG
            }
            catch (Exception e)
            {
                DebugConsole.ThrowError("Failed to restore collision with stickTarget", e);
            }
#endif

                stickTarget = null;
            }
            GameMain.World.RemoveJoint(stickJoint);
            stickJoint = null;
        }
コード例 #25
0
ファイル: Joints.cs プロジェクト: wqwkx2008/PhysX.Net
        public static PrismaticJoint PrismaticJointWithLimit(Scene scene)
        {
            Actor actorA, actorB;
            {
                BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

                BodyDescription bodyDesc = new BodyDescription(10.0f);
                bodyDesc.BodyFlags |= BodyFlag.Kinematic;

                ActorDescription actorDesc = new ActorDescription()
                {
                    BodyDescription = bodyDesc,
                    GlobalPose      = Matrix.Translation(70, 25, -65),
                    Shapes          = { boxShapeDesc }
                };
                actorA = scene.CreateActor(actorDesc);
            }
            {
                BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

                ActorDescription actorDesc = new ActorDescription()
                {
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.Translation(70, 15, -65),
                    Shapes          = { boxShapeDesc }
                };
                actorB = scene.CreateActor(actorDesc);
            }

            PrismaticJointDescription prismaticJointDesc = new PrismaticJointDescription()
            {
                Actor1 = actorA,
                Actor2 = actorB,
            };

            prismaticJointDesc.SetGlobalAnchor(new Vector3(70, 20, -65));
            prismaticJointDesc.SetGlobalAxis(new Vector3(0, 1, 0));

            PrismaticJoint prismaticJoint = scene.CreateJoint(prismaticJointDesc) as PrismaticJoint;

            LimitPlane limitPlane = new LimitPlane(new Vector3(0, 1, 0), new Vector3(-30, 8, -30), 0);

            prismaticJoint.AddLimitPlane(limitPlane);

            return(prismaticJoint);
        }
コード例 #26
0
        public Laser(Vector3 position, Vector3 direction, int baseDamage)
            : base(new Box(position, 0.25f, 2, 0.25f),
                   new ModelDrawingObject(new Accelerated_Delivery_Win.BaseModel(delegate { return(Program.Game.Loader.LaserModel); }, false, null, position)),
                   1)
        {
            damage = baseDamage;

            PhysicsObject.IsAffectedByGravity = false;
            PhysicsObject.CollisionInformation.Events.InitialCollisionDetected += onCollision;
            // todo: rotate laser correctly

            lineJoint = new PrismaticJoint(null, PhysicsObject, position, direction, position);
            lineJoint.Motor.Settings.Servo.Goal = 1000000; // go for infinity
            lineJoint.Motor.IsActive            = true;
            lineJoint.IsActive = true;
            lineJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = 1.5f;
        }
コード例 #27
0
        public Prismatic()
        {
            Body ground;
            {
                var bd = new BodyDef();
                ground = World.CreateBody(bd);

                var shape = new EdgeShape();
                shape.Set(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                var shape = new PolygonShape();
                shape.SetAsBox(2.0f, 0.5f);

                var bd = new BodyDef();
                bd.BodyType = BodyType.DynamicBody;
                bd.Position.Set(-10.0f, 10.0f);
                bd.Angle      = 0.5f * Settings.Pi;
                bd.AllowSleep = false;
                var body = World.CreateBody(bd);
                body.CreateFixture(shape, 5.0f);

                var pjd = new PrismaticJointDef();

                // Bouncy limit
                var axis = new Vector2(2.0f, 1.0f);

                axis = Vector2.Normalize(axis);
                pjd.Initialize(ground, body, new Vector2(0.0f, 0.0f), axis);

                // Non-bouncy limit
                //pjd.Initialize(ground, body, new Vector2(-10.0f, 10.0f), new Vector2(1.0f, 0.0f));

                pjd.MotorSpeed       = 10.0f;
                pjd.MaxMotorForce    = 10000.0f;
                pjd.EnableMotor      = true;
                pjd.LowerTranslation = 0.0f;
                pjd.UpperTranslation = 20.0f;
                pjd.EnableLimit      = true;

                _joint = (PrismaticJoint)World.CreateJoint(pjd);
            }
        }
コード例 #28
0
    public override void InitJoint()
    {
        base.InitJoint();

        //Microsoft.Xna.Framework.FVector2 angleV = new Microsoft.Xna.Framework.FVector2(BodyB.PhysicsBody.Position.X - BodyA.PhysicsBody.Position.X, BodyB.PhysicsBody.Position.Y - BodyA.PhysicsBody.Position.Y);
        float ang = Mathf.Atan2(BodyB.PhysicsBody.Position.Y - BodyA.PhysicsBody.Position.Y, BodyB.PhysicsBody.Position.X - BodyA.PhysicsBody.Position.X);

        Microsoft.Xna.Framework.FVector2 angleV = new Microsoft.Xna.Framework.FVector2(Mathf.Cos(ang), Mathf.Sin(ang));
        //angleV.Normalize();
        joint = FarseerPhysics.Factories.JointFactory.CreatePrismaticJoint(FSWorldComponent.PhysicsWorld,
                                                                           BodyA.PhysicsBody,
                                                                           BodyB.PhysicsBody,
                                                                           Microsoft.Xna.Framework.FVector2.Zero,
                                                                           angleV);
        joint.CollideConnected = CollideConnected;
        //joint.Frequency = Frequency;
        //joint.DampingRatio = 0.5f; d
    }
コード例 #29
0
        public override Joint CreateJoint()
        {
            PrismaticJoint joint = new PrismaticJoint(BodyA, BodyB, OwnerBodyAnchor * FSConvert.DisplayToSim,
                                                      OtherBodyAnchor * FSConvert.DisplayToSim)
            {
                CollideConnected = CollideConnected,
                Axis             = Axis,
                LimitEnabled     = LimitEnabled,
                LowerLimit       = LowerLimit,
                UpperLimit       = UpperLimit,
                MotorEnabled     = MotorEnabled,
                MotorSpeed       = MotorSpeed,
                MaxMotorForce    = MaxMotorForce,
                MotorImpulse     = MotorImpulse
            };

            return(joint);
        }
コード例 #30
0
        public PrismaticJointTestBase()
        {
            Body ground;

            {
                var bd = new BodyDef();
                ground = World.CreateBody(bd);

                var shape = new EdgeShape();
                shape.SetTwoSided(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            EnableLimit = true;
            EnableMotor = false;
            MotorSpeed  = 10.0f;

            {
                PolygonShape shape = new PolygonShape();
                shape.SetAsBox(1.0f, 1.0f);

                BodyDef bd = new BodyDef();
                bd.BodyType = BodyType.DynamicBody;
                bd.Position.Set(0.0f, 10.0f);
                bd.Angle      = 0.5f * Settings.Pi;
                bd.AllowSleep = false;
                var body = World.CreateBody(bd);
                body.CreateFixture(shape, 5.0f);

                PrismaticJointDef pjd = new PrismaticJointDef();

                // Horizontal
                pjd.Initialize(ground, body, bd.Position, new Vector2(1.0f, 0.0f));

                pjd.MotorSpeed       = MotorSpeed;
                pjd.MaxMotorForce    = 10000.0f;
                pjd.EnableMotor      = EnableMotor;
                pjd.LowerTranslation = -10.0f;
                pjd.UpperTranslation = 10.0f;
                pjd.EnableLimit      = EnableLimit;

                Joint = (PrismaticJoint)World.CreateJoint(pjd);
            }
        }
コード例 #31
0
ファイル: Prismatic.cs プロジェクト: GretelF/squircle
        public Prismatic()
        {
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = _world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.SetAsEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.SetAsBox(2.0f, 0.5f);

                BodyDef bd = new BodyDef();
                bd.type = BodyType.Dynamic;
                bd.position = new Vector2(-10.0f, 10.0f);
                bd.angle = 0.5f * (float)Settings.b2_pi;
                Body body = _world.CreateBody(bd);
                body.CreateFixture(shape, 5.0f);

                PrismaticJointDef pjd = new PrismaticJointDef();

                // Bouncy limit
                Vector2 axis = new Vector2(2, 1);
                axis.Normalize();
                pjd.Initialize(ground, body, new Vector2(0.0f, 0.0f), axis);

                // Non-bouncy limit
                //pjd.Initialize(ground, body, new Vector2(-10.0f, 10.0f), new Vector2(1.0f, 0.0f));

                pjd.motorSpeed = 10.0f;
                pjd.maxMotorForce = 1000.0f;
                pjd.enableMotor = true;
                pjd.lowerTranslation = 0.0f;
                pjd.upperTranslation = 20.0f;
                pjd.enableLimit = true;

                _joint = (PrismaticJoint)_world.CreateJoint(pjd);
            }
        }
コード例 #32
0
ファイル: SliderCrank.cs プロジェクト: GretelF/squircle
        public SliderCrank()
        {
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = _world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.SetAsEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                Body prevBody = ground;

                // Define crank.
                {
                    PolygonShape shape = new PolygonShape();
                    shape.SetAsBox(0.5f, 2.0f);

                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.Dynamic;
                    bd.position = new Vector2(0.0f, 7.0f);
                    Body body = _world.CreateBody(bd);
                    body.CreateFixture(shape, 2.0f);

                    RevoluteJointDef rjd = new RevoluteJointDef();
                    rjd.Initialize(prevBody, body, new Vector2(0.0f, 5.0f));
                    rjd.motorSpeed = 1.0f * (float)Settings.b2_pi;
                    rjd.maxMotorTorque = 10000.0f;
                    rjd.enableMotor = true;
                    _joint1 = (RevoluteJoint)_world.CreateJoint(rjd);

                    prevBody = body;
                }

                // Define follower.
                {
                    PolygonShape shape = new PolygonShape();
                    shape.SetAsBox(0.5f, 4.0f);

                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.Dynamic;
                    bd.position = new Vector2(0.0f, 13.0f);
                    Body body = _world.CreateBody(bd);
                    body.CreateFixture(shape, 2.0f);

                    RevoluteJointDef rjd3 = new RevoluteJointDef();
                    rjd3.Initialize(prevBody, body, new Vector2(0.0f, 9.0f));
                    rjd3.enableMotor = false;
                    _world.CreateJoint(rjd3);

                    prevBody = body;
                }

                // Define piston
                {
                    PolygonShape shape = new PolygonShape();
                    shape.SetAsBox(1.5f, 1.5f);

                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.Dynamic;
                    bd.position = new Vector2(0.0f, 17.0f);
                    Body body = _world.CreateBody(bd);
                    body.CreateFixture(shape, 2.0f);

                    RevoluteJointDef rjd2 = new RevoluteJointDef();
                    rjd2.Initialize(prevBody, body, new Vector2(0.0f, 17.0f));
                    _world.CreateJoint(rjd2);

                    PrismaticJointDef pjd = new PrismaticJointDef();
                    pjd.Initialize(ground, body, new Vector2(0.0f, 17.0f), new Vector2(0.0f, 1.0f));

                    pjd.maxMotorForce = 1000.0f;
                    pjd.enableMotor = true;

                    _joint2 = (PrismaticJoint)_world.CreateJoint(pjd);
                }

                // Create a payload
                {
                    PolygonShape shape = new PolygonShape();
                    shape.SetAsBox(1.5f, 1.5f);

                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.Dynamic;
                    bd.position = new Vector2(0.0f, 23.0f);
                    Body body = _world.CreateBody(bd);
                    body.CreateFixture(shape, 2.0f);
                }
            }
        }
コード例 #33
0
ファイル: Gears.cs プロジェクト: GretelF/squircle
        Gears()
        {
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = _world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.SetAsEdge(new Vector2(50.0f, 0.0f), new Vector2(-50.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

            {
                CircleShape circle1 = new CircleShape();
                circle1._radius = 1.0f;

                CircleShape circle2 = new CircleShape();
                circle2._radius = 2.0f;

                PolygonShape box = new PolygonShape();
                box.SetAsBox(0.5f, 5.0f);

                BodyDef bd1 = new BodyDef();
                bd1.type = BodyType.Dynamic;
                bd1.position = new Vector2(-3.0f, 12.0f);
                Body body1 = _world.CreateBody(bd1);
                body1.CreateFixture(circle1, 5.0f);

                RevoluteJointDef jd1 = new RevoluteJointDef();
                jd1.bodyA = ground;
                jd1.bodyB = body1;
                jd1.localAnchorA = ground.GetLocalPoint(bd1.position);
                jd1.localAnchorB = body1.GetLocalPoint(bd1.position);
                jd1.referenceAngle = body1.GetAngle() - ground.GetAngle();
                _joint1 = (RevoluteJoint)_world.CreateJoint(jd1);

                BodyDef bd2 = new BodyDef();
                bd2.type = BodyType.Dynamic;
                bd2.position = new Vector2(0.0f, 12.0f);
                Body body2 = _world.CreateBody(bd2);
                body2.CreateFixture(circle2, 5.0f);

                RevoluteJointDef jd2 = new RevoluteJointDef();
                jd2.Initialize(ground, body2, bd2.position);
                _joint2 = (RevoluteJoint)_world.CreateJoint(jd2);

                BodyDef bd3 = new BodyDef();
                bd3.type = BodyType.Dynamic;
                bd3.position = new Vector2(2.5f, 12.0f);
                Body body3 = _world.CreateBody(bd3);
                body3.CreateFixture(box, 5.0f);

                PrismaticJointDef jd3 = new PrismaticJointDef();
                jd3.Initialize(ground, body3, bd3.position, new Vector2(0.0f, 1.0f));
                jd3.lowerTranslation = -5.0f;
                jd3.upperTranslation = 5.0f;
                jd3.enableLimit = true;

                _joint3 = (PrismaticJoint)_world.CreateJoint(jd3);

                GearJointDef jd4 = new GearJointDef();
                jd4.bodyA = body1;
                jd4.bodyB = body2;
                jd4.joint1 = _joint1;
                jd4.joint2 = _joint2;
                jd4.ratio = circle2._radius / circle1._radius;
                _joint4 = (GearJoint)_world.CreateJoint(jd4);

                GearJointDef jd5 = new GearJointDef();
                jd5.bodyA = body2;
                jd5.bodyB = body3;
                jd5.joint1 = _joint2;
                jd5.joint2 = _joint3;
                jd5.ratio = -1.0f / circle2._radius;
                _joint5 = (GearJoint)_world.CreateJoint(jd5);
            }
        }
コード例 #34
0
ファイル: Mechanism.cs プロジェクト: visose/Robots
        internal static Mechanism Create(XElement element)
        {
            var modelName = element.Attribute(XName.Get("model")).Value;
            var manufacturer = (Manufacturers)Enum.Parse(typeof(Manufacturers), element.Attribute(XName.Get("manufacturer")).Value);
            string fullName = $"{element.Name.LocalName}.{manufacturer.ToString()}.{modelName}";

            bool movesRobot = false;
            var movesRobotAttribute = element.Attribute(XName.Get("movesRobot"));
            if (movesRobotAttribute != null) movesRobot = XmlConvert.ToBoolean(movesRobotAttribute.Value);

            var meshes = GetMeshes(fullName);

            double payload = Convert.ToDouble(element.Attribute(XName.Get("payload")).Value);

            var baseMesh = meshes[0].DuplicateMesh();
            XElement baseElement = element.Element(XName.Get("Base"));
            double x = XmlConvert.ToDouble(baseElement.Attribute(XName.Get("x")).Value);
            double y = XmlConvert.ToDouble(baseElement.Attribute(XName.Get("y")).Value);
            double z = XmlConvert.ToDouble(baseElement.Attribute(XName.Get("z")).Value);
            double q1 = XmlConvert.ToDouble(baseElement.Attribute(XName.Get("q1")).Value);
            double q2 = XmlConvert.ToDouble(baseElement.Attribute(XName.Get("q2")).Value);
            double q3 = XmlConvert.ToDouble(baseElement.Attribute(XName.Get("q3")).Value);
            double q4 = XmlConvert.ToDouble(baseElement.Attribute(XName.Get("q4")).Value);
            var basePlane = RobotCellAbb.QuaternionToPlane(x, y, z, q1, q2, q3, q4);

            var jointElements = element.Element(XName.Get("Joints")).Descendants().ToArray();
            Joint[] joints = new Joint[jointElements.Length];

            for (int i = 0; i < jointElements.Length; i++)
            {
                var jointElement = jointElements[i];
                double a = XmlConvert.ToDouble(jointElement.Attribute(XName.Get("a")).Value);
                double d = XmlConvert.ToDouble(jointElement.Attribute(XName.Get("d")).Value);
                string text = jointElement.Attribute(XName.Get("minrange")).Value;
                double minRange = XmlConvert.ToDouble(text);
                double maxRange = XmlConvert.ToDouble(jointElement.Attribute(XName.Get("maxrange")).Value);
                Interval range = new Interval(minRange, maxRange);
                double maxSpeed = XmlConvert.ToDouble(jointElement.Attribute(XName.Get("maxspeed")).Value);
                Mesh mesh = meshes[i + 1].DuplicateMesh();
                int number = XmlConvert.ToInt32(jointElement.Attribute(XName.Get("number")).Value) - 1;

                if (jointElement.Name == "Revolute")
                    joints[i] = new RevoluteJoint() { Index = i, Number = number, A = a, D = d, Range = range, MaxSpeed = maxSpeed.ToRadians(), Mesh = mesh };
                else if (jointElement.Name == "Prismatic")
                    joints[i] = new PrismaticJoint() { Index = i, Number = number, A = a, D = d, Range = range, MaxSpeed = maxSpeed, Mesh = mesh };
            }

            switch (element.Name.ToString())
            {
                case ("RobotArm"):
                    {
                        switch (manufacturer)
                        {
                            case (Manufacturers.ABB):
                                return new RobotAbb(modelName, payload, basePlane, baseMesh, joints);
                            case (Manufacturers.KUKA):
                                return new RobotKuka(modelName, payload, basePlane, baseMesh, joints);
                            case (Manufacturers.UR):
                                return new RobotUR(modelName, payload, basePlane, baseMesh, joints);
                            default:
                                return null;
                        }
                    }
                case ("Positioner"):
                    return new Positioner(modelName, manufacturer, payload, basePlane, baseMesh, joints, movesRobot);
                case ("Track"):
                    return new Track(modelName, manufacturer, payload, basePlane, baseMesh, joints, movesRobot);
                default:
                    return null;
            }

        }