Ejemplo n.º 1
0
        public static XMVector Reflect(XMVector incident, XMVector normal)
        {
            //// Result = Incident - (2 * dot(Incident, Normal)) * Normal

            XMVector result;

            result = XMVector2.Dot(incident, normal);
            result = XMVector.Add(result, result);
            result = XMVector.NegativeMultiplySubtract(result, normal, incident);
            return(result);
        }
Ejemplo n.º 2
0
        public static XMVector AngleBetweenVectors(XMVector v1, XMVector v2)
        {
            XMVector l1  = XMVector2.ReciprocalLength(v1);
            XMVector l2  = XMVector2.ReciprocalLength(v2);
            XMVector dot = XMVector2.Dot(v1, v2);

            l1 = XMVector.Multiply(l1, l2);

            return(XMVector.Multiply(dot, l1)
                   .Clamp(XMGlobalConstants.NegativeOne, XMGlobalConstants.One)
                   .ACos());
        }
Ejemplo n.º 3
0
        public static XMVector LinePointDistance(XMVector linePoint1, XMVector linePoint2, XMVector point)
        {
            //// Given a vector PointVector from LinePoint1 to Point and a vector
            //// LineVector from LinePoint1 to LinePoint2, the scaled distance
            //// PointProjectionScale from LinePoint1 to the perpendicular projection
            //// of PointVector onto the line is defined as:
            ////
            ////     PointProjectionScale = dot(PointVector, LineVector) / LengthSq(LineVector)

            XMVector pointVector = XMVector.Subtract(point, linePoint1);
            XMVector lineVector  = XMVector.Subtract(linePoint2, linePoint1);

            XMVector lengthSq = XMVector2.LengthSquare(lineVector);

            XMVector pointProjectionScale = XMVector2.Dot(pointVector, lineVector);

            pointProjectionScale = XMVector.Divide(pointProjectionScale, lengthSq);

            XMVector distanceVector = XMVector.Multiply(lineVector, pointProjectionScale);

            distanceVector = XMVector.Subtract(pointVector, distanceVector);

            return(XMVector2.Length(distanceVector));
        }
Ejemplo n.º 4
0
 public static XMVector AngleBetweenNormals(XMVector n1, XMVector n2)
 {
     return(XMVector2.Dot(n1, n2)
            .Clamp(XMGlobalConstants.NegativeOne, XMGlobalConstants.One)
            .ACos());
 }
Ejemplo n.º 5
0
 public static XMVector LengthSquare(XMVector v)
 {
     return(XMVector2.Dot(v, v));
 }