public VerletMesh(Mesh m) { Faces = m.Faces; VertexList = m.VertexList; Normals = m.Normals; init (); }
void DrawMesh(Mesh m) { // var c = 0; foreach (var f in m.Faces) { if(useLines) GL.Begin (BeginMode.Triangles); else GL.Begin (BeginMode.Points); // Console.Write (string.Format ("Face {0} [ ", c++)); for (var i =0; i<Face.N; i++) { var v = m.VertexList [f.posIndex [i]]; GL.Vertex3 (v.X, v.Y, v.Z); // Console.Write (string.Format (" ({0},{1},{2}) ",v.X,v.Y,v.Z)); } // Console.WriteLine(" ] "); GL.End (); } }
public static Mesh CreatePlane(float width, float height, int rows,int columns) { if (rows == columns && rows == 0) return null; var plane = new Mesh (); var dw = width / rows; var dh = height / columns; for (var r = 0; r<rows+1; r++) for (var c = 0; c<columns+1; c++) plane.VertexList.Add (new Vec3 (c*dw, r*dh , 0.0f)); for (var r = 0; r<rows; r++) for (var c = 0; c<columns; c++) { var v0 = r * (columns + 1) + c; var v1 = v0 + columns + 1; var v2 = v1 + 1; var v3 = v0 + 1; plane.VertexList.Add ( plane.VertexList [v0] * 0.25f + plane.VertexList [v1] * 0.25f + plane.VertexList [v2] * 0.25f + plane.VertexList [v3] * 0.25f ); var vc = plane.VertexList.Count - 1; plane.Faces.Add (new Face (v0, v1, vc)); plane.Faces.Add (new Face (v1, v2, vc)); plane.Faces.Add (new Face (v2, v3, vc)); plane.Faces.Add (new Face (v3, v0, vc)); } return plane; }
public static Mesh CreateSphere(float radius, float rings, float segments) { double s, t; var list = new List<Vec3> (); for(var i = 0; i < rings; i++){ for(var j = 0; j < segments; j++){ s = (float)i * 2 * Math.PI / rings; t = (float)j * 2 * Math.PI / segments; list.Add(new Vec3( (float)(radius * Math.Sin(s) * Math.Cos(t)), (float)(radius * Math.Sin(s) * Math.Sin(t)), (float)(radius * Math.Cos(s)) )); s = (double)(i + 1) * 2 * Math.PI / rings; list.Add( new Vec3( (float)(radius * Math.Sin(s) * Math.Cos(t)), (float)(radius * Math.Sin(s) * Math.Sin(t)), (float)(radius * Math.Cos(s)) )); } } var mesh = new Mesh (); mesh.VertexList = list; for(var i = 0; i<list.Count-2; i++) { mesh.Faces.Add (new Face (i, i + 1, i + 2)); } return mesh; }