Exemplo n.º 1
0
 public Drag(List<EditorObject> modified, Transform2 transform)
 {
     IsMarker = true;
     foreach (EditorObject e in modified)
     {
         _modified.Add(new MementoDrag(e));
     }
     _transform = transform.ShallowClone();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Determine a position that is sufficiently far away from all portals so that it isn't ambiguous which side of a 
        /// portal the position is at.
        /// </summary>
        /// <param name="portals"></param>
        /// <param name="portalPrevious">The last portal that was exited.</param>
        /// <param name="transform"></param>
        /// <param name="velocity"></param>
        private static Transform2 AddMargin(IEnumerable<IPortal> portals, IPortal portalPrevious, Transform2 transform, Transform2 velocity)
        {
            transform = transform.ShallowClone();
            foreach (IPortal p in portals)
            {
                if (!Portal.IsValid(p))
                {
                    continue;
                }
                LineF exitLine = new LineF(Portal.GetWorldVerts(p));
                Vector2 position = transform.Position;
                double distanceToPortal = MathExt.PointLineDistance(position, exitLine, true);
                if (distanceToPortal < Portal.EnterMinDistance)
                {
                    Vector2 exitNormal = p.WorldTransform.GetRight();
                    Side sideOf;
                    if (p == portalPrevious)
                    {
                        sideOf = exitLine.GetSideOf(position + velocity.Position);
                    }
                    else
                    {
                        sideOf = exitLine.GetSideOf(position - velocity.Position);
                    }
                    if (sideOf != exitLine.GetSideOf(exitNormal + p.WorldTransform.Position))
                    {
                        exitNormal = -exitNormal;
                    }

                    Vector2 pos = exitNormal * (Portal.EnterMinDistance - (float)distanceToPortal);
                    transform.Position += pos;
                    break;
                }
            }
            return transform;
        }
Exemplo n.º 3
0
 private static Transform2 UndoPortalTransform(BodyData data, Transform2 transform)
 {
     Transform2 copy = transform.ShallowClone();
     if (data.Parent == null)
     {
         return copy;
     }
     return UndoPortalTransform(
         data.Parent,
         copy.Transform(Portal.GetLinkedTransform(data.BodyParent.Portal).Inverted()));
 }
Exemplo n.º 4
0
 public override void SetVelocity(Transform2 velocity)
 {
     Velocity = velocity.ShallowClone();
     base.SetVelocity(velocity);
 }
Exemplo n.º 5
0
 public override void SetTransform(Transform2 transform)
 {
     Transform = transform.ShallowClone();
     base.SetTransform(transform);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Returns new velocity from entering portal.
        /// </summary>
        /// <param name="portal">Portal being entered.</param>
        /// <param name="intersectT">Intersection point on the portal.</param>
        /// <param name="velocity">Velocity before entering.</param>
        public static Transform2 EnterVelocity(IPortal portal, float intersectT, Transform2 velocity, bool ignorePortalVelocity = false)
        {
            Debug.Assert(IsValid(portal));
            Matrix4 matrix = GetLinkedMatrix(portal);
            Vector2 origin = Vector2Ext.Transform(new Vector2(), matrix);
            Transform2 velocityClone = velocity.ShallowClone();

            if (!ignorePortalVelocity)
            {
                velocityClone.Position -= portal.WorldVelocity.Position;
                velocityClone.Rotation -= portal.WorldVelocity.Rotation;
                velocityClone.Position -= GetAngularVelocity(portal, intersectT);
            }
            velocityClone.Position = Vector2Ext.Transform(velocityClone.Position, matrix);
            velocityClone.Position -= origin;

            if (portal.WorldTransform.MirrorX == portal.Linked.WorldTransform.MirrorX)
            {
                velocityClone.Rotation = -velocityClone.Rotation;
            }
            if (!ignorePortalVelocity)
            {
                velocityClone.Position += portal.Linked.WorldVelocity.Position;
                velocityClone.Rotation += portal.Linked.WorldVelocity.Rotation;
                velocityClone.Position += GetAngularVelocity(portal.Linked, intersectT);
            }
            return velocityClone;
        }
Exemplo n.º 7
0
 public Drag(HashSet<MementoDrag> modified, Transform2 transform)
 {
     _modified.UnionWith(modified);
     _transform = transform.ShallowClone();
 }
Exemplo n.º 8
0
 public void SetTransform(Transform2 transform)
 {
     _transform = transform.ShallowClone();
 }