/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */
package despliega;

import java.awt.Color;
import java.awt.Graphics;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import tiburcio.lib3D.s3D;

/**
 *
 * @author mario
 */
public class Despliega extends s3D{

    /**
     * @param args the command line arguments
     */
    public Despliega(){
        DEF_SISTEMA("Desplegando",800,800,Color.black,30,30,1,400,400);
        
    }
    
    public void paint(Graphics g){
        ejes3D(Color.green,g);
        g.setColor(Color.green);
        //caja(50,50,50,-50,-50,-50,g);
        try{
          Path path = Path.of("/home/mario/povs/taza/taza.tib");
          List<String> lineas = Files.readAllLines(path);
          String trianguloS=lineas.get(0);
          int triangulos=Integer.parseInt(trianguloS);
          int esc=200;
          for (int i=1;i<=triangulos;i++){
            int posT=i*3-2;
            //System.out.println("Triángulo "+posT);
            String v1[]=lineas.get(posT).split(",");
            double v1f[]={ esc*Double.parseDouble(v1[0]),
                           esc*Double.parseDouble(v1[1]),
                           esc*Double.parseDouble(v1[2]) };
            String v2[]=lineas.get(posT+1).split(",");
            double v2f[]={ esc*Double.parseDouble(v2[0]),
                           esc*Double.parseDouble(v2[1]),
                           esc*Double.parseDouble(v2[2]) };
            String v3[]=lineas.get(posT+2).split(",");
            double v3f[]={ esc*Double.parseDouble(v3[0]),
                           esc*Double.parseDouble(v3[1]),
                           esc*Double.parseDouble(v3[2]) };
            g.setColor(Color.green);
            linea3D(v1f[0],v1f[1],v1f[2],v2f[0],v2f[1],v2f[2],g);
            linea3D(v2f[0],v2f[1],v2f[2],v3f[0],v3f[1],v3f[2],g);
            linea3D(v3f[0],v3f[1],v3f[2],v1f[0],v1f[1],v1f[2],g);
          } //for
          System.out.println("FIN !!");
        } //try
        catch(Exception e){
             System.out.println("Error !!"+e.getMessage());
        }       
    }
    
    public static void main(String[] args) {
        // TODO code application logic here
        Despliega p=new Despliega();
    }
    
}
