/// <summary> /// Returns an axis-locked version of the specified vector, if requested by the user. Doesn't /// do anything when no axis lock is in currently active. /// </summary> /// <param name="baseVec">The base vector without any locking in place.</param> /// <param name="lockedVec">A reference vector that represents the base vector being locked to all axes at once.</param> /// <param name="beginToTarget">The movement vector to evaluate in order to determine the axes to which the base vector will be locked.</param> /// <returns></returns> protected Vector3 ApplyAxisLock(Vector3 baseVec, Vector3 lockedVec, Vector3 beginToTarget) { bool shift = (Control.ModifierKeys & Keys.Shift) != Keys.None; if (!shift) { this.actionLockedAxis = LockedAxis.None; return(baseVec); } else { float xWeight = MathF.Abs(Vector3.Dot(beginToTarget.Normalized, Vector3.UnitX)); float yWeight = MathF.Abs(Vector3.Dot(beginToTarget.Normalized, Vector3.UnitY)); float zWeight = MathF.Abs(Vector3.Dot(beginToTarget.Normalized, Vector3.UnitZ)); if (xWeight >= yWeight && xWeight >= zWeight) { this.actionLockedAxis = LockedAxis.X; return(new Vector3(baseVec.X, lockedVec.Y, lockedVec.Z)); } else if (yWeight >= xWeight && yWeight >= zWeight) { this.actionLockedAxis = LockedAxis.Y; return(new Vector3(lockedVec.X, baseVec.Y, lockedVec.Z)); } else if (zWeight >= yWeight && zWeight >= xWeight) { this.actionLockedAxis = LockedAxis.Z; return(new Vector3(lockedVec.X, lockedVec.Y, baseVec.Z)); } return(lockedVec); } }
protected override void OnKeyUp(KeyEventArgs e) { if (e.KeyCode == Keys.ShiftKey) { this.actionLockedAxis = LockedAxis.None; this.UpdateAction(); } else if (e.KeyCode == Keys.ControlKey) { this.UpdateAction(); } base.OnKeyUp(e); }