Example #1
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            VertexPositionTexture[] billboardVertices = new VertexPositionTexture[positions.Count * 6];
            int i = 0;

            foreach (var position in positions)
            {
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1));

                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 1));
            }


            VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly);

            vertexBufferS.SetData(billboardVertices);
            int noVertices  = billboardVertices.Count();
            int noTriangles = noVertices / 3;

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, 0, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.NORMAL);
            b[0].VertexBuffer    = vertexBufferS;
            b[0].IndexBuffer     = null;
            BatchInformations[0] = b;

            TextureInformations       = new TextureInformation[1][];
            TextureInformations[0]    = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
Example #2
0
        public void SetUpWaterVertices(GraphicsDevice device)
        {
            VertexPositionTexture[] waterVertices = new VertexPositionTexture[6];
            float WH = WaterHeight - 0.2f;

            waterVertices[0] = new VertexPositionTexture(new Vector3(BlockSize * -10, WH, BlockSize * -10), new Vector2(0, 0)); //10
            waterVertices[1] = new VertexPositionTexture(new Vector3(BlockSize * 10, WH, BlockSize * 10), new Vector2(1, 1));   //01
            waterVertices[2] = new VertexPositionTexture(new Vector3(BlockSize * -10, WH, BlockSize * 10), new Vector2(0, 1));  //00

            waterVertices[3] = new VertexPositionTexture(new Vector3(BlockSize * -10, WH, BlockSize * -10), new Vector2(0, 0)); //01
            waterVertices[4] = new VertexPositionTexture(new Vector3(BlockSize * 10, WH, BlockSize * -10), new Vector2(1, 0));  //11
            waterVertices[5] = new VertexPositionTexture(new Vector3(BlockSize * 10, WH, BlockSize * 10), new Vector2(1, 1));   //01

            //waterVertexBuffer = new VertexBuffer(device, waterVertices.Length * VertexPositionTexture.SizeInBytes, BufferUsage.WriteOnly);
            VertexDeclaration vertexDeclaration = VertexPositionTexture.VertexDeclaration;

            _water = new VertexBuffer(device, vertexDeclaration, waterVertices.Count(), BufferUsage.WriteOnly);
            _water.SetData(waterVertices);
        }
Example #3
0
        private void SetUpWaterVertices()
        {
            VertexPositionTexture[] waterVertices = new VertexPositionTexture[6];

            waterVertices[0] = new VertexPositionTexture(new Vector3(0, waterHeight, 0), new Vector2(0, 1));
            waterVertices[2] = new VertexPositionTexture(new Vector3(terrain.getWidthUnits(), waterHeight, -terrain.getHeightUnits()), new Vector2(1, 0));
            waterVertices[1] = new VertexPositionTexture(new Vector3(0, waterHeight, -terrain.getHeightUnits()), new Vector2(0, 0));

            waterVertices[3] = new VertexPositionTexture(new Vector3(0, waterHeight, 0), new Vector2(0, 1));
            waterVertices[5] = new VertexPositionTexture(new Vector3(terrain.getWidthUnits(), waterHeight, 0), new Vector2(1, 1));
            waterVertices[4] = new VertexPositionTexture(new Vector3(terrain.getWidthUnits(), waterHeight, -terrain.getHeightUnits()), new Vector2(1, 0));


            //   VertexDeclaration vertexDeclaration = new VertexDeclaration(VertexMultitextured.VertexElements);
            waterVertexBuffer = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, waterVertices.Count(), BufferUsage.WriteOnly);
            waterVertexBuffer.SetData(waterVertices);
        }
Example #4
0
        /// <summary>
        /// Loads the model.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="BatchInformations">The batch informations.</param>
        /// <param name="TextureInformations">The texture informations.</param>
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            VertexPositionTexture[] billboardVertices = new VertexPositionTexture[4];
            int i = 0;

            billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0));
            billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 0));
            billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 1));
            billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1));

            VertexElement v0 = new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 1);
            VertexElement v1 = new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 2);

            vd = new VertexDeclaration(v0, v1);

            VertexBuffer InstancedvertexBufferS;

            if (dynamicBufferSize != -1)
            {
                InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, dynamicBufferSize, BufferUsage.WriteOnly);
            }
            else
            {
                InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, instances.Count(), BufferUsage.WriteOnly);
            }

            InstancedvertexBufferS.SetData(instances);

            VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly);

            vertexBufferS.SetData(billboardVertices);

            short[] indices = new short[] { 0, 2, 1, 1, 2, 3 };

            IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly);

            indexBufferS.SetData <short>(indices);

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, 4, 2, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, instances.Count());
            b[0].VertexBuffer          = vertexBufferS;
            b[0].IndexBuffer           = indexBufferS;
            b[0].InstancedVertexBuffer = InstancedvertexBufferS;
            BatchInformations[0]       = b;

            TextureInformations       = new TextureInformation[1][];
            TextureInformations[0]    = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
Example #5
0
        public void SetUpWaterVertices(Game1 game, Terrain terrain)
        {
            VertexPositionTexture[] waterVertices = new VertexPositionTexture[6];

            waterVertices[0] = new VertexPositionTexture(new Vector3(0, waterHeight, 0), new Vector2(0, 1));
            waterVertices[2] = new VertexPositionTexture(new Vector3(terrain.terrainWidth * 4, waterHeight, -terrain.terrainLength * 4), new Vector2(1, 0));
            waterVertices[1] = new VertexPositionTexture(new Vector3(0, waterHeight, -terrain.terrainLength * 4), new Vector2(0, 0));

            waterVertices[3] = new VertexPositionTexture(new Vector3(0, waterHeight, 0), new Vector2(0, 1));
            waterVertices[5] = new VertexPositionTexture(new Vector3(terrain.terrainWidth * 4, waterHeight, 0), new Vector2(1, 1));
            waterVertices[4] = new VertexPositionTexture(new Vector3(terrain.terrainWidth * 4, waterHeight, -terrain.terrainLength * 4), new Vector2(1, 0));

            waterVertexBuffer = new VertexBuffer(game.GraphicsDevice, VertexPositionTexture.VertexDeclaration, waterVertices.Count(), BufferUsage.WriteOnly);
            waterVertexBuffer.SetData(waterVertices);
        }