コード例 #1
0
ファイル: Scene.cs プロジェクト: LodrikMtl/PhySim2D
        public Scene()
        {
            KTransform      t1 = new KTransform(new KVector2(0f, 2f), 1f, new KVector2(3, 1));
            KTransform      t2 = new KTransform(new KVector2(0, 0f), 0f, new KVector2(1, 1));
            KTransform      t3 = new KTransform(new KVector2(0f, 9f), 0.5, new KVector2(2, 1));
            List <Collider> ss = new List <Collider>
            {
                new Circle(new KVector2(0, 0)),
                new Circle(new KVector2(10, 4))
            };
            //Vertices v1 = new Vertices()
            //{
            // new KVector2(-1f, -1f),
            // new KVector2(-2.62f, 0.18f),
            // new KVector2(-2.62f, 3.98f),
            // new KVector2(-1f, 5.16f),
            // new KVector2(1f, 5.16f),
            // new KVector2(2.62f, 3.98f),
            // new KVector2(2.62f, 0.18f),
            // new KVector2(1f, -1f),
            //};
            //v1.Reverse();
            KVertices v1 = new KVertices()
            {
                new KVector2(0.5f, 0.5f),
                new KVector2(-0.5f, 0.5f),
                new KVector2(-0.5f, -0.5f),
                new KVector2(0.5f, -0.5f),
            };
            //Vertices v1 = new Vertices()
            //{
            //    new KVector2(-0.4330127018922f,-0.25f),
            //    new KVector2(0.4330127018922f,-0.25f),
            //    new KVector2(0f,0.5f),
            //};
            //v1.Reverse();
            //Vertices v = new Vertices()
            //{
            //    new KVector2(0.5f,0.5f),
            //    new KVector2(-0.5f,0.5f),
            //    new KVector2(-0.5f,-0.5f),
            //    new KVector2(0.5f,-0.5f),
            //};
            KVertices v = new KVertices()
            {
                new KVector2(5f, 5f),
                new KVector2(-5f, 5f),
                new KVector2(-5f, -5f),
                new KVector2(5f, -5f),
            };

            Rigidbody s  = BodyFactory.CreatePolygon(t1, new MassData(3, 3), v1);
            Rigidbody s2 = BodyFactory.CreatePolygon(t3, new MassData(1, 3), v1);

            c = BodyFactory.CreateCircleBody(new MassData(1, 1), t3);
            Rigidbody seg = BodyFactory.CreateSegmentBody(new KVector2(-1, 0), new KVector2(1, 0), new MassData(1, 1), t2);

            rect = BodyFactory.CreatePolygon(t2, new MassData(1, 0), v);
            //Bodies.Add(BodyFactory.CreateCircleBody(new MassData(1, 1), t1));
            //Bodies.Add(seg);
            Bodies.Add(rect);
            Bodies.Add(c);
            s.AddImpulseAtWPos(new KVector2(3f, 0), s.State.Transform.Position);

            s.State.ForceGenerators.Add("G", new GravityHMR(new KVector2(0, -2)));
            c.State.ForceGenerators.Add("G", new GravityHMR(new KVector2(0, -2)));

            Integrator = new RK4();
        }