Beispiel #1
0
        /// <summary>
        /// Finds where a line hits the plane, if anywhere.
        /// </summary>
        /// <param name="start">The start of the line.</param>
        /// <param name="end">The end of the line.</param>
        /// <returns>A location of the hit, or NaN if none.</returns>
        public Location IntersectLine(Location start, Location end)
        {
            Location ba     = end - start;
            double   nDotA  = Normal.Dot(start);
            double   nDotBA = Normal.Dot(ba);
            double   t      = -(nDotA + D) / (nDotBA);

            if (t < 0) // || t > 1
            {
                return(Location.NaN);
            }
            return(start + t * ba);
        }
Beispiel #2
0
 public Plane(Location v1, Location v2, Location v3)
 {
     vec1   = v1;
     vec2   = v2;
     vec3   = v3;
     Normal = (v2 - v1).CrossProduct(v3 - v1).Normalize();
     D      = -(Normal.Dot(vec1));
 }
Beispiel #3
0
 public Plane(Location v1, Location v2, Location v3, Location _normal)
 {
     vec1   = v1;
     vec2   = v2;
     vec3   = v3;
     Normal = _normal;
     D      = -(Normal.Dot(vec1));
 }
Beispiel #4
0
        public static Matrix LookAtLH(Location start, Location end, Location up)
        {
            Location zAxis = (end - start).Normalize();
            Location xAxis = up.CrossProduct(zAxis).Normalize();
            Location yAxis = zAxis.CrossProduct(xAxis);

            return(new Matrix((double)xAxis.X, (double)yAxis.X, (double)zAxis.X, 0, (double)xAxis.Y,
                              (double)yAxis.Y, (double)zAxis.Y, 0, (double)xAxis.Z, (double)yAxis.Z, (double)zAxis.Z, 0,
                              (double)-xAxis.Dot(start), (double)-yAxis.Dot(start), (double)-zAxis.Dot(start), 1));
        }