Ejemplo n.º 1
0
        private static Ray3D ComputeIntersectionLine(ref Plane3D p1, ref Plane3D p2)
        {
            Ray3D ray = new Ray3D
            {
                Direction = (Vector3D)Normal3D.Cross(p1.Normal, p2.Normal)
            };
            float num = ray.Direction.LengthSquared();

            ray.Origin = (Point3D)(Vector3D.Cross((-p1.D * p2.Normal) + (p2.D * p1.Normal), ray.Direction) / num);
            return(ray);
        }
Ejemplo n.º 2
0
        private void SetMatrix(ref Matrix3D value)
        {
            this.matrix             = value;
            this.planes[2].Normal.X = -value.M14 - value.M11;
            this.planes[2].Normal.Y = -value.M24 - value.M21;
            this.planes[2].Normal.Z = -value.M34 - value.M31;
            this.planes[2].D        = -value.M44 - value.M41;
            this.planes[3].Normal.X = -value.M14 + value.M11;
            this.planes[3].Normal.Y = -value.M24 + value.M21;
            this.planes[3].Normal.Z = -value.M34 + value.M31;
            this.planes[3].D        = -value.M44 + value.M41;
            this.planes[4].Normal.X = -value.M14 + value.M12;
            this.planes[4].Normal.Y = -value.M24 + value.M22;
            this.planes[4].Normal.Z = -value.M34 + value.M32;
            this.planes[4].D        = -value.M44 + value.M42;
            this.planes[5].Normal.X = -value.M14 - value.M12;
            this.planes[5].Normal.Y = -value.M24 - value.M22;
            this.planes[5].Normal.Z = -value.M34 - value.M32;
            this.planes[5].D        = -value.M44 - value.M42;
            this.planes[0].Normal.X = -value.M13;
            this.planes[0].Normal.Y = -value.M23;
            this.planes[0].Normal.Z = -value.M33;
            this.planes[0].D        = -value.M43;
            this.planes[1].Normal.X = -value.M14 + value.M13;
            this.planes[1].Normal.Y = -value.M24 + value.M23;
            this.planes[1].Normal.Z = -value.M34 + value.M33;
            this.planes[1].D        = -value.M44 + value.M43;
            for (int i = 0; i < 6; i++)
            {
                float num2 = this.planes[i].Normal.Length();
                this.planes[i].Normal = (this.planes[i].Normal / num2);
                this.planes[i].D     /= num2;
            }
            Ray3D ray = ComputeIntersectionLine(ref this.planes[0], ref this.planes[2]);

            this.cornerArray[0] = ComputeIntersection(ref this.planes[4], ref ray);
            this.cornerArray[3] = ComputeIntersection(ref this.planes[5], ref ray);
            ray = ComputeIntersectionLine(ref this.planes[3], ref this.planes[0]);
            this.cornerArray[1] = ComputeIntersection(ref this.planes[4], ref ray);
            this.cornerArray[2] = ComputeIntersection(ref this.planes[5], ref ray);
            ray = ComputeIntersectionLine(ref this.planes[2], ref this.planes[1]);
            this.cornerArray[4] = ComputeIntersection(ref this.planes[4], ref ray);
            this.cornerArray[7] = ComputeIntersection(ref this.planes[5], ref ray);
            ray = ComputeIntersectionLine(ref this.planes[1], ref this.planes[3]);
            this.cornerArray[5] = ComputeIntersection(ref this.planes[4], ref ray);
            this.cornerArray[6] = ComputeIntersection(ref this.planes[5], ref ray);
        }
Ejemplo n.º 3
0
 public float? Intersects(Ray3D ray)
 {
     return ray.Intersects(this);
 }
Ejemplo n.º 4
0
        private static Point3D ComputeIntersection(ref Plane3D plane, ref Ray3D ray)
        {
            float num = (-plane.D - Vector3D.Dot(plane.Normal, (Vector3D)ray.Origin)) / Vector3D.Dot(plane.Normal, ray.Direction);

            return(ray.Origin + ray.Direction * num);
        }
Ejemplo n.º 5
0
 public Ray3D Transform(Ray3D ray)
 {
     Ray3D ret;
     ret.Origin = Transform(ray.Origin);
     ret.Direction = Transform(ray.Direction);
     return ret;
 }
Ejemplo n.º 6
0
 public float?Intersects(Ray3D ray)
 {
     return(ray.Intersects(this));
 }