void CreateVertexBuffer() { if (Root.Instance.UserInterface == null) { return; } VertexP3C4T2[] data = new VertexP3C4T2[] { new VertexP3C4T2(1, 0, -1, 1, 1, 1, 1, 1, 0), new VertexP3C4T2(-1, 0, -1, 1, 1, 1, 1, 0, 0), new VertexP3C4T2(-1, 0, 1, 1, 1, 1, 1, 0, 1), new VertexP3C4T2(1, 0, 1, 1, 1, 1, 1, 1, 1) }; Vertices = Root.Instance.UserInterface.Renderer.CreateStaticVertexBuffer(data, (3 + 4 + 2) * 4 * 4); Vertices.Format = VertexFormat.VF_P3C4T2; }
void CreateVertexBuffer() { if (Root.Instance.UserInterface==null) return; VertexP3C4T2[] data = new VertexP3C4T2[]{ new VertexP3C4T2(1,0,-1, 1,1,1,1, 1,0), new VertexP3C4T2(-1,0,-1, 1,1,1,1, 0,0), new VertexP3C4T2(-1,0,1, 1,1,1,1, 0,1), new VertexP3C4T2(1,0,1, 1,1,1,1, 1,1) }; Vertices = Root.Instance.UserInterface.Renderer.CreateStaticVertexBuffer(data, (3 + 4 + 2) * 4 * 4); Vertices.Format = VertexFormat.VF_P3C4T2; }
public void Generate() { int c = Master.PatchSize; int i; //Index[0]=GenerateIndex(1); int step = 1; for (i = 0; i < ib.Length; ++i) { ib[i] = new IndexBuffer(); ib[i].buffer = GenerateIndex(step); step *= 2; } //byte[] vertices=new byte[c*c*4*(3+4+2)]; vertices = new VertexP3C4T2[c * c]; //MemoryStream ms=new MemoryStream(vertices); //BinaryWriter bw=new BinaryWriter(ms); float s = Master.PatchScale; i = 0; for (int y = 0; y < c; ++y) { for (int x = 0; x < c; ++x) { float px = (float)PatchGridPosition.X * s + ((float)x / (float)(c - 1)) * s; float py = (float)PatchGridPosition.Y * s + ((float)y / (float)(c - 1)) * s; px -= s * Master.PatchCount / 2; py -= s * Master.PatchCount / 2; float h = ((float)Master.Height.GetHeight( PatchGridPosition.X * (Master.PatchSize - 1) + x, PatchGridPosition.Y * (Master.PatchSize - 1) + y) / 255) * Master.HeightScale; /*bw.Write(px);bw.Write(h);bw.Write(py); * bw.Write(1.0f);bw.Write(1.0f);bw.Write(1.0f);bw.Write(1.0f); * bw.Write((float)(PatchGridPosition.X*(Master.PatchSize-1)+x)/(float)(Master.PatchCount*(Master.PatchSize-1))); * bw.Write((float)(PatchGridPosition.Y*(Master.PatchSize-1)+y)/(float)(Master.PatchCount*(Master.PatchSize-1))); * */ vertices[i].position.X = px; vertices[i].position.Y = h; vertices[i].position.Z = py; vertices[i].color.r = vertices[i].color.g = vertices[i].color.b = vertices[i].color.a = 1.0f; vertices[i].texture0.X = (float)(PatchGridPosition.X * (Master.PatchSize - 1) + x) / (float)(Master.PatchCount * (Master.PatchSize - 1)); vertices[i].texture0.Y = (float)(PatchGridPosition.Y * (Master.PatchSize - 1) + y) / (float)(Master.PatchCount * (Master.PatchSize - 1)); i++; } } if (Root.Instance.UserInterface != null) { IRenderer r = Root.Instance.UserInterface.Renderer; vb = r.CreateStaticVertexBuffer(vertices, vertices.Length * (3 + 4 + 2) * 4); /*VertexFormat format=new VertexFormat(new VertexFormat.Element[]{ * new VertexFormat.Element(VertexFormat.ElementName.Position,3), * new VertexFormat.Element(VertexFormat.ElementName.Color,4), * new VertexFormat.Element(VertexFormat.ElementName.Texture0,2) * });*/ vb.Format = VertexFormat.VF_P3C4T2; } }