Exemple #1
0
        public virtual void MouseDrag()
        {
            // mouse press
            if (Input.GetMouseButtonDown(0) && mouseJoint == null)
            {
                FSBody body = GetBodyAtMouse();
                if (body != null)
                {
                    FVector2 target = new FVector2(MouseXWorldPhys, MouseYWorldPhys);
                    mouseJoint = JointFactory.CreateFixedMouseJoint(FSWorldComponent.PhysicsWorld, body, target);
                    mouseJoint.CollideConnected = true;
                    mouseJoint.MaxForce         = 300f * body.Mass;
                    body.Awake = true;
                }
            }
            // mouse release
            if (Input.GetMouseButtonUp(0))
            {
                if (mouseJoint != null)
                {
                    FSWorldComponent.PhysicsWorld.RemoveJoint(mouseJoint);
                    mouseJoint = null;
                }
            }

            // mouse move
            if (mouseJoint != null)
            {
                FVector2 p2 = new FVector2(MouseXWorldPhys, MouseYWorldPhys);
                mouseJoint.WorldAnchorB = p2;
            }
        }
Exemple #2
0
        public static FSFixedMouseJoint CreateFixedMouseJoint(FSWorld world, FSBody body, FVector2 target)
        {
            FSFixedMouseJoint joint = new FSFixedMouseJoint(body, target);

            world.AddJoint(joint);
            return(joint);
        }