当前位置: 首页>>代码示例>>C#>>正文


C# BoundingFrustum类代码示例

本文整理汇总了C#中BoundingFrustum的典型用法代码示例。如果您正苦于以下问题:C# BoundingFrustum类的具体用法?C# BoundingFrustum怎么用?C# BoundingFrustum使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BoundingFrustum类属于命名空间,在下文中一共展示了BoundingFrustum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Draw

        public void Draw(
            ref BoundingFrustum boundingFrustum,
            Effect effect,
            ref Color vertexColor)
        {
            var coners = boundingFrustum.GetCorners();
            var vertices = new VertexPositionColor[8];
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = coners[i];
                vertices[i].Color = vertexColor;
            }

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                    PrimitiveType.LineList,
                    vertices,
                    0,
                    8,
                    indices,
                    0,
                    primitiveCount);
            }
        }
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:26,代码来源:BoundingFrustumDrawer.cs

示例2: CullMeshes

        public void CullMeshes(ref ChunkCoordinate current, ref BoundingFrustum frustum)
        {
            BoundingBox box;
            if (!current.Equals(ref _previous))
            {
                _solidMeshes.Sort((x, y) => x.Position.LengthSquared().CompareTo(y.Position.LengthSquared()));
                _transparentMeshes.Sort((x, y) => -x.Position.LengthSquared().CompareTo(y.Position.LengthSquared()));
            }

            for (int i = 0; i < _solidMeshes.Count; i++)
            {
                _solidMeshes[i].GetBoundingBox(out box);
                if (frustum.Contains(box) != ContainmentType.Disjoint)
                {
                    _solidMeshRenderQueue.Enqueue(_solidMeshes[i]);
                }
            }

            for (int i = 0; i < _transparentMeshes.Count; i++)
            {
               _transparentMeshes[i].GetBoundingBox(out box);
               if (frustum.Contains(box) != ContainmentType.Disjoint)
               {
                   _transparentMeshRenderQueue.Enqueue(_transparentMeshes[i]);
               }
            }
        }
开发者ID:lancelot2112,项目名称:CubeEngine,代码行数:27,代码来源:ChunkMeshRenderer.cs

示例3: Camera

 /// <summary>
 /// Public constructor. Creates a new camera.
 /// </summary>
 /// <param name="world">The world transformation matrix holding the cameras position and orientation.</param>
 /// <param name="projection">The projection transformation matrix specifing the perspective on the world.</param>
 public Camera(Matrix world, Matrix projection)
 {
     _world = world;
     _view = Matrix.Invert(world);
     _projection = projection;
     _frustum = new BoundingFrustum(_view * _projection);
 }
开发者ID:dweidner,项目名称:xna-honeycube,代码行数:12,代码来源:Camera.cs

示例4: Projector

        public Projector()
            : base()
        {
            const float near = 0.2f;
            const float far = 2.3f;
            const float scale = 1.0f / ScreenDistance * near;
            projection = Matrix.CreatePerspectiveOffCenter(
                scale * Skreen.Left, scale * Skreen.Right,
                scale * -Skreen.Height / 2, scale * Skreen.Height / 2,
                near, far);
            view = Matrix.CreateTranslation(0.0f, -Skreen.Height / 2, -ScreenDistance);

            // this.Width = Screen.PixelWidth;
            // this.Height = Screen.PixelHeight;
            // this.Left = WinScreen.AllScreens.Where(s => s != WinScreen.PrimaryScreen).First().Bounds.Left;
            // this.WindowState = FormWindowState.Maximized;
            // this.FormBorderStyle = FormBorderStyle.None;
            
            var num = Skreen.PixelHeight;
            var frustum = new BoundingFrustum(view * projection);
            var corners = frustum.GetCorners();
            var tpos = corners[4];
            var tray = (corners[7] - corners[4]) / (float)num;
            var bpos = corners[5];
            var bray = (corners[6] - corners[5]) / (float)num;

            SweptPlanes = new Plane[num];
            var projectorPos = Vector3.Zero;//.Invert(this.View).Translation;
            for (int i = 0; i < num; ++i)
                SweptPlanes[i] = new Plane(projectorPos, tpos + (float)i * tray, bpos + (float)i * bray);
        }
开发者ID:JaapSuter,项目名称:Pentacorn,代码行数:31,代码来源:Projector.cs

示例5: UpdateFromBoundingFrustum

        public void UpdateFromBoundingFrustum(BoundingFrustum sourceBoundingFrustum)
        {
            #region Create the lines if necessary

            if (mLines.Count == 0)
            {
                for (int i = 0; i < NumberOfLines; i++)
                {
                    Line line = ShapeManager.AddLine();
                    mLines.Add(line);
                }
            }

            #endregion

            Vector3[] corners = sourceBoundingFrustum.GetCorners();

            mLines[0].SetFromAbsoluteEndpoints(corners[0], corners[1]);
            mLines[1].SetFromAbsoluteEndpoints(corners[1], corners[2]);
            mLines[2].SetFromAbsoluteEndpoints(corners[2], corners[3]);
            mLines[3].SetFromAbsoluteEndpoints(corners[3], corners[0]);

            mLines[4].SetFromAbsoluteEndpoints(corners[4], corners[5]);
            mLines[5].SetFromAbsoluteEndpoints(corners[5], corners[6]);
            mLines[6].SetFromAbsoluteEndpoints(corners[6], corners[7]);
            mLines[7].SetFromAbsoluteEndpoints(corners[7], corners[4]);

            mLines[8].SetFromAbsoluteEndpoints(corners[0], corners[4]);
            mLines[9].SetFromAbsoluteEndpoints(corners[1], corners[5]);
            mLines[10].SetFromAbsoluteEndpoints(corners[2], corners[6]);
            mLines[11].SetFromAbsoluteEndpoints(corners[3], corners[7]);


            sourceBoundingFrustum.Near.ToString();
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:35,代码来源:Frustum.cs

示例6: DrawWireframe

        public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
			Matrix cameraView, Matrix cameraProjection,
			BoundingFrustum frustum, Color color)
        {
            // The points returned correspond to the corners of the BoundingFrustum faces that are
            // perpendicular to the z-axis. The near face is the face with the larger z value, and
            // the far face is the face with the smaller z value. Points 0 to 3 correspond to the
            // near face in a clockwise order starting at its upper-left corner when looking toward
            // the origin from the positive z direction. Points 4 to 7 correspond to the far face
            // in a clockwise order starting at its upper-left corner when looking toward the
            // origin from the positive z direction.
            frustum.GetCorners(Corners);

            FrustumVertices[6].Position = Corners[0];
            FrustumVertices[7].Position = Corners[1];
            FrustumVertices[5].Position = Corners[2];
            FrustumVertices[4].Position = Corners[3];
            FrustumVertices[2].Position = Corners[4];
            FrustumVertices[3].Position = Corners[5];
            FrustumVertices[1].Position = Corners[6];
            FrustumVertices[0].Position = Corners[7];

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection, color, null,
                PrimitiveType.LineList, FrustumVertices, WireFrustumIndices, false);
        }
开发者ID:tgjones,项目名称:osiris,代码行数:25,代码来源:Frustum.cs

示例7: Draw

        /// <summary>
        /// Draw a bounding frustrum representation
        /// </summary>
        /// <param name="frustum">Frustrum</param>
        /// <param name="camera">Camera</param>
        /// <param name="color">Color</param>
        public static void Draw(BoundingFrustum frustum, BaseCamera camera, Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(YnG.GraphicsDevice);
                effect.VertexColorEnabled = true;
                effect.LightingEnabled = false;
            }

            Vector3[] corners = frustum.GetCorners();
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = corners[i];
                vertices[i].Color = color;
            }

            effect.View = camera.View;
            effect.Projection = camera.Projection;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                YnG.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertices, 0, 8, indices, 0, indices.Length / 2);
            }
        }
开发者ID:shaoleibo,项目名称:YnaEngine,代码行数:31,代码来源:BoundingFrustrumRenderer.cs

示例8: Main

        public Main()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.SynchronizeWithVerticalRetrace = false;
            graphics.ApplyChanges();

            resolution = Settings.Default.WindowResolution;

            graphics.PreferredBackBufferWidth = resolution.X;
            graphics.PreferredBackBufferHeight = resolution.Y;

            Content.RootDirectory = "Content";

            camera = new FreeLookCamera(this);
            cameraHandler = new CameraHandler(this);
            fps = new FPS(this);
            hud = new HUD(this);

            Components.Add(camera);
            Components.Add(cameraHandler);
            Components.Add(fps);
            Components.Add(hud);

            Services.AddService(typeof(ICamera), camera);

            fakeViewFrustum = new BoundingFrustum(Matrix.Identity);
        }
开发者ID:sp-alex-osou,项目名称:TerrainLOD,代码行数:28,代码来源:Main.cs

示例9: FirstPersonCamera

 public FirstPersonCamera(Game game)
     : base(game)
 {
     
     Position = new Vector3(0, 0, 1);
     _viewFrustum = new BoundingFrustum(Matrix.Identity);
 }
开发者ID:andrewmyhre,项目名称:Tad.Xna.Common,代码行数:7,代码来源:FirstPersonCamera.cs

示例10: Draw

        public override void Draw(BoundingFrustum VisibleArea, Vector3 Position)
        {
            Manager.ResetFor2D();
            MyGame.graphics.GraphicsDevice.RenderState.CullMode = CullMode.None;
            Manager.TexturedEffect.CurrentTechnique = Manager.TexturedEffect.Techniques["TexturedCloud"];
            Manager.TexturedEffect.Parameters["InputTexture"].SetValue(NoiseMap);
            Manager.TexturedEffect.Parameters["ColorMapTexture"].SetValue(ColorMap);
            for (int i = 1; i < 2; i++)
            {
                Matrix transform = Transforms.Rotation
                        * Matrix.CreateScale(Transforms.Scale * 0.75f * i / 3)
                        * Matrix.CreateTranslation(Transforms.Position + Position);
                effect.Parameters["World"].SetValue(transform);
                Manager.TexturedEffect.Parameters["TextureAlphaThreshold"].SetValue(0.33f + 0.27f * i / 3);
                MyGame.graphics.GraphicsDevice.VertexDeclaration = DefaultDeclaration;

                effect.Begin();
                effect.CurrentTechnique.Passes.First<EffectPass>().Begin();
                MyGame.graphics.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionTexture>(
                    PrimitiveType.TriangleList
                    , ModelVertices
                    , 0
                    , ModelVertices.Length
                    , ModelIndices
                    , 0
                    , ModelIndices.Length / 3);
                effect.CurrentTechnique.Passes.First<EffectPass>().End();
                effect.End();
            }
            Manager.TexturedEffect.Parameters["TextureAlphaThreshold"].SetValue(0.33f);
            base.Draw(VisibleArea, Position);
            MyGame.graphics.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
        }
开发者ID:kaysoky,项目名称:AstronomicalSimulator,代码行数:33,代码来源:Nebula.cs

示例11: Draw

 public void Draw(DoubleVector3 cameraLocation, BoundingFrustum originBasedViewFrustum, Matrix originBasedViewMatrix, Matrix projectionMatrix)
 {
     foreach (var face in _faces)
     {
         face.Draw(cameraLocation, originBasedViewFrustum, originBasedViewMatrix, projectionMatrix);
     }
 }
开发者ID:GunioRobot,项目名称:GenesisEngine,代码行数:7,代码来源:Terrain.cs

示例12: Draw

        public void Draw(GameTime gameTime, BoundingFrustum VisibleArea)
        {
            if (units.Count > 0)
            {
                VertexPositionColor[] display = new VertexPositionColor[units.Count * 2];
                int[] pointIndex = new int[units.Count];
                for (int i = 0; i < units.Count; i++)
                {
                    display[i * 2] = new VertexPositionColor(units[i].Position, DisplayColor);
                    pointIndex[i] = i * 2;
                    if (units[i].Target != null)
                    {
                        display[i * 2 + 1] = new VertexPositionColor(units[i].Target.Position, DisplayColor);
                    }
                    else
                    {
                        display[i * 2 + 1] = display[i * 2];
                    }
                }

                Manager.ResetFor3D();
                MyGame.graphics.GraphicsDevice.VertexDeclaration = UnitDeclaration;
                MyGame.graphics.GraphicsDevice.RenderState.PointSize = 5.0f;
                Manager.OrdinaryEffect.CurrentTechnique = Manager.OrdinaryEffect.Techniques["Ordinary"];
                Manager.OrdinaryEffect.Parameters["World"].SetValue(Matrix.Identity);
                Manager.OrdinaryEffect.Begin();
                Manager.OrdinaryEffect.CurrentTechnique.Passes.First<EffectPass>().Begin();
                MyGame.graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, display, 0, display.Length / 2);
                MyGame.graphics.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.PointList, display, 0, display.Length
                    , pointIndex, 0, pointIndex.Length);
                Manager.OrdinaryEffect.CurrentTechnique.Passes.First<EffectPass>().End();
                Manager.OrdinaryEffect.End();
            }
        }
开发者ID:kaysoky,项目名称:RealTimeStrategyEngine,代码行数:34,代码来源:Controller.cs

示例13: Project

        /// <summary>
        /// Project a point into 2D space
        /// </summary>
        public static Vector2 Project(BoundingFrustum VisibleArea, Vector3 Point)
        {
            //Acquires the frustum of the area of the screen in view.
            //Then it stores the corners of the area.
            Vector3[] corners = VisibleArea.GetCorners();
            Ray ray = new Ray(Point, Point - Manager.CameraFocus - Manager.CameraLocation);

            float? DistanceToFar = ray.Intersects(VisibleArea.Far);
            float? DistanceToNear = ray.Intersects(VisibleArea.Near);
            Vector3 ScreenCoord;
            if (DistanceToFar.HasValue)
            {
                ScreenCoord = ray.Position + ray.Direction * DistanceToFar.Value;
                ScreenCoord = new Vector3(
                    Vector3.Dot(
                        Vector3.Normalize(corners[5] - corners[4])
                        , ScreenCoord - corners[4])
                    / (corners[5] - corners[4]).Length()
                    , Vector3.Dot(
                        Vector3.Normalize(corners[7] - corners[4])
                        , ScreenCoord - corners[4])
                    / (corners[7] - corners[4]).Length()
                    , 0);
            }
            else
            {
                //Make sure this is off the screen
                return Vector2.One * (Manager.GameWindow.Width + Manager.GameWindow.Height);
            }
            return new Vector2(ScreenCoord.X * Manager.GameWindow.Width, ScreenCoord.Y * Manager.GameWindow.Height);
        }
开发者ID:kaysoky,项目名称:AstronomicalSimulator,代码行数:34,代码来源:Cursor.cs

示例14: Unproject

        /// <summary>
        /// Unproject a screen coordinate into a ray
        /// </summary>
        public static Ray Unproject(Vector2 Point)
        {
            //Acquires the frustum of the area of the screen in view
            //Then it stores the corners of the area
            BoundingFrustum VisibleArea = new BoundingFrustum(Manager.View * Manager.Projection);
            Vector3[] corners = VisibleArea.GetCorners();
            Vector3 Position = new Vector3(Point, 0.0f);
            Ray ray = new Ray();

            //Point on the near plane of the visible area
            ray.Position =
                corners[0] * (1 - Position.X) * (1 - Position.Y)
                + corners[1] * Position.X * (1 - Position.Y)
                + corners[2] * Position.X * Position.Y
                + corners[3] * (1 - Position.X) * Position.Y;
            Position =
                corners[4] * (1 - Position.X) * (1 - Position.Y)
                + corners[5] * Position.X * (1 - Position.Y)
                + corners[6] * Position.X * Position.Y
                + corners[7] * (1 - Position.X) * Position.Y;
            //Direction between the two points
            ray.Direction = Vector3.Normalize(Position - ray.Position);

            return ray;
        }
开发者ID:kaysoky,项目名称:AstronomicalSimulator,代码行数:28,代码来源:Cursor.cs

示例15: SingleScreenSpaceShadow

 public SingleScreenSpaceShadow(IRenderContext context)
     : base(context)
 {
     lspsmLightCamera = new LspsmLightCamera();
     lightCameraFrustum = new BoundingFrustum(Matrix.Identity);
     shadowCasters = new List<Actor>();
 }
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:7,代码来源:SingleScreenSpaceShadow.cs


注:本文中的BoundingFrustum类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。