public TriangleRaytraceRenderer(GraphicsDeviceManager graphicsDeviceManager, WorldGrid grid, int width, int height, ISkyMap skyMap)
        {
            _grid                  = grid;
            _skyMap                = skyMap;
            _basicEffect           = new BasicEffect(graphicsDeviceManager.GraphicsDevice);
            _graphicsDeviceManager = graphicsDeviceManager;
            _graphicsDeviceManager.PreferredBackBufferHeight = height;
            _graphicsDeviceManager.PreferredBackBufferWidth  = width;
#if DEBUG
            _graphicsDeviceManager.IsFullScreen = false;
#else
            _graphicsDeviceManager.IsFullScreen = true;
#endif
            _graphicsDeviceManager.ApplyChanges();
            _graphicsDeviceManager.GraphicsDevice.Textures[0] = null;

            Vector2 center;
            center.X = _graphicsDeviceManager.GraphicsDevice.Viewport.Width * 0.5f;
            center.Y = _graphicsDeviceManager.GraphicsDevice.Viewport.Height * 0.5f;
            _minPos  = -center;
            _maxPos  = center;

            //This will create the triangles used for drawing the screen
            TriangleProjectionGrid projGrid = new TriangleProjectionGrid(_minPos.X, _minPos.Y, _maxPos.X, _maxPos.Y);

            projGrid.CreateGrid();

            _vertices = projGrid.GetTriangleIndex().GetVerticesPositionColor();
            ////test of moving polygon net
            //_orgVertices = new Vector2[_vertices.Length];
            //for (int i = 0; i < _vertices.Length; i++)
            //    _orgVertices[i] = new Vector2(_vertices[i].Position.X, _vertices[i].Position.Y);

            _vertexBuffer = new VertexBuffer(_graphicsDeviceManager.GraphicsDevice, typeof(VertexPositionColor), _vertices.Length, BufferUsage.WriteOnly);
            _vertexBuffer.SetData <VertexPositionColor>(_vertices);

            _indices     = projGrid.GetTriangleIndex().GetIndices();
            _indexBuffer = new IndexBuffer(_graphicsDeviceManager.GraphicsDevice, typeof(int), _indices.Length, BufferUsage.WriteOnly);
            _indexBuffer.SetData(_indices);

            _basicEffect.View               = Matrix.CreateLookAt(new Vector3(0, 0, -1), new Vector3(0, 0, 0), Vector3.Up);
            _basicEffect.Projection         = Matrix.CreateOrthographic(center.X * 2, center.Y * 2, 1, 2);
            _basicEffect.VertexColorEnabled = true;

            RasterizerState rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            _graphicsDeviceManager.GraphicsDevice.RasterizerState = rasterizerState;

            _graphicsDeviceManager.GraphicsDevice.Indices = _indexBuffer;//Same every time, only call once! (but it's not possible when 2Dtextures are drawn too)
        }
Пример #2
0
        public GameLoop() : base()
        {
            _graphicsDeviceManager = new GraphicsDeviceManager(this);
            _theEntireWorld        = new WorldGrid();

            //make it full screen... (borderless if you want to is an option as well)

#if DEBUG
            _graphicsDeviceManager.IsFullScreen = false;
            this.Window.Position     = new Point(0, 0);
            this.Window.IsBorderless = false;
#else
            _graphicsDeviceManager.IsFullScreen = true;
            this.Window.Position     = new Point(0, 0);
            this.Window.IsBorderless = true;
            #endif

            Content.RootDirectory = "Content";

            IsFixedTimeStep = false; // Setting this to true makes it fixed time step, false is variable time step.
        }