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
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //_guiFont = Content.Load<SpriteFont>("guiFont");

            // Create a new SpriteBatch, which can be used to draw textures.
            // _spriteBatch = new SpriteBatch(GraphicsDevice);

            _basicEffect = new BasicEffect(GraphicsDevice);

            _center.X = GraphicsDevice.Viewport.Width * 0.5f;
            _center.Y = GraphicsDevice.Viewport.Height * 0.5f;

            //This will create the triangles used for drawing the screen
            TriangleProjectionGrid projGrid = new TriangleProjectionGrid(-_center.X, -_center.Y, _center.X, _center.Y, 3, 2);

            //TODO: Check if multiples ar valid
            //TODO: The TriangleHexagonRings should be dynamic to the resolution
            for (int i = 0; i < 900; i += 3)
            {
                projGrid.MakeTriangleHexagonRing(i, 3);
            }

            //for (int i = 40; i < 180; i += 2)
            //    projGrid.MakeTriangleHexagonRing(i, 2);

            //for (int i = 180; i < 120; i += 4)
            //    projGrid.MakeTriangleHexagonRing(i, 4);

            //for (int i = 120; i < 180; i += 6)
            //    projGrid.MakeTriangleHexagonRing(i, 6);

            //for (int i = 180; i < 260; i += 8)
            //    projGrid.MakeTriangleHexagonRing(i, 8);

            _vertices = projGrid.GetTriangleIndex().GetVerticesPositionColor();
            //test av hur det kan se ut
            _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(GraphicsDevice, typeof(VertexPositionColor), _vertices.Length, BufferUsage.WriteOnly);
            _vertexBuffer.SetData <VertexPositionColor>(_vertices);


            _indices     = projGrid.GetTriangleIndex().GetIndices();
            _indexBuffer = new IndexBuffer(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.Down);
            _basicEffect.Projection = Matrix.CreateOrthographic(_center.X * 2, _center.Y * 2, 1, 2);

            Mouse.SetPosition((int)_center.X, (int)_center.Y);

            _theEntireWorld.CreateFlatWorld(40, 40, 40);

            //Not sure if this is wise but a lot of objects were created for building the scene
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }