private static void desenha(Object3D obj, Face f, BitmapData bdma) { int x1, x2, y1, y2; for (int i = 0; i < f.getVertexs().Count - 1; i++) { x1 = (int)(330 + obj.getActuals()[f.getVertexs()[i]].getX()); y1 = (int)(250 + obj.getActuals()[f.getVertexs()[i]].getY()); x2 = (int)(330 + obj.getActuals()[f.getVertexs()[i + 1]].getX()); y2 = (int)(250 + obj.getActuals()[f.getVertexs()[i + 1]].getY()); GraphicPrimitives.bresenham(bdma, x1, y1, x2, y2); } x1 = (int)(330 + obj.getActuals()[f.getVertexs()[f.getVertexs().Count - 1]].getX()); y1 = (int)(250 + obj.getActuals()[f.getVertexs()[f.getVertexs().Count - 1]].getY()); x2 = (int)(330 + obj.getActuals()[f.getVertexs()[0]].getX()); y2 = (int)(250 + obj.getActuals()[f.getVertexs()[0]].getY()); GraphicPrimitives.bresenham(bdma, x1, y1, x2, y2); }
public static Object3D readObj(StreamReader sr) { Object3D obj = new Object3D(); String[] s, s1; Face f; String line = sr.ReadLine(); while (line != null) { s = line.Split(' '); //add vertex if (s[0].Equals("v")) { obj.addOriginals(new Vertex(Convert.ToDouble(s[1].Replace(".", ",")), Convert.ToDouble(s[2].Replace(".", ",")), Convert.ToDouble(s[3].Replace(".", ",")))); } //add face else if (s[0].Equals("f")) { f = new Face(); if (s[s.Length - 1] == "") { Array.Resize(ref s, 3); } for (int i = 1; i < s.Length; i++) { s1 = s[i].Split('/'); f.addVertex(Convert.ToInt32(s1[0]) - 1); } obj.addFaces(f); } //add texture //else if () line = sr.ReadLine(); } obj.setActuals(obj.getOriginals()); obj.setNFaces(); return(obj); }
public static Bitmap drawObjectWire(Object3D obj, Bitmap b, bool face) { BitmapData bdma = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); foreach (Face f in obj.getFaces()) { if (!face) { if (f.getNormal().getZ() > 0) { desenha(obj, f, bdma); } } else { desenha(obj, f, bdma); } } b.UnlockBits(bdma); return(b); }