Normalized() public method

Returns a normalized representation of the vector. A normalized vector has a length of 1.
public Normalized ( ) : Vector3
return Vector3
示例#1
0
        /// <summary>
        /// Calculates the view matrix.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="up">The up direction.</param>
        /// <returns>The calculated view matrix.</returns>
        public static Matrix CalculateViewMatrix(Vector3 position, Vector3 direction, Vector3 up)
        {
            var n = -direction.Normalized();
            var u = up.Cross(n).Normalized();
            var v = n.Cross(u);
            var e = -position;

            return new Matrix(
                u.X, v.X, n.X, 0,
                u.Y, v.Y, n.Y, 0,
                u.Z, v.Z, n.Z, 0,
                u.Dot(e), v.Dot(e), n.Dot(e), 1);
        }
示例#2
0
        public void Normalized()
        {
            var original = new Vector3(1, 3, 5);

            var normalized = original.Normalized();

            var expected = new Vector3(original.X / original.Length,
                original.Y / original.Length, original.Z / original.Length);

            Assert.AreEqual(expected, normalized);
        }
示例#3
0
        public void Position_and_Direction_with_radius_and_declination()
        {
            var orbitingStand = new OrbitingStand(10, 0, Constants.HALF_PI * 0.5f);

            var expectedPosition = new Vector3(10 / Functions.Sqrt(2), 10 / Functions.Sqrt(2), 0);
            Assert.AreEqual(expectedPosition,
                orbitingStand.Position, new Vector3EqualityComparer());
            Assert.AreEqual(-expectedPosition.Normalized(), orbitingStand.Direction,
                new Vector3EqualityComparer());
        }
示例#4
0
        public void Position_and_Direction_with_radius_azimuth_and_declination()
        {
            var orbitingStand = new OrbitingStand(
                10, Constants.PI * 0.75f, Constants.HALF_PI * 0.5f);

            var expectedPosition = new Vector3(-5, 7.071068f, 5);
            Assert.AreEqual(expectedPosition, orbitingStand.Position,
                new Vector3EqualityComparer());
            Assert.AreEqual(-expectedPosition.Normalized(), orbitingStand.Direction,
                new Vector3EqualityComparer());
        }