Esempio n. 1
0
 private void MouseUp()
 {
     if (_mouseJoint != null)
     {
         World.DestroyJoint(_mouseJoint);
         _mouseJoint = null;
     }
 }
 /// <summary>
 /// Mouse interaction event.
 /// </summary>
 public void MouseUp()
 {
     if (_mouseJoint != null)
     {
         _world.DestroyJoint(_mouseJoint);
         _mouseJoint = null;
     }
 }
Esempio n. 3
0
 public virtual void MouseUp(Vector2 p)
 {
     if (_mouseJoint != null)
     {
         world.DestroyJoint(_mouseJoint);
         _mouseJoint = null;
     }
 }
Esempio n. 4
0
 public void MouseLeftReleasd()
 {
     if (m_mouseJoint != null)
     {
         m_mouseJoint.Destroy();
         m_mouseJoint = null;
     }
 }
Esempio n. 5
0
        public void MouseUp(Vector point)
        {
            Vector p = RelativeToWorld(point);

            if (mouseJoint != null)
            {
                world.DestroyJoint(mouseJoint);
                mouseJoint = null;
            }
        }
Esempio n. 6
0
        private void MouseDown()
        {
            if (_mouseJoint != null)
            {
                return;
            }

            var p = Mouse.ToVector2();

            // Make a small box.
            var aabb = new AABB();
            var d    = new Vector2(0.001f, 0.001f);

            aabb.LowerBound = p - d;
            aabb.UpperBound = p + d;

            // Query the world for overlapping shapes.
            Fixture fixture = null;

            World.QueryAABB(
                fixture1 =>
            {
                var body = fixture1.Body;
                if (body.BodyType == BodyType.DynamicBody)
                {
                    bool inside = fixture1.TestPoint(p);
                    if (inside)
                    {
                        fixture = fixture1;

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

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

            if (fixture != null)
            {
                var body = fixture.Body;
                var md   = new MouseJointDef
                {
                    BodyA    = GroundBody,
                    BodyB    = body,
                    Target   = p,
                    MaxForce = 1000.0f * body.Mass
                };
                _mouseJoint  = (MouseJoint)World.CreateJoint(md);
                body.IsAwake = true;
            }
        }
Esempio n. 7
0
        public virtual void MouseDown(Vector2 p)
        {
            _mouseWorld = p;

            if (_mouseJoint != null)
            {
                return;
            }

            // Make a small box.
            AABB    aabb;
            Vector2 d = new Vector2(0.001, 0.001);

            aabb.lowerBound = p - d;
            aabb.upperBound = p + d;

            Fixture _fixture = null;

            // Query the world for overlapping shapes.
            _world.QueryAABB(
                (fixtureProxy) =>
            {
                var fixture = fixtureProxy.fixture;
                Body body   = fixture.GetBody();
                if (body.GetType() == BodyType.Dynamic)
                {
                    bool inside = fixture.TestPoint(p);
                    if (inside)
                    {
                        _fixture = 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);
            }
        }
Esempio n. 8
0
        public void MouseDown(Vec2 p)
        {
            if (_mouseJoint != null)
            {
                return;
            }

            // Make a small box.
            AABB aabb = new AABB();
            Vec2 d    = new Vec2();

            d.Set(0.001f, 0.001f);
            aabb.LowerBound = p - d;
            aabb.UpperBound = p + d;

            // Query the world for overlapping shapes.
            int k_maxCount = 10;

            Fixture[] shapes = new Fixture[k_maxCount];
            int       count  = _world.Query(aabb, shapes, k_maxCount);
            Body      body   = null;

            for (int i = 0; i < count; ++i)
            {
                Body shapeBody = shapes[i].Body;
                if (shapeBody.IsStatic() == false && shapeBody.GetMass() > 0.0f)
                {
                    bool inside = shapes[i].TestPoint(p);
                    if (inside)
                    {
                        body = shapes[i].Body;
                        break;
                    }
                }
            }

            if (body != null)
            {
                MouseJointDef md = new MouseJointDef();
                md.Body1  = _world.GetGroundBody();
                md.Body2  = body;
                md.Target = p;
#if TARGET_FLOAT32_IS_FIXED
                md.MaxForce = (body.GetMass() < 16.0f)?
                              (1000.0f * body.GetMass()) : 16000.0f;
#else
                md.MaxForce = 1000.0f * body.GetMass();
#endif
                _mouseJoint = (MouseJoint)_world.CreateJoint(md);
                body.WakeUp();
            }
        }
Esempio n. 9
0
        public virtual void MouseUp(Vector2 p)
        {
            if (_mouseJoint != null)
            {
                _world.DestroyJoint(_mouseJoint);
                _mouseJoint = null;
            }

            if (_bombSpawning)
            {
                CompleteBombSpawn(p);
            }
        }
Esempio n. 10
0
        public void MouseUp()
        {
            if (MouseJoint != null)
            {
                World.DestroyJoint(MouseJoint);
                MouseJoint = null;
            }

            if (BombSpawning)
            {
                CompleteBombSpawn(MouseWorld);
            }
        }
        /// <summary>
        /// Mouse interaction event.
        /// </summary>
        public void MouseDown(Vec2 p)
        {
            if (_mouseJoint != null)
            {
                return;
            }

            // Make a small box.
            AABB aabb = new AABB();
            Vec2 d    = new Vec2();

            d.Set(0.001f, 0.001f);
            aabb.LowerBound = p - d;
            aabb.UpperBound = p + d;

            // Query the world for overlapping shapes.
            int k_maxCount = 10;

            Shape[] shapes = new Shape[k_maxCount];
            int     count  = _world.Query(aabb, shapes, k_maxCount);
            Body    body   = null;

            for (int i = 0; i < count; ++i)
            {
                Body shapeBody = shapes[i].GetBody();
                if (shapeBody.IsStatic() == false && shapeBody.GetMass() > 0.0f)
                {
                    bool inside = shapes[i].TestPoint(shapeBody.GetXForm(), p);
                    if (inside)
                    {
                        body = shapes[i].GetBody();
                        break;
                    }
                }
            }

            if (body != null)
            {
                MouseJointDef md = new MouseJointDef();
                md.Body1       = _world.GetGroundBody();
                md.Body2       = body;
                md.Target      = p;
                md.MaxForce    = 1000.0f * body.GetMass();
                md.FrequencyHz = 30f;
                _mouseJoint    = (MouseJoint)_world.CreateJoint(md);
                body.WakeUp();
            }
        }
Esempio n. 12
0
        public void MouseLeftPressed()
        {
            if (m_mouseJoint == null)
            {
                Vector2 p = GetMousePosOnWorld();
                // create
                Vector2 d     = new Vector2(0.001f, 0.001f);
                var     lower = p - d;
                var     upper = p + d;

                m_world.QueryBoundingBox(lower.X, lower.Y, upper.X, upper.Y, (Fixture pfixture) =>
                {
                    var body     = pfixture.GetBody();
                    m_mouseJoint = Physics.NewMouseJoint(body, p);
                    m_mouseJoint.SetMaxForce(1000.0f * body.GetMass());
                    m_mouseJointStartDragOffset = body.GetLocalPoint(p);
                    return(false);
                });
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Handles what happens when a user clicks the mouse
        /// </summary>
        /// <param name="p">
        /// The position of the mouse click in relative coordinates.
        /// </param>
        public void MouseDown(Vector point)
        {
            Vector p = RelativeToWorld(point);

            if (mouseJoint != null)
            {
                throw new Exception("ASSERT: mouseJoint should be null");
            }

            // Make a small box.
            Vector d    = new Vector(.001f, .001f);
            AABB   aabb = new AABB(p - d, p + d);

            // Query the world for overlapping shapes.
            IList <Shape> shapes = world.Query(aabb);
            Body          body   = null;

            foreach (Shape shape in shapes)
            {
                if (shape.Body.Static == false &&
                    shape.TestPoint(shape.Body.GetXForm(), p))
                {
                    body = shape.Body;
                    break;
                }
            }

            if (body != null)
            {
                MouseJointDef md = new MouseJointDef();
                md.Body1    = world.GetGroundBody();
                md.Body2    = body;
                md.Target   = p;
                md.MaxForce = 1000 * body.Mass;
                mouseJoint  = new MouseJoint(world.CreateJoint(md));
                body.WakeUp();
            }
        }
Esempio n. 14
0
        public Test()
        {
            _worldAABB = new AABB();
            _worldAABB.LowerBound.Set(-200.0f, -100.0f);
            _worldAABB.UpperBound.Set(200.0f, 200.0f);
            Vec2 gravity = new Vec2();

            gravity.Set(0.0f, -10.0f);
            bool doSleep = true;

            _world      = new World(_worldAABB, gravity, doSleep);
            _bomb       = null;
            _textLine   = 30;
            _mouseJoint = null;
            _pointCount = 0;

            _destructionListener.test = this;
            _boundaryListener.test    = this;
            //_contactListener.test = this;
            _world.SetDestructionListener(_destructionListener);
            _world.SetBoundaryListener(_boundaryListener);
            //_world.SetContactListener(_contactListener);
            _world.SetDebugDraw(_debugDraw);
        }
Esempio n. 15
0
        /// <summary>
        /// Handles what happens when a user clicks the mouse
        /// </summary>
        /// <param name="p">
        /// The position of the mouse click in relative coordinates.
        /// </param>
        public void MouseDown(Vector point)
        {
            Vector p = RelativeToWorld(point);

            if (mouseJoint != null)
                throw new Exception("ASSERT: mouseJoint should be null");

            // Make a small box.
            Vector d = new Vector(.001f, .001f);
            AABB aabb = new AABB(p - d, p + d);

            // Query the world for overlapping shapes.
            IList<Shape> shapes = world.Query(aabb);
            Body body = null;
            foreach (Shape shape in shapes)
            {
                if (shape.Body.Static == false &&
                    shape.TestPoint(shape.Body.GetXForm(), p))
                {
                    body = shape.Body;
                    break;
                }
            }

            if (body != null)
            {
                MouseJointDef md = new MouseJointDef();
                md.Body1 = world.GetGroundBody();
                md.Body2 = body;
                md.Target = p;
                md.MaxForce = 1000 * body.Mass;
                mouseJoint = new MouseJoint(world.CreateJoint(md));
                body.WakeUp();
            }
        }
Esempio n. 16
0
        public override void OnLoad()
        {
            Paint += OnPaint;

            dd = new SKDrawDebug(HipsterEngine);

            HipsterEngine.Physics.Initialize(-1000, -1000, 1000, 1000, 0, 0f, true);
            HipsterEngine.Physics.GetWorld().SetDebugDraw(dd);

            MousePosition = new Vec2(0, 0);


            HipsterEngine.Surface.Canvas.Camera.SetScale(0.5f);

            HipsterEngine.Surface.Canvas.Camera.Y = Height / 2;
            HipsterEngine.Surface.Canvas.Camera.X = -Width / 2;

            HipsterEngine.Particles.AddParticleSystem(new ParticlesControllerFire(HipsterEngine));


            var        isMove     = false;
            var        mouse      = new Vec2();
            var        listMouses = new List <Vec2>();
            MouseJoint joint      = null;
            Body       body       = null;

            MouseDown += (o, e) =>
            {
                isMove = true;

                if (e.Button == MouseButton.Right)
                {
                    HipsterEngine.Physics.FactoryBody
                    .CreateRigidVertex()
                    .CreateBox(0.2f, 0.2f, 50, 50, 0.2f)
                    .CreateBodyDef(e.X, e.Y, 0, true, false)
                    .Build(1f);
                }
            };
            MouseMove += (o, e) =>
            {
                MousePosition = new Vec2(e.X, e.Y);

                var ps = (ParticlesControllerFire)HipsterEngine.Particles.GetSystem(typeof(ParticlesControllerFire));
                ps.AddBlood(MousePosition.X - HipsterEngine.Surface.Canvas.Camera.X, MousePosition.Y + HipsterEngine.Surface.Canvas.Camera.Y, new Vec2(), 5);

                if (isMove)
                {
                    mouse = new Vec2(e.X / PhysicsController.metric, e.Y / PhysicsController.metric);

                    if (listMouses.Count >= 10)
                    {
                        listMouses.RemoveAt(0);
                    }
                    listMouses.Add(mouse);

                    body = HipsterEngine.Physics.GetRayBody(e.X, e.Y);

                    if (body != null && joint == null)
                    {
                        joint = HipsterEngine.Physics.AddJointMouse(body, mouse);
                    }

                    joint?.SetTarget(mouse);
                }
            };
            MouseUp += (o, e) =>
            {
                if (joint != null)
                {
                    HipsterEngine.Physics.GetWorld().DestroyJoint(joint);
                    joint = null;
                    body  = null;
                }

                isMove = false;
                listMouses.Clear();
            };

            Trees = new List <Tree>();


            InitializeBall();

            //   Robots = new List<IRobot>();
            //   var robot = new Robot(HipsterEngine, Earth);
            //   robot.Initialize(new TwoWheels(), new Box2(), new Gun1())
            //       .Build(Width / 2+200, 120, 90, 20);

            //   var robot1 = new Robot(HipsterEngine, Earth);
            //   robot1.Initialize(new TwoWheels(), new Box2(), new Gun1())
            //       .Build(Width / 2-200, 120, 90, 20);
            //   Robots.Add(robot);
            //   Robots.Add(robot1);

            aControl = new AttackControl(HipsterEngine, 70);
            mControl = new MoveControl(HipsterEngine);
            mControl.Tracker.Move += (sender, vec2) =>
            {
                ValueX = vec2.X;
                //       Robots.First().Transmission.Move(-ValueX / 10);

                if (ValueX > 0)
                {
                    //         ((Gun1) Robots.First().Arms).SetAngleRad(90);
                }
                else if (ValueX < 0)
                {
                    //         ((Gun1) Robots.First().Arms).SetAngleRad(-90);
                }
                else if (ValueX == 0)
                {
                    //     ((Gun1) Robots.First().Arms).SetAngleRad(180);
                }
            };
            aControl.Click += (sender, args) =>
            {
                //       Robots.First().Arms.Attack();
            };

            Timer       = new TimeWatch();
            Timer.Tick += tick => { ((Gun1)Robots.First().Arms).SetAngleRad(tick); };
        }
Esempio n. 17
0
        public virtual void MouseUp(Vector2 p)
        {
            if (_mouseJoint != null)
            {
                _world.DestroyJoint(_mouseJoint);
                _mouseJoint = null;
            }

            if (_bombSpawning)
            {
                CompleteBombSpawn(p);
            }
        }
Esempio n. 18
0
        public void MouseUp(Vector point)
        {
            Vector p = RelativeToWorld(point);

            if (mouseJoint != null)
            {
                world.DestroyJoint(mouseJoint);
                mouseJoint = null;
            }
        }
Esempio n. 19
0
        public virtual void MouseDown(Vector2 p)
        {
            _mouseWorld = p;

            if (_mouseJoint != null)
            {
                return;
            }

            // 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) =>
                {
                    var fixture = fixtureProxy.fixture;
                    Body body = fixture.GetBody();
                    if (body.GetType() == BodyType.Dynamic)
                    {
                        bool inside = fixture.TestPoint(p);
                        if (inside)
                        {
                            _fixture = 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);
            }
        }