Пример #1
0
        /// <summary>
        /// Builds an array of <see cref="Vector2"/> containing the normals used for the SAT algorithm for this <see cref="RectangleF"/> instance.
        /// </summary>
        /// <remarks>
        /// The array only contains the top and right normals as the bottom and left normals are the same (just rotated 180 degrees).
        /// </remarks>
        /// <returns>Array of normal vectors.</returns>
        private Vector2[] GetSATNormals()
        {
            Vector2[] normalVectors = new Vector2[4];

            normalVectors[0] = Vector2Helper.VectorFromRotation(this.Rotation);
            normalVectors[1] = normalVectors[0].Rotate(MathHelper.PiOver2);

            return(normalVectors);
        }
Пример #2
0
        /// <summary>
        /// Rotates this point about another by the given rotation.
        /// </summary>
        /// <param name="targetPoint">This <see cref="Vector2"/> instance.</param>
        /// <param name="rotationPoint">The point to rotate about.</param>
        /// <param name="rotation">The rotation to perform (in radians).</param>
        /// <returns>The new rotated point.</returns>
        public static Vector2 RotateAbout(this Vector2 targetPoint, Vector2 rotationPoint, float rotation)
        {
            Vector2 difference = targetPoint - rotationPoint; // Center the point of rotation at the origin

            if (difference == Vector2.Zero)
            {
                return(targetPoint);
            }
            else
            {
                float angle = difference.AngleBetween(Vector2Helper.Up) + rotation;                      // Get the new angle from the UP vector
                return((Vector2Helper.VectorFromRotation(angle) * difference.Length()) + rotationPoint); // Get the new vector and move it off the origin
            }
        }