Beispiel #1
0
        /// <summary>
        /// Crea una instancia de HFrustum a partir de una luz de tipo spot
        /// </summary>
        public Frustum(SpotLight spot)
        {
            planes = new List <Plane>(6);

            for (int i = 0; i < 6; i++)
            {
                planes.Add(new Plane());
            }

            UpdateFromSpotLight(spot);
        }
Beispiel #2
0
        /// <summary>
        /// Actualiza el frustum en base a una luz spot
        /// </summary>
        public void UpdateFromSpotLight(SpotLight spot)
        {
            //System.Diagnostics.Debug.Assert(planes.Count == 6);

            Matrix viewProjection = Matrix.Invert(spot.LocalMatrix) * spot.ProjectorPerspective;

            planes.Clear();

            float A, B, C, D;
            Plane p;

            // Left clipping plane
            A = -(viewProjection.M14 + viewProjection.M11);
            B = -(viewProjection.M24 + viewProjection.M21);
            C = -(viewProjection.M34 + viewProjection.M31);
            D = -(viewProjection.M44 + viewProjection.M41);
            p = new Plane(A, B, C, D);
            p.Normalize();
            planes.Add(p);

            // Right clipping plane
            A = -(viewProjection.M14 - viewProjection.M11);
            B = -(viewProjection.M24 - viewProjection.M21);
            C = -(viewProjection.M34 - viewProjection.M31);
            D = -(viewProjection.M44 - viewProjection.M41);
            p = new Plane(A, B, C, D);
            p.Normalize();
            planes.Add(p);

            // Top clipping plane
            A = -(viewProjection.M14 - viewProjection.M12);
            B = -(viewProjection.M24 - viewProjection.M22);
            C = -(viewProjection.M34 - viewProjection.M32);
            D = -(viewProjection.M44 - viewProjection.M42);
            p = new Plane(A, B, C, D);
            p.Normalize();
            planes.Add(p);

            // Bottom clipping plane
            A = -(viewProjection.M14 + viewProjection.M12);
            B = -(viewProjection.M24 + viewProjection.M22);
            C = -(viewProjection.M34 + viewProjection.M32);
            D = -(viewProjection.M44 + viewProjection.M42);
            p = new Plane(A, B, C, D);
            p.Normalize();
            planes.Add(p);

            // Near clipping plane
            A = -(viewProjection.M14 + viewProjection.M13);
            B = -(viewProjection.M24 + viewProjection.M23);
            C = -(viewProjection.M34 + viewProjection.M33);
            D = -(viewProjection.M44 + viewProjection.M43);
            p = new Plane(A, B, C, D);
            p.Normalize();
            planes.Add(p);

            // Far clipping plane
            A = -(viewProjection.M14 - viewProjection.M13);
            B = -(viewProjection.M24 - viewProjection.M23);
            C = -(viewProjection.M34 - viewProjection.M33);
            D = -(viewProjection.M44 - viewProjection.M43);
            p = new Plane(A, B, C, D);
            p.Normalize();
            planes.Add(p);

            // Create device clipping planes
            //CreateDeviceClipPlanes();
        }