Example #1
0
 public PressureBody(Shape s, float mass, float gasPressure, float edgeSpringK, float edgeSpringDamp, float shapeSpringK, float shapeSpringDamp)
     : base(s, mass, edgeSpringK, edgeSpringDamp, shapeSpringK, shapeSpringDamp)
 {
     pressure = gasPressure;
     normal_list = new Vector2[count];
     edgelength_list = new float[count];
 }
Example #2
0
        public Body(Shape shape, float mass)
        {
            this.base_shape = shape;
            this.curr_shape = shape.Clone();
            this.count = shape.count;

            this.pointmass_list = new PointMass[shape.count];
            for (int i = 0; i < shape.count; i++)
                pointmass_list[i] = new PointMass(shape.points[i], mass);

            this.bitmaskx = new Bitmask();
            this.bitmasky = new Bitmask();
        }
Example #3
0
        public void AddPhysicsBodies()
        {
            Shape groundShape = new Shape();
            groundShape.Begin(true);
            groundShape.Add(new Vector2(-15, 0));
            groundShape.Add(new Vector2(-15, 1));
            groundShape.Add(new Vector2(15, 1));
            groundShape.Add(new Vector2(15, 0));
            groundShape.End();

            ground = new SpringBody(groundShape, float.PositiveInfinity, 0, 0, 0, 0);
            ground.is_static = true;
            ground.position.Y = -1;
            physics.Add(ground);

            float scale = 0.5f;
            Shape boxShape = new Shape();
            boxShape.Begin(true);
            boxShape.Add(new Vector2(0, 0));
            boxShape.Add(new Vector2(0, scale * 0.5f));
            boxShape.Add(new Vector2(scale * 0.5f, scale * 0.5f));
            boxShape.Add(new Vector2(scale * 0.5f, 0));
            boxShape.End();

            for (int i = 0; i < 50; i++)
            {
                bubble = new PressureBody(boxShape, 1, 1, 1300, 20, 1000, 20);
                bubble.position.Y = i * scale * 0.5f;
                bubble.position.X = 0;
                physics.Add(bubble);
            }

            Shape circleShape = new Shape();
            circleShape.Begin(true);
            for (int i = 320; i >= 0; i -= 40)
            {
                circleShape.Add(new Vector2((float)Math.Cos(i / 180f * Math.PI) * 0.25f, (float)Math.Sin(i / 180f * Math.PI) * 0.25f));
            }
            circleShape.End();

            bubble = new PressureBody(circleShape, 1, 1, 130, 20, 130, 20);
            bubble.position.Y = 5;
            bubble.position.X = 5;
            physics.Add(bubble);
        }
        public void RenderShape(Shape shape)
        {
            Color color = new Color(0.5f, 0, 0.5f, 0.3f);

            int i;
            for (i = 0; i < shape.points.Length - 1; i++)
            {
                linebatch.Add(new LineVertex(new Vector3(shape.points[i].X, shape.points[i].Y, 0), color));
                linebatch.Add(new LineVertex(new Vector3(shape.points[i + 1].X, shape.points[i + 1].Y, 0), color));
            }
            linebatch.Add(new LineVertex(new Vector3(shape.points[i].X, shape.points[i].Y, 0), color));
            linebatch.Add(new LineVertex(new Vector3(shape.points[0].X, shape.points[0].Y, 0), color));
        }
Example #5
0
 public Shape Clone()
 {
     Shape clone = new Shape();
     clone.count = this.points.Length;
     clone.points = new Vector2[this.points.Length];
     this.points.CopyTo(clone.points,0);
     return clone;
 }