예제 #1
0
        protected Shape(Phys2DTransform transform)
        {
            Debug.Assert(transform != null);

            this.Transform         = transform;
            this.Transform.OnMove += this.HandleTransformMove;
        }
예제 #2
0
        public static Phys2DTransform Lerp(Phys2DTransform a, Phys2DTransform b, float t)
        {
            var position = Vector2.Lerp(a.Position, b.Position, t);
            var rotation = Mathf.Lerp(a.Rotation, b.Rotation, t);

            return(new Phys2DTransform(position, rotation));
        }
예제 #3
0
        public Circle(Phys2DTransform transform, float radius)
            : base(transform)
        {
            Debug.Assert(radius > 0f);

            this.Radius = radius;

            this.HandleTransformMove();
        }
예제 #4
0
        public Body(Shape shape, float mass)
        {
            Debug.Assert(shape != null);
            Debug.Assert(mass > 0f);

            this.initialTransform = shape.Transform.Clone();

            this.Shape = shape;
            this.Mass  = mass;

            this.Reset();
        }
예제 #5
0
        public Polyline(Phys2DTransform transform, PointSet localPoints)
            : base(transform)
        {
            Debug.Assert(localPoints != null && localPoints.Count >= 2);

            this.localPoints   = localPoints;
            this.localSegments = new List <LineSegment>();

            FillMultiEdgeSegments(this.localPoints, this.localSegments);

            this.worldPoints   = new PointSet();
            this.worldSegments = new List <LineSegment>();

            this.HandleTransformMove();
        }
예제 #6
0
        public Polygon(Phys2DTransform transform, PointSet localPoints)
            : base(transform)
        {
            Debug.Assert(localPoints != null && localPoints.Count >= 3);

            this.localPoints = localPoints;
            this.localEdges  = new List <LineSegment>();

            FillPolygonEdges(this.localPoints, this.localEdges);
            // TODO: Assert whether any edges intersect

            this.worldPoints = new PointSet();
            this.worldEdges  = new List <LineSegment>();

            this.HandleTransformMove();
        }
예제 #7
0
        public void Transform(Phys2DTransform transform)
        {
            Debug.Assert(transform != null);

            var shouldRotate = !Mathf.Approximately(transform.Rotation, 0f);
            var shouldOffset = transform.Position != Vector2.zero;

            for (var i = 0; i < this.points.Count; i++)
            {
                var newP = this.points[i];

                if (shouldRotate)
                {
                    newP = newP.Rotate(transform.Rotation);
                }

                if (shouldOffset)
                {
                    newP += transform.Position;
                }

                this.points[i] = newP;
            }
        }
예제 #8
0
 public Phys2DTransform LerpedTransform(float t)
 {
     return(Phys2DTransform.Lerp(this.lastTransform, this.Shape.Transform, t));
 }
예제 #9
0
        public void Reset()
        {
            this.Shape.Transform.Set(this.initialTransform);

            this.lastTransform = this.Shape.Transform.Clone();
        }
예제 #10
0
 public Polygon(Phys2DTransform transform, List <Vector2> localPoints)
     : this(transform, new PointSet(localPoints))
 {
 }
예제 #11
0
 public void Set(Phys2DTransform transform)
 {
     this.Set(transform.Position, transform.Rotation);
 }