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


C# DrawState.PushProjection方法代码示例

本文整理汇总了C#中DrawState.PushProjection方法的典型用法代码示例。如果您正苦于以下问题:C# DrawState.PushProjection方法的具体用法?C# DrawState.PushProjection怎么用?C# DrawState.PushProjection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DrawState的用法示例。


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

示例1: Draw

        private void Draw(DrawState state)
        {
            state.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, new Color(0.2f, 0.2f, 0.5f, 1.0f), 1.0f, 0);
            state.PushProjection(_camera.Projection);

            _shader.Bind(state);

            const int TileSize = 44;
            const int TileSizeOver2 = TileSize / 2;
            const int TileStepX = 22;
            const int TileStepY = 22;

            const int MaxTileDistance = 10;
            const int MaxTileDistanceTime2 = MaxTileDistance * 2;

            PresentationParameters pp = state.PresentationParameters;

            Vector2 cameraOffset = new Vector2(0.5f, 0.5f);
            Vector2 cameraPosition = state.Camera.Position + cameraOffset;
            Vector2 viewSize = new Vector2(pp.BackBufferWidth, pp.BackBufferHeight);
            Vector2 tileCounts = new Vector2(viewSize.X / 22, viewSize.Y / 22);

            tileCounts.X = Math.Min(tileCounts.X, MaxTileDistanceTime2);
            tileCounts.Y = Math.Min(tileCounts.Y, MaxTileDistanceTime2);

            int startX = (int)(cameraPosition.X - tileCounts.X);
            int startY = (int)(cameraPosition.Y - tileCounts.Y);
            int endX = (int)(cameraPosition.X + tileCounts.X);
            int endY = (int)(cameraPosition.Y + tileCounts.Y);

            Vector2 offset, northVector, eastVector, westVector, southVector, center;
            int tileZ, eastTileZ, southTileZ, downTileZ;

            for (int y = startY; y < endY; y++)
            {
                offset.X = ((-tileCounts.X / 4) + (startY - y)) * TileStepY;
                offset.Y = ((tileCounts.Y * 2) + (startY - y)) * TileStepY;

                BoundingBox bb;

                for (int x = startX; x < endX; x++)
                {
                    Tile tile = _maps.Felucca.Tiles.GetLandTile(x, y);
                    Tile tileEast = _maps.Felucca.Tiles.GetLandTile(x - 1, y);
                    Tile tileSouth = _maps.Felucca.Tiles.GetLandTile(x, y + 1);
                    Tile tileDown = _maps.Felucca.Tiles.GetLandTile(x - 1, y + 1);

                    offset.X += TileStepX;
                    offset.Y -= TileStepY;

                    tileZ = tile._z * 4;
                    eastTileZ = tileEast._z * 4;
                    southTileZ = tileSouth._z * 4;
                    downTileZ = tileDown._z * 4;

                    center.X = offset.X;
                    center.Y = offset.Y;

                    northVector.X = center.X;
                    northVector.Y = center.Y - TileSizeOver2 - tileZ;

                    eastVector.X = center.X + TileSizeOver2;
                    eastVector.Y = center.Y - eastTileZ;

                    westVector.X = center.X - TileSizeOver2;
                    westVector.Y = center.Y - southTileZ;

                    southVector.X = center.X;
                    southVector.Y = center.Y + TileSizeOver2 - downTileZ;

                    bb.Min = new Vector3(westVector.X, northVector.Y, 0);
                    bb.Max = new Vector3(eastVector.X, southVector.Y, 0);

                    if (_camera.BoundingFrustum.Intersects(bb))
                        _renderer.QueueQuad(state, ref northVector, ref eastVector, ref westVector, ref southVector, _textureFactory.CreateLand(tile._id));
                }
            }

            _renderer.Flush(state);

            state.PopProjection();
        }
开发者ID:bugraerdogan,项目名称:silverlight-uo-client,代码行数:82,代码来源:Engine.cs


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