void ApplyHeightMap() { //Random r = new Random(123); int i = 0; double d = z_res / (z_res + 1); for (int y = 0; y < z_res; y++) { //for (int x = -x_res / 2; x < x_res / 2; x++) for (int x = 0; x < x_res; x++) { int pos = y * x_res + x; float height = HeightColorToHeight(x, y); Vector3d normal = MassiveTools.Vector3dFromVector3(Vertices[i]._position) + transform.Position - CurrentBody.Position; normal.Normalize(); Vertices[i]._position += MassiveTools.Vector3FromVector3d(normal) * height; Vertices[i]._normal = MassiveTools.Vector3FromVector3d(normal); heights[x, y] = height; ///Vertices[i]._position.Y = HeightColorToHeight(x, y); i++; } } }
//TODO: Make work public void Render(Matrix4d viewproj, Matrix4d parentmodel) { Vector3[] positionArray = new Vector3[lines.Count]; Vector4[] colorArray = new Vector4[lines.Count]; int i; //Random r = new Random(); if (lines.Count() == 0) { return; } for (i = 0; i < lines.Count; i++) { positionArray[i] = MassiveTools.Vector3FromVector3d(lines[i].Position - Globals.GlobalOffset); colorArray[i] = lines[i].Color; } lines.Clear(); vertexCount = positionArray.Length; //GL.ClearColor(new Color4(0, 0, 0, 0.5f)); //GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Matrix4 mvp = MTransform.GetFloatMatrix(viewproj); Matrix4 model = MTransform.GetFloatMatrix(parentmodel); GL.UseProgram(shaderProgram); int loc = GL.GetUniformLocation(shaderProgram, "mvp"); GL.UniformMatrix4(loc, false, ref mvp); loc = GL.GetUniformLocation(shaderProgram, "model"); GL.UniformMatrix4(loc, false, ref model); lineVertexBuffer = GL.GenBuffer(); if (Globals.Avatar.Target == null) { return; } Vector3 tp = MassiveTools.Vector3FromVector3d(Globals.Avatar.Target.transform.Position); //Vector3[] lineVertices = { new Vector3(0, 0, 0), new Vector3((float)r.NextDouble(), .5f, 0.5f) - MassiveTools.FromV3d(Globals.GlobalOffset)}; //vertexCount = lineVertices.Length; GL.BindBuffer(BufferTarget.ArrayBuffer, lineVertexBuffer); GL.BufferData(BufferTarget.ArrayBuffer, System.Runtime.InteropServices.Marshal.SizeOf(positionArray[0]) * vertexCount, positionArray, BufferUsageHint.StreamDraw); vertexInfo = GL.GenVertexArray(); GL.BindVertexArray(vertexInfo); int locVPosition = GL.GetAttribLocation(shaderProgram, "vPosition"); GL.EnableVertexAttribArray(locVPosition); GL.VertexAttribPointer(locVPosition, 3, VertexAttribPointerType.Float, false, System.Runtime.InteropServices.Marshal.SizeOf(positionArray[0]), 0); //GL.BindVertexArray(0); //GL.BindBuffer(BufferTarget.ArrayBuffer, 0); //GL.UseProgram(0); //GL.ClearColor(Color4.Black); GL.Clear(ClearBufferMask.DepthBufferBit); int loca = GL.GetUniformLocation(shaderProgram, "mcolor"); if (UserColorCoding == true) { for (int ri = 0; ri <= positionArray.Count() - 2; ri += 2) { Vector4 v = colorArray[ri]; GL.Uniform4(loca, ref v); GL.DrawArrays(PrimitiveType.LineStrip, ri, 2); } } else { Vector4 v = new Vector4(1, 1, 1, 0.9f); GL.Uniform4(loca, ref v); GL.DrawArrays(PrimitiveType.LineStrip, 0, positionArray.Count()); } //GL.DrawArrays(PrimitiveType.LineStrip, ri, vertexCount); GL.BindVertexArray(0); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.UseProgram(0); }