Пример #1
0
 public Spring(PointMass pointmass_a, PointMass pointmass_b, float k, float damping, float length)
 {
     this.pointmass_a = pointmass_a;
     this.pointmass_b = pointmass_b;
     this.d = length;
     this.k = k;
     this.damping = damping;
 }
Пример #2
0
 public void Clear()
 {
     body_a = body_b = null;
     pointmass_a = pointmass_b = pointmass_c = new PointMass();
     edge_distance = 0f;
     point = Vector2.Zero;
     normal = Vector2.Zero;
     penetration = 0f;
 }
Пример #3
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();
        }
Пример #4
0
        public Chain(PointMass from, PointMass to, int count, float k, float damping, float mass)
        {
            this.damping = 0.99f;
            this.pointmass_list = new List<PointMass>();
            this.spring_list = new List<Spring>();

            float length = Vector2.Distance(from.position, to.position) / count;
            Vector2 direction = to.position - from.position;
            direction.Normalize();

            for (int i = 0; i < count+1; i++)
                pointmass_list.Add(new PointMass(new Vector2(from.position.X + direction.X * length * i, from.position.Y + direction.Y * length* i), mass));

            pointmass_list[0] = from;
            pointmass_list[count] = to;

            for (int i = 1; i < count+1; i++)
                spring_list.Add(new Spring(pointmass_list[i - 1], pointmass_list[i - 0], k, damping));
        }
Пример #5
0
 public Spring(PointMass pointmass_a, PointMass pointmass_b, float k, float damping)
     : this(pointmass_a, pointmass_b, k, damping, 0)
 {
     Reset();
 }
Пример #6
0
        public void RenderOutlines(PointMass[] points)
        {
            Color color = Color.White;

            int i;
            for (i = 0; i < points.Length - 1; i++)
            {
                linebatch.Add(new LineVertex(new Vector3(points[i].position.X, points[i].position.Y, 0), color));
                linebatch.Add(new LineVertex(new Vector3(points[i + 1].position.X, points[i + 1].position.Y, 0), color));
            }
            linebatch.Add(new LineVertex(new Vector3(points[i].position.X, points[i].position.Y, 0), color));
            linebatch.Add(new LineVertex(new Vector3(points[0].position.X, points[0].position.Y, 0), color));
        }
Пример #7
0
        public void RenderNormals(PointMass[] points)
        {
            Color color = Color.Purple;
            float size = 0.1f;

            int prevPt, nextPt;
            Vector2 pt, prev, next, fromPrev, toNext, ptNorm;
            fromPrev = toNext = ptNorm = new Vector2();

            for (int i = 0; i < points.Length; i++)
            {
                pt = points[i].position;
                prevPt = (i > 0) ? i - 1 : points.Length - 1;
                nextPt = (i < points.Length - 1) ? i + 1 : 0;
                prev = points[prevPt].position;
                next = points[nextPt].position;
                fromPrev.X = pt.X - prev.X;
                fromPrev.Y = pt.Y - prev.Y;
                toNext.X = next.X - pt.X;
                toNext.Y = next.Y - pt.Y;
                fromPrev.Normalize();
                toNext.Normalize();
                ptNorm.X = -(fromPrev.Y + toNext.Y);
                ptNorm.Y = fromPrev.X + toNext.X;
                ptNorm.Normalize();

                linebatch.Add(new LineVertex(new Vector3(pt.X, pt.Y, 0), color));
                linebatch.Add(new LineVertex(new Vector3(pt.X + ptNorm.X * size, pt.Y + ptNorm.Y * size, 0), color));
            }
        }