Пример #1
0
 public I2DObject(I2DPhysicObject physicObject, I2DMaterial material, IModelo2D Modelo)
 {
     System.Diagnostics.Debug.Assert(physicObject != null);
     System.Diagnostics.Debug.Assert(material != null);
     System.Diagnostics.Debug.Assert(Modelo != null);
     this.Material       = material;
     this.PhysicObject   = physicObject;
     this.Modelo         = Modelo;
     I2DObjectAtachtment = new List <IObject2DAtachtment>();
 }
 /// <summary>
 /// Removes the object.
 /// </summary>
 /// <param name="obj">The obj.</param>
 public override void RemoveObject(I2DPhysicObject obj)
 {
     if (obj.Physic2DType == Physic2DType.Physic)
     {
         FarseerObject ob = obj as FarseerObject;
         world.RemoveBody(ob.Body);
     }
     else if (obj.Physic2DType == Physic2DType.Ghost)
     {
         obj.Enabled = false;
     }
 }
 /// <summary>
 /// Adds the object.
 /// </summary>
 /// <param name="obj">The obj.</param>
 public override void AddObject(I2DPhysicObject obj)
 {
     if (obj.Physic2DType == Physic2DType.Physic)
     {
         FarseerObject ob = obj as FarseerObject;
         ob.Body.UserData = obj;
         ob.Body.Enabled  = true;
     }
     else if (obj.Physic2DType == Physic2DType.Ghost)
     {
         obj.Enabled = true;
     }
 }
        /// <summary>
        /// Tests the AABB against the world.
        /// </summary>
        /// <param name="min">The min.</param>
        /// <param name="max">The max.</param>
        /// <returns></returns>
        public override List <I2DPhysicObject> TestAABB(Vector2 min, Vector2 max)
        {
            objs.Clear();
            AABB a = new AABB(ref min, ref max);

            world.QueryAABB(
                (p) =>
            {
                if (p.Body.UserData != null)
                {
                    I2DPhysicObject I2DPhysicObject = (I2DPhysicObject)p.Body.UserData;
                    if (!objs.Contains(I2DPhysicObject))
                    {
                        objs.Add(I2DPhysicObject);
                    }
                }
                return(true);
            }

                , ref a);
            return(objs);
        }
Пример #5
0
        protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, PloobsEngine.SceneControl.IContentManager contentManager)
        {
            tile = factory.GetTexture2D("Textures/tile");


            FarseerWorld fworld = this.World.PhysicWorld as FarseerWorld;

            ///border
            border = new Border(fworld, factory, GraphicInfo, factory.CreateTexture2DColor(1, 1, Color.Red));

            ///from texture
            {
                Texture2D tex              = factory.GetTexture2D("Textures//goo");
                IModelo2D model            = new SpriteFarseer(tex);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject          fs  = new FarseerObject(fworld, tex);

                I2DObject o = new I2DObject(fs, mat, model);
                o.Name = "Goo";
                this.World.AddObject(o);
            }

            ///rectangle
            Vertices verts = PolygonTools.CreateRectangle(5, 5);
            {
                IModelo2D model            = new SpriteFarseer(factory, verts, Color.Orange);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject          fs  = new FarseerObject(fworld, verts);

                I2DObject o = new I2DObject(fs, mat, model);
                o.Name = "Rectangle";
                this.World.AddObject(o);
            }

            ///circle
            CircleShape circle = new CircleShape(5, 1);

            {
                IModelo2D model            = new SpriteFarseer(factory, circle, Color.Orange);
                Basic2DTextureMaterial mat = new Basic2DTextureMaterial();
                FarseerObject          fs  = new FarseerObject(fworld, circle);

                I2DObject o = new I2DObject(fs, mat, model);
                o.Name = "Circle";
                this.World.AddObject(o);
            }

            ///camera
            this.World.Camera2D = new Camera2D(GraphicInfo);

            base.LoadContent(GraphicInfo, factory, contentManager);

            this.BindInput(new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.Tap,
                                                                  (sample) =>
            {
                I2DPhysicObject obj = this.World.PhysicWorld.Picking(this.World.Camera2D.ConvertScreenToWorld(sample.Position));
                if (obj != null)
                {
                    pickedName = obj.Owner.Name + " " + sample.Position;
                }
                else
                {
                    pickedName = null;
                }
            }
                                                                  ));
        }