Пример #1
0
        internal static Joint Create(JointDef def)
        {
            Joint joint = null;

            switch (def.type)
            {
            case JointType.Distance:
                {
                    joint = new DistanceJoint((DistanceJointDef)def);
                }
                break;

            case JointType.Mouse:
                {
                    joint = new MouseJoint((MouseJointDef)def);
                }
                break;

            case JointType.Prismatic:
                {
                    joint = new PrismaticJoint((PrismaticJointDef)def);
                }
                break;

            case JointType.Revolute:
                {
                    joint = new RevoluteJoint((RevoluteJointDef)def);
                }
                break;

            case JointType.Pulley:
                {
                    joint = new PulleyJoint((PulleyJointDef)def);
                }
                break;

            case JointType.Gear:
                {
                    joint = new GearJoint((GearJointDef)def);
                }
                break;

            case JointType.Line:
                {
                    joint = new LineJoint((LineJointDef)def);
                }
                break;

            case JointType.Weld:
                {
                    joint = new WeldJoint((WeldJointDef)def);
                }
                break;
            case JointType.Friction:
                {
                    joint = new FrictionJoint((FrictionJointDef)def);
                }
                break;
            case JointType.MaxDistance:
                {
                    joint = new MaxDistanceJoint((MaxDistanceJointDef)def);
                }
                break;

            default:
                Debug.Assert(false);
                break;
            }

            return joint;
        }
        void HandleEquipment(InputState input)
        {
            Vector2 m = mousePos * gameContent.scale;
            Point mp = new Point((int)m.X, (int)m.Y);

            Equipment mouseOverEq = null;
            if (mouseEq == null)
                foreach (Equipment e in equipments)
                {
                    e.isMouseOver = false;

                    if (mouseOverEq == null && !isMenuEntrySelected
                        && (e.MoveButtonBound.Contains(mp) || e.RotationButtonBound.Contains(mp)))
                    {
                        mouseOverEq = e; e.isMouseOver = true;
                    }
                }

            if (input.IsLeftClicked() && mouseOverEq != null)
            {
                if (mouseOverEq.MoveButtonBound.Contains(mp) || mouseOverEq.RotationButtonBound.Contains(mp))
                {
                    MouseJointDef mjd = new MouseJointDef();
                    mjd.maxForce = 500;
                    //mjd.frequencyHz = 10f; mjd.dampingRatio = .1f;
                    mjd.target = mousePos; mjd.bodyA = mouseGroundBody; mjd.bodyB = mouseOverEq.body;

                    mouseJoint = (MouseJoint)world.CreateJoint(mjd);
                    mouseEq = mouseOverEq;
                    mouseEq.body.SetAngularDamping(20000);

                    if (mouseOverEq.RotationButtonBound.Contains(mp))
                    {
                        RevoluteJointDef rjd = new RevoluteJointDef();
                        rjd.bodyA = mouseGroundBody; rjd.bodyB = mouseOverEq.body;
                        rjd.localAnchorA = mouseOverEq.body.Position; rjd.localAnchorB = Vector2.Zero;
                        pin = world.CreateJoint(rjd);

                        mouseEq.body.SetAngularDamping(20);
                    }

                    if (selectedEq != mouseOverEq)
                    {
                        if (selectedEq != null)
                        {
                            selectedEq.isSelected = false; selectedEq.SetMode(editMode, false); selectedEq = null;
                        }

                        selectedEq = mouseOverEq; selectedEq.isClamped = false; selectedEq.isSelected = true;
                    }

                    mouseEq.SetMode(editMode, true);
                }
            }
            else if (mouseOverEq != null && input.IsRightClicked()
                || input.CurrentMouseState[0].LeftButton == ButtonState.Released)
            {
                if (mouseJoint != null && mouseEq != null)
                {
                    world.DestroyJoint(mouseJoint);
                    mouseJoint = null;

                    if (pin != null) { world.DestroyJoint(pin); pin = null; }

                    mouseEq.SetMode(editMode, false);
                    mouseEq = null;
                }

                if (mouseOverEq != null && input.IsRightClicked())
                {
                    selectedEq = null;

                    mouseOverEq.Remove(); equipments.Remove(mouseOverEq);
                }
            }

            // Remove
            if (!equipmentAdded && (input.IsLeftClicked() || input.IsRightClicked()) && mouseOverEq == null
                && mouseEq == null && selectedEq != null)
            {
                selectedEq.isSelected = false; selectedEq.SetMode(editMode, false); selectedEq = null;
            }
            equipmentAdded = false;
        }
        void HandleAtom(InputState input)
        {
            Atom mouseOverAtom = null;
            foreach (Atom a in atoms)
            {
                if (mouseAtom == null && !isMenuEntrySelected && a.eye < EyeState.Disappear
                    && a.fixture.TestPoint(mousePos))
                    mouseOverAtom = a;
            }

            // click to add atoms
            if (mouseOverAtom == null && input.IsLeftClicked() && isLAB && !editMode && !isMenuEntrySelected)
                atoms.Add(new Atom((Symbol)(gameContent.random.Next(gameContent.symbolCount - 1) + 1),
                        mousePos * gameContent.scale, gameContent, world));

            if (input.IsLeftClicked())
            {
                if (mouseOverAtom != null)
                {
                    MouseJointDef mjd = new MouseJointDef();
                    mjd.maxForce = 500;
                    //mjd.frequencyHz = 10;
                    //mjd.dampingRatio = .1f;
                    mjd.target = mouseOverAtom.body.Position;
                    mjd.bodyA = mouseGroundBody;
                    mjd.bodyB = mouseOverAtom.body;

                    mouseJoint = (MouseJoint)world.CreateJoint(mjd);
                    mouseAtom = mouseOverAtom;
                    mouseAtom.SetMode(editMode, true);
                }
            }
            else if (mouseJoint != null && mouseAtom != null && (mouseAtom.eye == EyeState.Disappear
                || input.CurrentMouseState[0].LeftButton == ButtonState.Released))
            {
                if (mouseAtom.eye != EyeState.Disappear) // Disappear has priority over LeftButton Released
                {
                    world.DestroyJoint(mouseJoint);
                    mouseAtom.SetMode(editMode, false);
                    mouseAtom.CreateBond();
                }

                mouseJoint = null; mouseAtom = null;
            }

            if (input.IsRightClicked())
            {
                if (mouseOverAtom != null)
                {
                    if (mouseOverAtom.bondedAtoms.Count > 0)
                    {
                        Cue cue = gameContent.soundBank.GetCue("detach"); cue.Play();
                        mouseOverAtom.DestroyBonds();
                    }
                    else if (isLAB && !editMode && mouseOverAtom.bondedAtoms.Count == 0)
                    {
                        mouseOverAtom.Remove(); atoms.Remove(mouseOverAtom);
                    }
                }
            }
        }
Пример #4
0
 public virtual void MouseUp(Vector2 p)
 {
     if (_mouseJoint != null)
     {
         world.DestroyJoint(_mouseJoint);
         _mouseJoint = null;
     }
 }
Пример #5
0
        //#if !XBOX
        public virtual void MouseDown(Vector2 p)
        {
            if (_mouseJoint != null)
            {
                return;
            }

            p /= V2DScreen.WorldScale;
            // Make a small box.
            AABB aabb;
            Vector2 d = new Vector2(0.001f, 0.001f);
            aabb.lowerBound = p - d;
            aabb.upperBound = p + d;

            Fixture _fixture = null;

            // Query the world for overlapping shapes.
            world.QueryAABB(
                (fixtureProxy) =>
                {
                    Body body = fixtureProxy.fixture.GetBody();
                    if (body.GetType() == BodyType.Dynamic)
                    {
                        bool inside = fixtureProxy.fixture.TestPoint(p);
                        if (inside)
                        {
                            _fixture = fixtureProxy.fixture;

                            // We are done, terminate the query.
                            return false;
                        }
                    }

                    // Continue the query.
                    return true;
                }, ref aabb);

            if (_fixture != null)
            {
                Body body = _fixture.GetBody();
                MouseJointDef md = new MouseJointDef();
                md.bodyA = groundBody;
                md.bodyB = body;
                md.target = p;
                md.maxForce = 1000.0f * body.GetMass();
                _mouseJoint = (MouseJoint)world.CreateJoint(md);
                body.SetAwake(true);
            }
        }
Пример #6
0
        internal static Joint Create(JointDef def)
        {
            Joint joint = null;

            switch (def.type)
            {
            case JointType.Distance:
            {
                joint = new DistanceJoint((DistanceJointDef)def);
            }
            break;

            case JointType.Mouse:
            {
                joint = new MouseJoint((MouseJointDef)def);
            }
            break;

            case JointType.Prismatic:
            {
                joint = new PrismaticJoint((PrismaticJointDef)def);
            }
            break;

            case JointType.Revolute:
            {
                joint = new RevoluteJoint((RevoluteJointDef)def);
            }
            break;

            case JointType.Pulley:
            {
                joint = new PulleyJoint((PulleyJointDef)def);
            }
            break;

            case JointType.Gear:
            {
                joint = new GearJoint((GearJointDef)def);
            }
            break;

            case JointType.Line:
            {
                joint = new LineJoint((LineJointDef)def);
            }
            break;

            case JointType.Weld:
            {
                joint = new WeldJoint((WeldJointDef)def);
            }
            break;

            case JointType.Friction:
            {
                joint = new FrictionJoint((FrictionJointDef)def);
            }
            break;

            case JointType.MaxDistance:
            {
                joint = new MaxDistanceJoint((MaxDistanceJointDef)def);
            }
            break;

            default:
                Debug.Assert(false);
                break;
            }

            return(joint);
        }