コード例 #1
0
ファイル: Form1.cs プロジェクト: reduPKR/imagens_3d_c-
 public void Scanline()
 {
     Pontos[] pol = GerarPoligono();
     Reta.AlocarBitmap(ret);
     ScanLine.Scanline(Reta.getImgDta(), pol);
     Reta.DesalocarBitmap(ret);
     pictureBox.Image = ret;
     imgBmp           = ret;
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: reduPKR/imagens_3d_c-
        /*Controles*/
        private void BtnCarregar_Click(object sender, EventArgs e)
        {
            openFileDialog.FileName = "";
            openFileDialog.Filter   = "Arquivos obj (*.obj)|*.obj";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string arquivo = openFileDialog.FileName;

                if (File.Exists(arquivo))
                {
                    EstadoInicial();

                    int      i;
                    String   linha;
                    String[] cel = new String[10];
                    String[] aux = new String[3];
                    No       no  = null;
                    No       ini = null;

                    try
                    {
                        using (FileStream fs = new FileStream(arquivo, FileMode.Open))
                        {
                            StreamReader sr = new StreamReader(fs);
                            while ((linha = sr.ReadLine()) != null)
                            {
                                if (linha.Substring(1, 1) == " ")
                                {
                                    cel = linha.Split(' ');

                                    if (cel[0] == "v")
                                    {
                                        for (i = 1; i <= 3; i++)
                                        {
                                            cel[i] = cel[i].Replace('.', ',');
                                        }

                                        lVertOriginais.Add(new Pontos(cel[1], cel[2], cel[3]));
                                        lVertAtual.Add(new Pontos(cel[1], cel[2], cel[3]));
                                    }
                                    else
                                    if (cel[0] == "f")
                                    {
                                        for (i = 1; i < cel.Length && !cel[i].Equals(" "); i++)
                                        {
                                            aux = cel[i].Split('/');

                                            if (ini == null)//-1 pra comecar de 0
                                            {
                                                no = ini = new No(Convert.ToInt32(aux[0]) - 1, null);
                                            }
                                            else
                                            {
                                                no.setProx(new No(Convert.ToInt32(aux[0]) - 1, null));
                                                no = no.getProx();
                                            }
                                        }

                                        ini.setCount(i);
                                        lFace.Add(ini);
                                        ini = null;
                                    }
                                }
                            }
                        }

                        Reta.HeightWidth(imgBmp);
                        PontoCentral(true);//Centro da tela
                        Transladar(ctrX, ctrY, 0);
                        MultiplicarPontos();
                        Desenhar();
                        BloqueioDeOpcoes(true);
                        AtualizarCor();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: reduPKR/imagens_3d_c-
        private void ProjecaoObliqua(double[][] mat)
        {
            int j;

            double[] p1, p2;
            No       face;

            Pontos[] p;

            ret = imgBmp;

            Reta.IniciarMatriz();
            for (int i = 0; i < lFace.Count; i++)
            {
                face = ((No)(lFace[i]));
                p    = new Pontos[face.getCount()];

                j = 0;
                while (face != null)
                {
                    p[j] = (Pontos)lVertAtual[face.getPos()];
                    j++;
                    face = face.getProx();
                }
                p[j] = p[0];

                Pontos vertAB = new Pontos(p[1].getX() - p[0].getX(), p[1].getY() - p[0].getY(), p[1].getZ() - p[0].getZ());
                Pontos vertAC = new Pontos(p[2].getX() - p[0].getX(), p[2].getY() - p[0].getY(), p[2].getZ() - p[0].getZ());

                if (lVetorNormal.Count <= i)
                {
                    lVetorNormal.Add(new Vetor(vertAB, vertAC));
                }
                else
                {
                    lVetorNormal[i] = new Vetor(vertAB, vertAC);
                }

                if (cbBackFaceCulling.Checked)
                {
                    if (((Vetor)lVetorNormal[i]).getZ() > 0)
                    {
                        for (int k = 0; k < j; k++)
                        {
                            p1 = MultiplicarPontos(mat, p[k]);
                            p2 = MultiplicarPontos(mat, p[k + 1]);

                            Reta.Bresenham((int)p1[0], (int)p1[1], (int)p2[0], (int)p2[1]);
                        }
                    }
                }
                else
                {
                    for (int k = 0; k < j; k++)
                    {
                        p1 = MultiplicarPontos(mat, p[k]);
                        p2 = MultiplicarPontos(mat, p[k + 1]);

                        Reta.Bresenham((int)p1[0], (int)p1[1], (int)p2[0], (int)p2[1]);
                    }
                }
            }

            Reta.AlocarBitmap(ret);
            Reta.Desenhar();
            if (btnColorir.Text.Equals("Colorir"))
            {
                // ScanLine.Scanline(Reta.getImgDta());
            }
            Reta.DesalocarBitmap(ret);

            pictureBox.Image = ret;
            imgBmp           = ret;
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: reduPKR/imagens_3d_c-
        private void OrtograficaLateral()
        {
            int j;
            No  face;

            Pontos[] p;

            ret = imgBmp;

            Reta.IniciarMatriz();

            for (int i = 0; i < lFace.Count; i++)
            {
                face = ((No)(lFace[i]));
                p    = new Pontos[face.getCount()];

                j = 0;
                while (face != null)
                {
                    p[j] = (Pontos)lVertAtual[face.getPos()];
                    j++;
                    face = face.getProx();
                }
                p[j] = p[0];

                Pontos vertAB = new Pontos(p[1].getX() - p[0].getX(), p[1].getY() - p[0].getY(), p[1].getZ() - p[0].getZ());
                Pontos vertAC = new Pontos(p[2].getX() - p[0].getX(), p[2].getY() - p[0].getY(), p[2].getZ() - p[0].getZ());

                if (lVetorNormal.Count <= i)
                {
                    lVetorNormal.Add(new Vetor(vertAB, vertAC));
                }
                else
                {
                    lVetorNormal[i] = new Vetor(vertAB, vertAC);
                }

                if (cbBackFaceCulling.Checked)
                {
                    if (((Vetor)lVetorNormal[i]).getX() > 0)
                    {
                        for (int k = 0; k < j; k++)
                        {
                            Reta.Bresenham(p[k].getY() + 100, p[k].getZ() + 425, p[k + 1].getY() + 100, p[k + 1].getZ() + 425);//pintanto
                        }
                    }
                }
                else
                {
                    for (int k = 0; k < j; k++)
                    {
                        Reta.Bresenham(p[k].getY() + 100, p[k].getZ() + 425, p[k + 1].getY() + 100, p[k + 1].getZ() + 425);//pintanto
                    }
                }
            }

            Reta.AlocarBitmap(ret);
            Reta.Desenhar();
            if (btnColorir.Text.Equals("Colorir"))
            {
                //ScanLine.Scanline(Reta.getImgDta());
            }
            Reta.DesalocarBitmap(ret);

            pictureBox.Image = ret;
            imgBmp           = ret;
        }