Пример #1
0
 void setMessage(Animator a) {
   anim = a;
   who.setText(a.author());
   ref.setText(a.description());
   pan.remove(last);
   last = a.container();
   pan.add(last, "Center");
   if (T != null) T.interrupt();
 }
 public void init(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();
   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glLoadMatrixd(this._nyar.getGlProjectionMatrix(), 0);
   gl.glEnable(GL.GL_DEPTH_TEST);
   gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   Animator animator = new Animator(drawable);
   animator.start();
   return;
 }
  /**
   * Starts the animation thread, creating and initializing it if necessary. This method is invoked
   * when an indeterminate progress bar should start animating. Reasons for this may include:
   *
   * <ul>
   *   <li>The progress bar is determinate and becomes displayable
   *   <li>The progress bar is displayable and becomes determinate
   *   <li>The progress bar is displayable and determinate and this UI is installed
   * </ul>
   *
   * If you implement your own animation thread, you must override this method.
   *
   * @since 1.4
   * @see #stopAnimationTimer
   */
  protected void startAnimationTimer() {
    if (animator == null) {
      animator = new Animator();
    }

    animator.start(getRepaintInterval());
  }
Пример #4
0
 public void run() {
   if (Thread.currentThread() != T) throw new Error("do not call directly -- use start()");
   while (T != null) {
     int d = anim.doTick();
     if (d < 50) d = 50;
     if (d > 2000) d = 2000;
     try {
       Thread.sleep(d);
     } catch (Exception ex) {
     }
   }
 }
Пример #5
0
 boolean tryDir(String d) {
   ClassLoader L = getClass().getClassLoader();
   File p = new File(d, PACKAGE);
   System.out.println("Try " + p);
   if (!p.exists() || !p.isDirectory()) return false;
   for (File f : p.listFiles()) {
     String s = f.getName();
     if (!s.endsWith(".class")) continue;
     String name = s.substring(0, s.length() - 6);
     try {
       Class<?> c = L.loadClass(PACKAGE + "." + name);
       if (!Animator.class.isAssignableFrom(c)) continue;
       Animator a = (Animator) c.newInstance();
       a.container().setPreferredSize(DIM);
       map.put(name, a);
       System.out.println("  " + name);
       // ClassNotFoundException InstantiationException IllegalAccessException
     } catch (Exception e) {
       continue;
     }
   }
   return map.size() > 0;
 }
 /**
  * Stops the animation thread. This method is invoked when the indeterminate animation should be
  * stopped. Reasons for this may include:
  *
  * <ul>
  *   <li>The progress bar changes to determinate
  *   <li>The progress bar is no longer part of a displayable hierarchy
  *   <li>This UI in uninstalled
  * </ul>
  *
  * If you implement your own animation thread, you must override this method.
  *
  * @since 1.4
  * @see #startAnimationTimer
  */
 protected void stopAnimationTimer() {
   if (animator != null) {
     animator.stop();
   }
 }
Пример #7
0
 public void endAnimation() {
   if (fAnimator != null) {
     fAnimator.end();
     fAnimator = null;
   }
 }
Пример #8
0
 public void startAnimation() {
   if (view().drawing() instanceof Animatable && fAnimator == null) {
     fAnimator = new Animator((Animatable) view().drawing(), view());
     fAnimator.start();
   }
 }
Пример #9
0
  // Constructora
  public Principal() {

    // Titulo de la ventana y tamaño
    setTitle("Práctica 4");
    setSize(new Dimension(425, 500));
    super.setResizable(false);

    // Contenedor del editor
    panel = this.getContentPane();
    panel.setBackground(Color.blue);
    panel.setLayout(new BorderLayout());

    // Generamos el menu
    menu = new JMenuBar();
    archivo = new JMenu("Archivo");
    nuevo = new JMenuItem("Nuevo");
    salir = new JMenuItem("Salir");
    sobre = new JMenu("Sobre..");
    autores = new JMenuItem("Autores");

    menu.add(archivo);
    archivo.add(nuevo);
    archivo.add(salir);

    menu.add(sobre);
    sobre.add(autores);

    setJMenuBar(menu);

    // Creamos los botones
    this.panelBotones = new JPanel();
    panelBotones.setLayout(new GridLayout(3, 3));
    panel.add(panelBotones, BorderLayout.SOUTH);

    botonDefinirPuntos = new JButton("Definir Perfil");
    botonDefinirPuntos.setVisible(true);
    panelBotones.add(botonDefinirPuntos);

    botonAplicarSplines = new JButton("BSplines");
    botonAplicarSplines.setVisible(true);
    panelBotones.add(botonAplicarSplines);

    botonGenerarMallaRevolucion = new JButton("Revolución");
    botonGenerarMallaRevolucion.setVisible(true);
    panelBotones.add(botonGenerarMallaRevolucion);

    botonGenerarMallaExtrusion = new JButton("Extrusión");
    botonGenerarMallaExtrusion.setVisible(true);
    panelBotones.add(botonGenerarMallaExtrusion);

    botonCambiarModo = new JButton("Cambiar Modo");
    botonCambiarModo.setVisible(true);
    panelBotones.add(botonCambiarModo);

    botonDibujarNormales = new JButton("Activa Normales");
    botonDibujarNormales.setVisible(true);
    panelBotones.add(botonDibujarNormales);

    // Definimos el tipo de malla actual a representar
    this.tipoMalla = 0;

    // Definimos un perfil por defecto
    this.perfil = new ArrayList<PuntoVector3D>();
    this.perfil.add(new PuntoVector3D(250, 330, 0, 1));
    this.perfil.add(new PuntoVector3D(250, 300, 0, 1));
    this.perfil.add(new PuntoVector3D(230, 270, 0, 1));
    this.perfil.add(new PuntoVector3D(200, 240, 0, 1));
    this.perfil.add(new PuntoVector3D(200, 210, 0, 1));
    this.perfil.add(new PuntoVector3D(200, 180, 0, 1));
    this.perfil.add(new PuntoVector3D(200, 150, 0, 1));
    this.perfil.add(new PuntoVector3D(230, 120, 0, 1));

    // Creamos el canvas de dibujo
    canvas = new GLJPanel();
    escena = new GL3D(425, 425);
    canvas.addGLEventListener(escena);
    canvas.addMouseListener(new ManejadorRaton());
    panel.add(canvas, BorderLayout.CENTER);

    // Transformamos el perfil a coordenadas de la escena
    this.perfil = escena.transformarPerfil(this.perfil);
    escena.setPerfil(this.perfil);

    // Animación de la escena
    animacion = new Animator(canvas);
    animacion.start();

    // Entrada de datos desactivada
    entradaDatos = false;

    // Acción por defecto al cerrar la ventana
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    // Evento Oyente para la barra de menu "nuevo"
    nuevo.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            perfil = new ArrayList<PuntoVector3D>();
            escena.actualizarPerfil(tipoMalla, perfil);
          }
        });

    // Evento Oyente para la barra de menu "Autores"
    autores.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                null, "Iván Romero\nPedro Sánchez", "Autores", JOptionPane.INFORMATION_MESSAGE);
          }
        });

    // Evento Oyente para el boton "Definir Perfil"
    botonDefinirPuntos.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            perfil = new ArrayList<PuntoVector3D>();
            escena.setPerfil(perfil);
            entradaDatos = true;
          }
        });

    // Evento Oyente para el boton "Aplicar Splines"
    botonAplicarSplines.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            String dato =
                JOptionPane.showInputDialog(
                    null,
                    "Numero de puntos de control. Rango[" + perfil.size() + "...N]",
                    "Datos de Entrada",
                    1);
            if (dato != null) {
              int num = Integer.parseInt(dato);
              perfil = new Calculos().calculaPuntosBSplines(perfil, num);
              if (perfil.size() > num) {
                ArrayList<PuntoVector3D> perfilAux = new ArrayList<PuntoVector3D>();
                for (int i = 0; i < num - 2; i++) {
                  perfilAux.add(perfil.get(i));
                }
                perfil = (ArrayList<PuntoVector3D>) perfilAux.clone();
              }
              escena.setPerfil(perfil);
              entradaDatos = false;
            }
          }
        });

    // Evento Oyente para el boton "Malla Revolución"
    botonGenerarMallaRevolucion.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            // String datoNumVertices = "4";
            String datoAng = JOptionPane.showInputDialog("Ángulo de rotación: ", "0.15");
            if (datoAng != null) {

              Object[] opciones = {"3", "4"};
              int eleccion =
                  JOptionPane.showOptionDialog(
                      null,
                      "Número de Vértices de la cara: ",
                      "Datos de Entrada",
                      JOptionPane.DEFAULT_OPTION,
                      JOptionPane.WARNING_MESSAGE,
                      null,
                      opciones,
                      opciones[0]);

              int numVerticesCara = Integer.parseInt((String) opciones[eleccion]);
              double anguloRadianes = Double.parseDouble(datoAng);

              mallaActual = new MallaPorRevolucion(perfil, numVerticesCara, anguloRadianes);
              //  mallaRevolucion = new MallaPorRevolucion(perfil, numVerticesCara, anguloRadianes);

              //  escena.actualizarMallaRev(2, mallaRevolucion);
              escena.actualizarMalla(2, mallaActual);
              escena.setGenerado(true);
              entradaDatos = false;
            }
          }
        });

    // Evento Oyente para el boton "Malla Extrusión"
    botonGenerarMallaExtrusion.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            String SnP =
                JOptionPane.showInputDialog(
                    "Número de lados que aproximan la sección del toroide", "10");
            String SnQ = JOptionPane.showInputDialog("Número de capas del toroide", "50");
            String Sr1 = JOptionPane.showInputDialog("Radio del toro", "150");
            String Sr2 = JOptionPane.showInputDialog("Radio de la sección del toro", "20");

            int nP = Integer.parseInt(SnP);
            int nQ = Integer.parseInt(SnQ);
            float r1 = Float.parseFloat(Sr1);
            float r2 = Float.parseFloat(Sr2);

            mallaActual = new Toro(nP, nQ, r1, r2);
            escena.actualizarMalla(3, mallaActual);

            escena.setGenerado(true);
            entradaDatos = false;
          }
        });

    // Evento Oyente para el botón "Cambiar Modo"
    botonCambiarModo.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            Object[] opciones = {"Puntos", "Líneas", "Sólidos"};
            int eleccion =
                JOptionPane.showOptionDialog(
                    null,
                    "Cambiar Modo de Representación a: ",
                    "Datos de Entrada",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    opciones,
                    opciones[0]);

            mallaActual.setTipoMalla(eleccion);
          }
        });

    // Evento Oyente para el botón "Dibujar Normales"
    botonDibujarNormales.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            if (botonDibujarNormales.getText().equals("Activa Normales")) {
              botonDibujarNormales.setText("DesactivaNormales");
              mallaActual.setNormales(true);
            } else {
              botonDibujarNormales.setText("Activa Normales");
              mallaActual.setNormales(false);
            }
          }
        });

    // Añadimos un evento para la acción de salida
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            new Thread(
                    new Runnable() {

                      public void run() {
                        animacion.stop();
                        System.exit(0);
                      }
                    })
                .start();
          }
        });
  }
Пример #10
0
 // Start/stop animation
 public void setAnimation(boolean on) {
   if (on) animator.start();
   else animator.stop();
 }
Пример #11
0
 // Check if animation is proceeding
 public boolean isAnimated() {
   return animator.isAnimating();
 }
Пример #12
0
 public String message() {
   return anim.description();
 }