Ejemplo n.º 1
0
            public override void SetConstants(IGraphicsContext context)
            {
                // set camera parameters
                var camera = context.CurrentCamera;

                Effect.Parameters["wPosCamera"].SetValue(camera.Position);
                Effect.Parameters["near_plane"].SetValue((float)camera.NearPlane);
                Effect.Parameters["far_plane"].SetValue((float)camera.FarPlane);
                Effect.Parameters["fov"].SetValue((float)camera.FieldOfView);

                Vector3D[] frustumCornersWS    = new Vector3D[8];
                Vector3D[] farFrustumCornersWS = new Vector3D[4];
                Vector3D[] farFrustumCornersVS = new Vector3D[4];
                MatrixD    view = camera.ViewD;

                BoundingFrustumD frustum = new BoundingFrustumD(context.RenderContext.ViewProjD);

                frustum.GetCorners(frustumCornersWS);

                //  2 ____________  1
                //   |            |
                //   |            |
                //   |            |
                //  3|____________| 0
                //
                for (int i = 4; i < 8; i++)
                {
                    farFrustumCornersWS[i - 4] = frustumCornersWS[i];
                }

                Vector3D.TransformCoordinate(farFrustumCornersWS, ref view, farFrustumCornersVS);

                Vector3D[] o  = new Vector3D[4];
                Vector4D[] o4 = new Vector4D[4];
                for (int i = 0; i < 4; i++)
                {
                    Vector3D.Normalize(ref farFrustumCornersVS[i], out o[i]);
                    o4[i] = new Vector4D(o[i], 1.0);
                }

                Effect.Parameters["frustumCornersVS"].SetValue(o4.Select(v => v.ToVector4()).ToArray());
                view.Invert();
                Effect.Parameters["IView"].SetValue(view.ToMatrix());

                // set sun parameters
                Effect.Parameters["sunVector"].SetValue(new Vector3(0, 0, 1));
            }
Ejemplo n.º 2
0
        public static LineD[] GetLines(this BoundingFrustumD frust)
        {
            var corners = new Vector3D[8];

            frust.GetCorners(corners);
            var lines = new LineD[12];

            lines[0]  = new LineD(corners[0], corners[1]);
            lines[1]  = new LineD(corners[1], corners[2]);
            lines[2]  = new LineD(corners[2], corners[3]);
            lines[3]  = new LineD(corners[3], corners[0]);
            lines[4]  = new LineD(corners[4], corners[5]);
            lines[5]  = new LineD(corners[5], corners[6]);
            lines[6]  = new LineD(corners[6], corners[7]);
            lines[7]  = new LineD(corners[7], corners[4]);
            lines[8]  = new LineD(corners[0], corners[4]);
            lines[9]  = new LineD(corners[1], corners[5]);
            lines[10] = new LineD(corners[2], corners[6]);
            lines[11] = new LineD(corners[3], corners[7]);
            return(lines);
        }
Ejemplo n.º 3
0
        public static void DrawBoundingFrustum(BoundingFrustumD boundingFrustum, Color color)
        {
            boundingFrustum.GetCorners(m_frustumCorners);
            m_lineBatch.Begin();

            // near face            
            m_lineBatch.DrawLine(m_frustumCorners[0], m_frustumCorners[1], color);
            m_lineBatch.DrawLine(m_frustumCorners[1], m_frustumCorners[2], color);
            m_lineBatch.DrawLine(m_frustumCorners[2], m_frustumCorners[3], color);
            m_lineBatch.DrawLine(m_frustumCorners[3], m_frustumCorners[0], color);

            // far face            
            m_lineBatch.DrawLine(m_frustumCorners[4], m_frustumCorners[5], color);
            m_lineBatch.DrawLine(m_frustumCorners[5], m_frustumCorners[6], color);
            m_lineBatch.DrawLine(m_frustumCorners[6], m_frustumCorners[7], color);
            m_lineBatch.DrawLine(m_frustumCorners[7], m_frustumCorners[4], color);

            // top,right,bottom,left face            
            m_lineBatch.DrawLine(m_frustumCorners[0], m_frustumCorners[4], color);
            m_lineBatch.DrawLine(m_frustumCorners[1], m_frustumCorners[5], color);
            m_lineBatch.DrawLine(m_frustumCorners[2], m_frustumCorners[6], color);
            m_lineBatch.DrawLine(m_frustumCorners[3], m_frustumCorners[7], color);

            m_lineBatch.End();
        }