public Drag(List<EditorObject> modified, Transform2 transform) { IsMarker = true; foreach (EditorObject e in modified) { _modified.Add(new MementoDrag(e)); } _transform = transform.ShallowClone(); }
/// <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; }
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())); }
public override void SetVelocity(Transform2 velocity) { Velocity = velocity.ShallowClone(); base.SetVelocity(velocity); }
public override void SetTransform(Transform2 transform) { Transform = transform.ShallowClone(); base.SetTransform(transform); }
/// <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; }
public Drag(HashSet<MementoDrag> modified, Transform2 transform) { _modified.UnionWith(modified); _transform = transform.ShallowClone(); }
public void SetTransform(Transform2 transform) { _transform = transform.ShallowClone(); }