Пример #1
0
        /// <summary>
        /// Builds the Planes so that they make up the left, right, up, down, front and back of the Frustum
        /// </summary>
        public void UpdateFrustum(Matrix4 projectionMatrix, Matrix4 modelviewMatrix)
        {
            Matrix4 clipMatrix = modelviewMatrix * projectionMatrix;

            planes[0] = new Plane(clipMatrix[0].w - clipMatrix[0].x, clipMatrix[1].w - clipMatrix[1].x, clipMatrix[2].w - clipMatrix[2].x, clipMatrix[3].w - clipMatrix[3].x);
            planes[1] = new Plane(clipMatrix[0].w + clipMatrix[0].x, clipMatrix[1].w + clipMatrix[1].x, clipMatrix[2].w + clipMatrix[2].x, clipMatrix[3].w + clipMatrix[3].x);
            planes[2] = new Plane(clipMatrix[0].w + clipMatrix[0].y, clipMatrix[1].w + clipMatrix[1].y, clipMatrix[2].w + clipMatrix[2].y, clipMatrix[3].w + clipMatrix[3].y);
            planes[3] = new Plane(clipMatrix[0].w - clipMatrix[0].y, clipMatrix[1].w - clipMatrix[1].y, clipMatrix[2].w - clipMatrix[2].y, clipMatrix[3].w - clipMatrix[3].y);
            planes[4] = new Plane(clipMatrix[0].w - clipMatrix[0].z, clipMatrix[1].w - clipMatrix[1].z, clipMatrix[2].w - clipMatrix[2].z, clipMatrix[3].w - clipMatrix[3].z);
            planes[5] = new Plane(clipMatrix[0].w + clipMatrix[0].z, clipMatrix[1].w + clipMatrix[1].z, clipMatrix[2].w + clipMatrix[2].z, clipMatrix[3].w + clipMatrix[3].z);

            for (int i = 0; i < 6; i++)
            {
                float t_mag = planes[i].Normal.Length;
                planes[i].Scalar /= t_mag;
                planes[i].Normal /= t_mag;
            }
        }
Пример #2
0
 /// <summary>
 /// Builds a duplicate plane
 /// </summary>
 /// <param name="_Plane">Plane to duplicate</param>
 public Plane(Plane plane)
 {
     normal = plane.Normal;
     scalar = plane.Scalar;
 }
Пример #3
0
 /// <summary>
 /// Builds a new Frustum and initializes six new planes
 /// </summary>
 public Frustum()
 {
     planes = new Plane[6];
     for (int i = 0; i < 6; i++) planes[i] = new Plane(0, 0, 0, 0);
 }
Пример #4
0
 /// <summary>
 /// Returns the position of the AxisAlignedBoudingBox relative to a plane
 /// </summary>
 /// <param name="p">Plane to test</param>
 /// <returns>Negative, Positive or Both sides of plane</returns>
 public Plane.PlaneSide Intersects(Plane p)
 {
     return p.Intersects(this);
 }