public DrawabeElement(VertexPositionNormal4Texture[] vpc, BiomeType gt) { this.vpc = vpc; effect = new BasicEffect(Tools.Quick.device); setEffect(gt); vb = new VertexBuffer(Tools.Quick.device, VertexPositionNormal4Texture.VertexDeclaration, vpc.Count(), BufferUsage.WriteOnly); vb.SetData(vpc); //effect.Parameters["xTexture"].SetValue(effect.Texture); }
public void makebigbuffer() { makeTextureMap(Game.GraphicsDevice); effect = Tools.Quick.content.Load<Effect>("Effects/MyEffect"); effect.Parameters["xWorldScale"].SetValue(new Vector2(Map.MAPSIZE, Map.MAPSIZE)); effect.Parameters["xTexturesMap"].SetValue(biomeTexture); effect.Parameters["xEnableLighting"].SetValue(true); Vector3 lightDirection = new Vector3(0.5f, -1f, 0); lightDirection.Normalize(); effect.Parameters["xLightDirection"].SetValue(lightDirection); effect.Parameters["xClipping"].SetValue(false); effect.Parameters["xTextureAtlas"].SetValue(Tools.Quick.biome3D); bigbuffer = new VertexPositionNormal4Texture[tiles.Count * 6]; //indexvertex = new int[tiles.Count * 6]; Color color = Color.AliceBlue; int i = 0; int j = 0; int num = 0; foreach (Tile t in tiles) { if (t.v1.Y <= waterlevel) { num++; } } //bigbufferWater = new VertexPositionNormal4Texture[num * 6]; VertexPositionNormal4Texture[] buffer = new VertexPositionNormal4Texture[(Map.MAPSIZE+1) * (Map.MAPSIZE+1)]; int[] iBuffer = new int[Map.MAPSIZE * Map.MAPSIZE * 6]; for (int n = 0; n <= Map.MAPSIZE; n++) { buffer[n] = new VertexPositionNormal4Texture( new Vector3(n, 0, 0), new Vector3(0, 1, 0), new Vector4(1,0,0,0), new Vector4((int)BiomeType.Water)); } for (int n = 0; n < tiles.Count; n++) { Tile t = tiles[n]; Vector3 normal = Vector3.Cross(t.v2 - t.v4, t.v1 - t.v4); normal.Normalize(); normal = Vector3.Multiply(normal, -1); int y = n / (Map.MAPSIZE); int x = n % (Map.MAPSIZE); if (x == 0) buffer[n + (Map.MAPSIZE) + y+1] = new VertexPositionNormal4Texture( new Vector3(0, 0, y + 1), new Vector3(0, 1, 0), new Vector4(1,0,0,0), new Vector4((int)BiomeType.Water)); buffer[n + Map.MAPSIZE + y + 2] = new VertexPositionNormal4Texture(new Vector3(x + 1, t.v1.Y, y + 1), t.n1, new Vector4(1,0,0,0), new Vector4((int)t.gp)); buffer[n + y].TextureType.Y = (int)t.gp; buffer[n + y].TextureWeight.Y = 1; buffer[n + y].TextureWeight.Normalize(); buffer[n + Map.MAPSIZE + y + 1].TextureType.Z = (int)t.gp; buffer[n + Map.MAPSIZE + y + 1].TextureWeight.Z = 1; buffer[n + Map.MAPSIZE + y + 1].TextureWeight.Normalize(); buffer[n + Map.MAPSIZE + y + 2].TextureType.W = (int)t.gp; buffer[n + Map.MAPSIZE + y + 2].TextureWeight.W = 1; buffer[n + Map.MAPSIZE + y + 2].TextureWeight.Normalize(); iBuffer[n * 6] = n + y; iBuffer[n * 6 + 1] = n + Map.MAPSIZE + y + 1; iBuffer[n * 6 + 2] = n + y + 1; iBuffer[n * 6 + 3] = n + y + 1; iBuffer[n * 6 + 4] = n + Map.MAPSIZE + y + 1; iBuffer[n * 6 + 5] = n + Map.MAPSIZE + y + 2; } GroundVertices = new VertexBuffer(Tools.Quick.device, VertexPositionNormal4Texture.VertexDeclaration, (Map.MAPSIZE + 1) * (Map.MAPSIZE + 1), BufferUsage.WriteOnly); GroundVertices.SetData(buffer); GroundIndices = new IndexBuffer(Tools.Quick.device, IndexElementSize.ThirtyTwoBits, (Map.MAPSIZE) * (Map.MAPSIZE) * 6, BufferUsage.WriteOnly); GroundIndices.SetData(iBuffer); // verifAppliTex(bigbufferWater); }
public void initDraw() { //elements.Add(new DrawabeElement(bigbufferWater, GroundType.Water)); if (bigbuffer.Count() > VAL_DECOUPAGE) { VertexPositionNormal4Texture[] intermediatebuffer; int i = 0; while (i < bigbuffer.Count()) { i += VAL_DECOUPAGE; if (i < bigbuffer.Count()) { intermediatebuffer = new VertexPositionNormal4Texture[VAL_DECOUPAGE]; Array.Copy(bigbuffer, i - VAL_DECOUPAGE, intermediatebuffer, 0, VAL_DECOUPAGE); } else { intermediatebuffer = new VertexPositionNormal4Texture[bigbuffer.Length - (i - VAL_DECOUPAGE)]; Array.Copy(bigbuffer, i - VAL_DECOUPAGE, intermediatebuffer, 0, bigbuffer.Length - (i - VAL_DECOUPAGE)); } elements.Add(new DrawabeElement(intermediatebuffer, BiomeType.SubtropicalDesert)); } } else { elements.Add(new DrawabeElement(bigbuffer, BiomeType.SubtropicalDesert)); } }