public void Draw(Soft3DScreen s) { foreach(Model3D m in list) { m.Draw(s); } }
//vykresli model public void Draw(Soft3DScreen s) { foreach(TexturedTriangle t in triangles) { if(t != null)//jestlize nema texturu vykresli bez textury { if(t.Texture != null) s.DrawTexturedTriangle3d(t); else { s.ActualColor = t.MyColor; s.DrawFilledTriangle3d(t.V1.Transform(matrix),t.V2.Transform(matrix), t.V3.Transform(matrix)); } } } }
void OnPaint(object sender, PaintEventArgs e) { //= new Bitmap(e.ClipRectangle.Width, e.ClipRectangle.Height, e.Graphics); //MyUnion union; if((e.ClipRectangle.Height != oldy) || (e.ClipRectangle.Width != oldx)) { pole = new Int32[e.ClipRectangle.Height,e.ClipRectangle.Width]; oldx = e.ClipRectangle.Width; oldy = e.ClipRectangle.Height; }else{} //byte[] bytes = new byte[b.Width*b.Height*4]; //Int32[,] pole = new Int32[b.Width,b.Height]; Soft3DScreen s = new Soft3DScreen(pole); //Triangle3D t3; s.ViewMatrix.Translate(0,0,-5); s.ViewMatrix.RotateX(rx); s.ViewMatrix.RotateY(ry); // Vector2 texcoord1 = new Vector2(-1,-1); // Vector2 texcoord2 = new Vector2(-1,1); // Vector2 texcoord3 = new Vector2(1,-1); Vector3 v1 = new Vector3(-1,-1,-1); Vector3 v2 = new Vector3(-1,1,-1); Vector3 v3 = new Vector3(1,-1,-1); /* t3 = new Triangle3D(v1,v2,v3); t2 = new Triangle2D(texcoord1,texcoord2,texcoord3); TexturedTriangle ttriangle = new TexturedTriangle(t3,t2,texture); s.DrawTexturedTriangle3d(ttriangle); texcoord1.Set(-1,1); texcoord2.Set(1,1); texcoord3.Set(1,-1); v1.Set(-1,1,-1); v2.Set(1,1,-1); v3.Set(1,-1,-1); t3 = new Triangle3D(v1,v2,v3); t2 = new Triangle2D(texcoord1,texcoord2,texcoord3); ttriangle = new TexturedTriangle(t3,t2,texture); s.DrawTexturedTriangle3d(ttriangle); */ s.ActualColor = Color.White.ToArgb(); v1.Set(-1,1,1); v2.Set(1,1,1); v3.Set(1,-1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); v1.Set(-1,1,1); v2.Set(-1,-1,1); v3.Set(1,-1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); s.ActualColor = Color.Green.ToArgb(); v1.Set(1,1,1); v2.Set(1,1,-1); v3.Set(1,-1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); v1.Set(1,-1,-1); v2.Set(1,1,-1); v3.Set(1,-1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); s.ActualColor = Color.Blue.ToArgb(); v1.Set(-1,1,1); v2.Set(-1,1,-1); v3.Set(-1,-1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3);; v1.Set(-1,-1,-1); v2.Set(-1,1,-1); v3.Set(-1,-1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); s.ActualColor = Color.Cyan.ToArgb(); v1.Set(1,1,1); v2.Set(1,1,-1); v3.Set(-1,1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); v1.Set(-1,1,-1); v2.Set(-1,1,1); v3.Set(1,1,-1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); s.ActualColor = Color.Orange.ToArgb(); v1.Set(1,-1,1); v2.Set(1,-1,-1); v3.Set(-1,-1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); v1.Set(-1,-1,-1); v2.Set(1,-1,-1); v3.Set(-1,-1,1); //t3 = new Triangle3D(v1,v2,v3); s.DrawFilledTriangle3d(v1,v2,v3); Bitmap b = ToBitmap(pole); e.Graphics.DrawImageUnscaled(b, 0, 0); //e.Graphics.DrawImageUnscaled(texture, 0, 0); }
void OnPaint(object sender, PaintEventArgs e) { // DateTime startTime = DateTime.Now; Int32[,] pole = new Int32[e.ClipRectangle.Height,e.ClipRectangle.Width]; Soft3DScreen s = new Soft3DScreen(pole);//vytvoreni sceny s.ViewMatrix.Translate(transx,transy,-10); s.ViewMatrix.RotateX(rx); s.ViewMatrix.RotateY(ry); s.ViewMatrix.Scale(scale); if(l != null)//jestlize je nactena scena, kresli l.Draw(s); Bitmap b = Soft3DBitmap.ToBitmap(pole); e.Graphics.DrawImageUnscaled(b, 0, 0); // DateTime stopTime = DateTime.Now; // TimeSpan duration = stopTime - startTime; //Console.WriteLine("seconds:" + duration.Seconds); //Console.WriteLine("milliseconds:" + duration.Milliseconds); }