コード例 #1
0
        PolygonDef CreatePolygonDef(asd.Vector2DF vertex1, asd.Vector2DF vertex2, asd.Vector2DF vertex3)
        {
            PolygonDef b2PolygonDef   = new PolygonDef();
            var        sortedVertexes = new List <asd.Vector2DF>();

            sortedVertexes.Add(vertex1);
            sortedVertexes.Add(vertex2);
            sortedVertexes.Add(vertex3);
            sortedVertexes.Sort((a, b) => a.Degree.CompareTo(b.Degree));
            b2PolygonDef.VertexCount = 3;
            for (int i = 0; i < 3; i++)
            {
                b2PolygonDef.Vertices[i] = PhysicalConvert.Tob2Vector(sortedVertexes[i]);
            }

            b2PolygonDef.Density     = Density;
            b2PolygonDef.Restitution = Restitution;
            b2PolygonDef.Friction    = Friction;
            b2PolygonDef.Filter      = new FilterData()
            {
                GroupIndex   = GroupIndex,
                CategoryBits = CategoryBits,
                MaskBits     = MaskBits
            };
            return(b2PolygonDef);
        }
コード例 #2
0
 public void Reset()
 {
     if (b2Body != null)
     {
         refWorld.B2World.DestroyBody(b2Body);
         b2Body.Dispose();
     }
     b2BodyDef          = new BodyDef();
     b2PolygonDef       = new PolygonDef();
     b2BodyDef.Position = PhysicalConvert.Tob2Vector(DrawingArea.Size / 2.0f + DrawingArea.Position);
     CenterPosition     = DrawingArea.Size / 2.0f;
     b2BodyDef.Angle    = Angle / 180.0f * 3.14f;
     b2PolygonDef.SetAsBox(PhysicalConvert.Tob2Single(DrawingArea.Width) / 2.0f, PhysicalConvert.Tob2Single(DrawingArea.Height) / 2.0f);
     b2PolygonDef.Density             = Density;
     b2PolygonDef.Restitution         = Restitution;
     b2PolygonDef.Friction            = Friction;
     b2PolygonDef.Filter.GroupIndex   = GroupIndex;
     b2PolygonDef.Filter.CategoryBits = CategoryBits;
     b2PolygonDef.Filter.MaskBits     = MaskBits;
     b2Body = refWorld.B2World.CreateBody(b2BodyDef);
     b2Body.CreateFixture(b2PolygonDef);
     if (physicalShapeType == PhysicalShapeType.Dynamic)
     {
         b2Body.SetMassFromShapes();
     }
 }
コード例 #3
0
        public void Reset()
        {
            if (vertexes.Count < 3)
            {
                return;
            }

            if (b2Body != null)
            {
                refWorld.B2World.DestroyBody(b2Body);
                b2Body.Dispose();
            }

            b2BodyDef = new BodyDef();

            b2BodyDef.Angle    = Angle / 180.0f * 3.14f;
            b2BodyDef.Position = PhysicalConvert.Tob2Vector(CenterPosition);

            b2PolygonDefs = DivideToTriangles(vertexes);
            b2Body        = refWorld.B2World.CreateBody(b2BodyDef);

            foreach (var item in b2PolygonDefs)
            {
                b2Body.CreateFixture(item);
            }

            if (physicalShapeType == PhysicalShapeType.Dynamic)
            {
                b2Body.SetMassFromShapes();
            }
        }
コード例 #4
0
 public void Reset()
 {
     if (b2Body != null)
     {
         refWorld.B2World.DestroyBody(b2Body);
         b2Body.Dispose();
     }
     b2BodyDef               = new BodyDef();
     b2CircleDef             = new CircleDef();
     b2BodyDef.Angle         = Angle / 180.0f * 3.14f;
     b2BodyDef.Position      = PhysicalConvert.Tob2Vector(Position);
     b2CircleDef.Radius      = PhysicalConvert.Tob2Single(OuterDiameter / 2.0f);
     b2CircleDef.Density     = Density;
     b2CircleDef.Restitution = Restitution;
     b2CircleDef.Friction    = Friction;
     b2CircleDef.Filter      = new FilterData()
     {
         GroupIndex   = GroupIndex,
         CategoryBits = CategoryBits,
         MaskBits     = MaskBits
     };
     b2Body = refWorld.B2World.CreateBody(b2BodyDef);
     b2Body.CreateFixture(b2CircleDef);
     if (physicalShapeType == PhysicalShapeType.Dynamic)
     {
         b2Body.SetMassFromShapes();
     }
 }
コード例 #5
0
 /// <summary>
 /// 衝撃を加える
 /// </summary>
 /// <param name="vector">衝撃を加える方向</param>
 /// <param name="position">衝撃を加えるローカル位置</param>
 public void SetImpulse(asd.Vector2DF vector, asd.Vector2DF position)
 {
     if (!IsActive)
     {
         return;
     }
     b2Body.ApplyImpulse(PhysicalConvert.Tob2Vector(vector), PhysicalConvert.Tob2Vector(CenterPosition + position));
 }
コード例 #6
0
 /// <summary>
 /// 力を加える
 /// </summary>
 /// <param name="vector">力を加える方向</param>
 /// <param name="position">力を加えるローカル位置</param>
 public void SetForce(asd.Vector2DF vector, asd.Vector2DF position)
 {
     if (!IsActive)
     {
         return;
     }
     b2Body.ApplyForce(PhysicalConvert.Tob2Vector(vector), PhysicalConvert.Tob2Vector(DrawingArea.Position + position));
 }
コード例 #7
0
        /// <summary>
        /// ワールドを初期化
        /// </summary>
        /// <param name="worldRect">適用範囲</param>
        /// <param name="gravity">重力</param>
        public PhysicalWorld(asd.RectF worldRect, asd.Vector2DF gravity)
        {
            physicalShapes      = new List <PhysicalShape>();
            collisionController = new CollisionController(this);
            AABB aabb = new AABB();

            aabb.LowerBound = PhysicalConvert.Tob2Vector(worldRect.Position);
            aabb.UpperBound = PhysicalConvert.Tob2Vector(worldRect.Vertexes[2]);
            b2World         = new World(aabb, PhysicalConvert.Tob2Vector(gravity), true);
            b2World.SetContactListener(collisionController);
            b2World.SetContactFilter(new ContactFilter());
            TimeStep           = 1.0f / 60.0f;
            VelocityItetions   = 8;
            PositionIterations = 1;
        }
コード例 #8
0
        public void Reset()
        {
            if (b2Body != null)
            {
                refWorld.B2World.DestroyBody(b2Body);
                b2Body.Dispose();
            }

            b2BodyDef    = new BodyDef();
            b2PolygonDef = new PolygonDef();

            b2BodyDef.Angle    = Angle / 180.0f * 3.14f;
            b2BodyDef.Position = PhysicalConvert.Tob2Vector(CenterPosition);

            var sortedVertexes = new List <asd.Vector2DF>();

            foreach (var item in vertexes)
            {
                sortedVertexes.Add(item);
            }
            sortedVertexes.Sort((a, b) => a.Degree.CompareTo(b.Degree));
            b2PolygonDef.VertexCount = 3;
            for (int i = 0; i < 3; i++)
            {
                b2PolygonDef.Vertices[i] = PhysicalConvert.Tob2Vector(sortedVertexes[i]);
            }

            b2PolygonDef.Density     = Density;
            b2PolygonDef.Restitution = Restitution;
            b2PolygonDef.Friction    = Friction;
            b2PolygonDef.Filter      = new FilterData()
            {
                GroupIndex   = GroupIndex,
                CategoryBits = CategoryBits,
                MaskBits     = MaskBits
            };

            b2Body = refWorld.B2World.CreateBody(b2BodyDef);
            b2Body.CreateFixture(b2PolygonDef);

            if (physicalShapeType == PhysicalShapeType.Dynamic)
            {
                b2Body.SetMassFromShapes();
            }
        }
コード例 #9
0
 /// <summary>
 /// 初期化
 /// </summary>
 /// <param name="shapeType">物理形状タイプ</param>
 /// <param name="world">登録するワールド</param>
 public PhysicalRectangleShape(PhysicalShapeType shapeType, PhysicalWorld world)
 {
     density            = 1;
     restitution        = 0;
     friction           = 0.6f;
     groupIndex         = 0;
     categoryBits       = 0x0001;
     maskBits           = 0xffff;
     b2BodyDef          = new BodyDef();
     b2PolygonDef       = new PolygonDef();
     refWorld           = world;
     physicalShapeType  = shapeType;
     b2BodyDef.Position = PhysicalConvert.Tob2Vector(new asd.Vector2DF());
     b2PolygonDef.SetAsBox(PhysicalConvert.Tob2Single(1) / 2.0f, PhysicalConvert.Tob2Single(1) / 2.0f);
     b2Body = refWorld.B2World.CreateBody(b2BodyDef);
     b2Body.CreateFixture(b2PolygonDef);
     if (physicalShapeType == PhysicalShapeType.Dynamic)
     {
         b2Body.SetMassFromShapes();
     }
     world.Add(this);
 }