Пример #1
0
  private XRCompositeManager(XRSurfaceData surface) {
    con = new XRBackendNative();
    // con = XRBackendJava.getInstance();

    String gradProp = System.getProperty("sun.java2d.xrgradcache");
    enableGradCache =
        gradProp == null || !(gradProp.equalsIgnoreCase("false") || gradProp.equalsIgnoreCase("f"));

    XRPaints.register(this);

    initResources(surface);

    maskBuffer = new MaskTileManager(this, surface.getXid());
    textRenderer = new XRTextRenderer(this);
    maskImage = new XRMaskImage(this, surface.getXid());
  }
Пример #2
0
  public void actionPerformed(ActionEvent e) {
    final String command = e.getActionCommand();

    if (OPEN_CSV_FILE.equals(command)) {
      final JFileChooser chooser = new JFileChooser(System.getProperty("user.home"));
      final FileFilter filter = new CVSFileFilter();
      chooser.setFileFilter(filter);
      final int returnVal = chooser.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        // setCvsFile(chooser.getSelectedFile().getPath());
      }

    } else if (EXIT.equals(command)) {
      windowClosingEvent(null);
    }

    if (EXIT.equals(command)) windowClosingEvent(null);
  }
Пример #3
0
  /**
   * File Manager Frame
   *
   * @param frame parent frame
   */
  public FileManager(JFrame frame, FileFilter filter) {
    super("File Manager");

    FileTree ftree = new FileTree(new File(System.getProperty("user.dir")), frame, filter);
    JScrollPane jsp = new JScrollPane(ftree);
    JPanel pane = (JPanel) getContentPane();
    pane.setLayout(new BorderLayout());
    pane.add(jsp, BorderLayout.CENTER);
    setJMenuBar(makeMenuBar(pane, ftree));
    pane.add(getFileFileterComboBox(ftree), BorderLayout.SOUTH);

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    jsp.setPreferredSize(new Dimension(210, (int) (screen.getHeight() / 2)));
    pack();

    int yloc = (int) ((screen.getHeight() - getHeight()) / 2);
    setLocation(0, yloc);
    setVisible(true);
  }
Пример #4
0
  boolean setHighscore() {
    int high = 0;
    boolean newh = false;

    String path = "";
    if (System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0)
      path =
          new JFileChooser().getFileSystemView().getDefaultDirectory().toString()
              + "/Library/Application Support/ByRikard/IJAG";
    else path = System.getenv("APPDATA") + "/ByRikard/IJAG";
    String highscorePath = path + "/highscore";

    try {
      FileInputStream fstream = new FileInputStream(highscorePath);
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      high = Integer.parseInt(br.readLine());
      in.close();
    } catch (Exception e) {
    }
    oldHighScore = high;
    if (high < player.score) {
      high = player.score;
      newh = true;
    }

    try {
      String content = "" + high;
      File file = new File(highscorePath);

      if (!file.exists()) {
        file.createNewFile();
      }
      FileWriter fw = new FileWriter(file.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);
      bw.write(content);
      bw.close();

    } catch (IOException e) {
    }
    return newh;
  }
Пример #5
0
/**
 * a View for rendering Text's based on bitmaps (when available) or TextLayout (when image not
 * available)
 */
public class TextViewHybrid extends LeafElementView implements Runnable {

  boolean wantToComputeLatexDimensions =
      true; // from preferences: do we want to run LateX to compute preferences
  boolean wantToGetBitMap =
      true; // from preferences: do we want to run LateX+pstoimg to get a bitmap.
  //   wantToGetBitMap=true should Imply wantToComputeLatexDimensions=true

  protected double strx, stry; // TextLayout/Image location with respect to PicText's anchor point
  // [pending] pas joli. A enlever sous peu (utilise juste dans HitInfo que je ne comprends pas, je
  // laisse donc en attendant)

  protected TextLayout
      textLayout; // the TextLayout that renders the text string of this TextEditable
  // [inherited] shape; But here it's the frame box !!! (not textLayout !)
  protected AffineTransform text2ModelTr =
      new AffineTransform();; // maps text coordinates to Model coordinates
  protected BufferedImage image; // bitmap (if null, we rely on TextLayout)
  protected boolean areDimensionsComputed; // has the real dimensions been read from the log file ?
  protected int fileDPI =
      300; // Dot Per Inch of the file (for image resizing) [pending] gerer les preferences de ce
           // parametre
  // il faut passer la valeur en DPI en argument a create_bitmap.sh

  /** pattern used for parsing log file */
  private static final Pattern LogFilePattern =
      Pattern.compile("JPICEDT INFO:\\s*([0-9.]*)pt,\\s*([0-9.]*)pt,\\s*([0-9.]*)pt");

  private static final String CR_LF = System.getProperty("line.separator");

  private PicPoint ptBuf = new PicPoint();

  /** construct a new View for the given PicRectangle */
  public TextViewHybrid(PicText te, AttributesViewFactory f) {
    super(te, f);
    areDimensionsComputed = false;
    changedUpdate(null);
  }

  public PicText getElement() {
    return (PicText) element;
  }

  /**
   * Returns the text rotation in radians : subclassers that don't support rotating text may return
   * 0 here. Used by TextLayout only.
   */
  protected double getRotation() {
    //			debug(set.getAttribute(TEXT_ROTATION).toString());
    return Math.toRadians(element.getAttribute(TEXT_ROTATION).doubleValue());
  }

  /**
   * Give notification from the model that a change occured to the text this view is responsible for
   * rendering.
   *
   * <p>
   */
  public void changedUpdate(DrawingEvent.EventType eventType) {
    PicText text = (PicText) element;
    if (textLayout == null) {
      // new *************************** begin (by ss & bp)
      textLayout =
          new TextLayout(
              text.getText(text.getTextMode()).length() == 0
                  ? " "
                  : text.getText(text.getTextMode()),
              // new *************************** end (by ss & bp)
              DefaultViewFactory.textFont, // static field
              new FontRenderContext(null, false, false));
    }
    if (eventType == DrawingEvent.EventType.TEXT_CHANGE) {
      // new *************************** begin (by ss & bp)
      textLayout =
          new TextLayout(
              text.getText(text.getTextMode()).length() == 0
                  ? " "
                  : text.getText(text.getTextMode()),
              // new *************************** end (by ss & bp)
              DefaultViewFactory.textFont,
              new FontRenderContext(null, false, false));

      // first try to create a bitmap
      image =
          null; // aka "reset" image => we might temporarily resort to TextLayout until the image is
                // ready
      areDimensionsComputed = false;
      // reset dimensions to the textlayout dimensions
      text.setDimensions(
          textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent());

      // new *************************** begin (by ss & bp)
      if (wantToComputeLatexDimensions && text.getText(text.getTextMode()).length() > 0) {
        // new *************************** end (by ss & bp)
        // don't produce a bitmap for an empty string (LaTeX might not like it)
        // [pending] this should be made dependent on a preference's option
        new Thread(this).start();
      }
      if (image == null) super.changedUpdate(null); // ie resort to TextLayout (update all)
    } else {
      text.updateFrame();
      super.changedUpdate(eventType);
    }
  }

  // Thread's run method aimed at creating a bitmap asynchronously
  public void run() {
    Drawing drawing = new Drawing();
    PicText rawPicText = new PicText();
    String s = ((PicText) element).getText();
    rawPicText.setText(s);
    drawing.add(
        rawPicText); // bug fix: we must add a CLONE of the PicText, otherwise it loses it former
                     // parent... (then pb with the view )
    drawing.setNotparsedCommands(
        "\\newlength{\\jpicwidth}\\settowidth{\\jpicwidth}{"
            + s
            + "}"
            + CR_LF
            + "\\newlength{\\jpicheight}\\settoheight{\\jpicheight}{"
            + s
            + "}"
            + CR_LF
            + "\\newlength{\\jpicdepth}\\settodepth{\\jpicdepth}{"
            + s
            + "}"
            + CR_LF
            + "\\typeout{JPICEDT INFO: \\the\\jpicwidth, \\the\\jpicheight,  \\the\\jpicdepth }"
            + CR_LF);
    RunExternalCommand.Command commandToRun = RunExternalCommand.Command.BITMAP_CREATION;
    // RunExternalCommand command = new RunExternalCommand(drawing, contentType,commandToRun);
    boolean isWriteTmpTeXfile = true;
    String bitmapExt = "png"; // [pending] preferences
    String cmdLine =
        "{i}/unix/tetex/create_bitmap.sh {p} {f} "
            + bitmapExt
            + " "
            + fileDPI; // [pending] preferences
    ContentType contentType = getContainer().getContentType();
    RunExternalCommand.isGUI = false; // System.out, no dialog box // [pending] debug
    RunExternalCommand command =
        new RunExternalCommand(drawing, contentType, cmdLine, isWriteTmpTeXfile);
    command
        .run(); // synchronous in an async. thread => it's ok (anyway, we must way until the LaTeX
                // process has completed)

    if (wantToComputeLatexDimensions) {
      // load size of text:
      try {
        File logFile = new File(command.getTmpPath(), command.getTmpFilePrefix() + ".log");
        BufferedReader reader = null;
        try {
          reader = new BufferedReader(new FileReader(logFile));
        } catch (FileNotFoundException fnfe) {
          System.out.println("Cannot find log file! " + fnfe.getMessage());
          System.out.println(logFile);
        } catch (IOException ioex) {
          System.out.println("Log file IO exception");
          ioex.printStackTrace();
        } // utile ?
        System.out.println("Log file created! file=" + logFile);
        getDimensionsFromLogFile(reader, (PicText) element);
        syncStringLocation(); // update dimensions
        syncBounds();
        syncFrame();
        SwingUtilities.invokeLater(
            new Thread() {
              public void run() {
                repaint(null);
              }
            });
        // repaint(null); // now that dimensions are available, we force a repaint() [pending]
        // smart-repaint ?
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (wantToGetBitMap) {
      // load image:
      try {
        File bitmapFile =
            new File(command.getTmpPath(), command.getTmpFilePrefix() + "." + bitmapExt);
        this.image = ImageIO.read(bitmapFile);
        System.out.println(
            "Bitmap created! file="
                + bitmapFile
                + ", width="
                + image.getWidth()
                + "pixels, height="
                + image.getHeight()
                + "pixels");
        if (image == null) return;
        syncStringLocation(); // sets strx, stry, and dimensions of text
        syncBounds();
        // update the AffineTransform that will be applied to the bitmap before displaying on screen
        PicText te = (PicText) element;
        text2ModelTr.setToIdentity(); // reset
        PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
        text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
        text2ModelTr.translate(te.getLeftX(), te.getTopY());
        text2ModelTr.scale(
            te.getWidth() / image.getWidth(),
            -(te.getHeight() + te.getDepth()) / image.getHeight());
        // [pending]  should do something special to avoid dividing by 0 or setting a rescaling
        // factor to 0 [non invertible matrix] (java will throw an exception)
        syncFrame();
        SwingUtilities.invokeLater(
            new Thread() {
              public void run() {
                repaint(null);
              }
            });
        // repaint(null); // now that bitmap is available, we force a repaint() [pending]
        // smart-repaint ?
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  /**
   * update strx stry = location of TextLayout's bottom-Left corner with respect to PicText's
   * anchor-point
   */
  protected void syncStringLocation() {
    PicText te = (PicText) element;
    PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
    if (image == null) {
      if (!areDimensionsComputed) {
        te.setDimensions(
            textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent());
      }
      strx = te.getLeftX() - anchor.x;
      stry = te.getBaseLineY() - anchor.y;
    } else { // image not null
      strx = te.getLeftX() - anchor.x;
      stry = te.getBottomY() - anchor.y;
    }
  }

  /**
   * Synchronize the textLayout and the shape (=frame box, by calling syncFrame) with the model When
   * <code>TextLayout</code> is used, this delegates to <code>getRotation()</code> where computing
   * rotation angle is concerned, and updates the AffineTransform returned by <code>
   * getTextToModelTransform()</code>.
   */
  protected void syncShape() {
    PicText te = (PicText) element;

    //			textLayout = new TextLayout(te.getText().length()==0 ? " " : te.getText(),
    //			    textFont,
    //			    new FontRenderContext(null,false,false));

    text2ModelTr.setToIdentity(); // reset
    PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
    text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
    // the reference point of an image is the top-left one, but the refpoint of a text layout is on
    // the baseline
    if (image != null) {
      text2ModelTr.translate(te.getLeftX(), te.getTopY());
      if (te.getWidth() != 0
          && image.getWidth() != 0
          && (te.getDepth() + te.getHeight()) != 0
          && image.getHeight() != 0)
        text2ModelTr.scale(
            te.getWidth() / image.getWidth(),
            -(te.getHeight() + te.getDepth()) / image.getHeight());
    } else {
      // Hack ? Just cheating a little bit ? Ou juste ruse ?
      // we want here to use the dimensions of the textLayout instead of latex dimensions if
      // areDimensionsComputed
      // sinon on va aligner le textlayout en fonction des parametres latex, et l'Utilisateur (qui
      // est bien bete) ne va rien comprendre.
      double latexH = 0;
      double latexD = 0;
      double latexW = 0;
      if (areDimensionsComputed) { // store latex dimensions, and setDimensions to textLayout ones
        latexH = te.getHeight();
        latexD = te.getDepth();
        latexW = te.getWidth();
        te.setDimensions(
            textLayout.getBounds().getWidth(), textLayout.getAscent(), textLayout.getDescent());
      }
      text2ModelTr.translate(te.getLeftX(), te.getBaseLineY());
      if (areDimensionsComputed) { // restore latex dimensions
        te.setDimensions(latexW, latexH, latexD);
      }
      // Autre possibilite= comprimer le texte pour qu'il rentre dans la boite (evite le hack
      // ci-dessus):
      // text2ModelTr.scale(te.getWidth()/textLayout.getWidth(),-(te.getHeight()+te.getDepth())/textLayout.getHeight());
      text2ModelTr.scale(1.0, -1.0);
    }
    syncFrame();
  }

  /**
   * synchronize frame shape and location (TextLayout only) ; this is called by syncShape(), so that
   * subclasser might override easily when only rectangular shapes are availables.
   */
  protected void syncFrame() {
    PicText te = (PicText) element;
    if (!te.isFramed()) {
      return;
    }
    AffineTransform tr =
        new AffineTransform(); // maps Image coordinates to Model coordinates (see paint)
    tr.setToIdentity(); // reset
    PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
    tr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
    shape = tr.createTransformedShape(te.getShapeOfFrame());
  }

  protected void getDimensionsFromLogFile(BufferedReader reader, PicText text) {
    if (reader == null) {
      return;
    }
    String line = ""; // il rale si j'initialise pas ...
    boolean finished = false;
    while (!finished) {
      try {
        line = reader.readLine();
      } catch (IOException ioex) {
        ioex.printStackTrace();
        return;
      }
      if (line == null) {
        System.out.println("Size of text not found in log file...");
        return;
      }

      System.out.println(line);
      Matcher matcher = LogFilePattern.matcher(line);

      if (line != null && matcher.find()) {
        System.out.println("FOUND :" + line);
        finished = true;
        try {
          text.setDimensions(
              0.3515 * Double.parseDouble(matcher.group(1)), // height, pt->mm (1pt=0.3515 mm)
              0.3515 * Double.parseDouble(matcher.group(2)), // width
              0.3515 * Double.parseDouble(matcher.group(3))); // depth
          areDimensionsComputed = true;
        } catch (NumberFormatException e) {
          System.out.println("Logfile number format problem: $line" + e.getMessage());
        } catch (IndexOutOfBoundsException e) {
          System.out.println("Logfile regexp problem: $line" + e.getMessage());
        }
      }
    }
    return;
  }

  /** Synchronizes bounding box with the model ; */
  protected void syncBounds() {
    PicText te = (PicText) element;
    // [pending] Il faut tenir compte de la rotation !

    Rectangle2D latexBB =
        null; // BB relative to latex dimensions (including rotation) (without frame)
    Rectangle2D textLayoutBB =
        null; // BB relative to textLayout dimensions (including rotation) (without frame)
    Rectangle2D textBB = null; // BB of the text (including rotation), without frame

    if (areDimensionsComputed) { // compute latexBB
      Rectangle2D nonRotated =
          new Rectangle2D.Double(
              te.getLeftX(), te.getBottomY(), te.getWidth(), te.getHeight() + te.getDepth());
      AffineTransform tr =
          new AffineTransform(); // maps Image coordinates to Model coordinates (see paint)
      tr.setToIdentity(); // reset
      PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
      tr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
      latexBB = tr.createTransformedShape(nonRotated).getBounds2D();
    }

    if (image == null) { // compute textLayoutBB
      Rectangle2D nonRotated = textLayout.getBounds();
      textLayoutBB = text2ModelTr.createTransformedShape(nonRotated).getBounds2D();
    }

    // use textLayoutBB or latexBB or their union
    if (image != null) textBB = latexBB;
    else {
      if (!areDimensionsComputed) textBB = textLayoutBB;
      else {
        textBB = latexBB.createUnion(textLayoutBB);
      }
    }

    // union with frame BB
    if (te.isFramed()) {
      super.syncBounds(); // update bounds of the frame if necessary
      Rectangle2D.union(super.bounds, textBB, this.bounds);
    } else this.bounds = textBB;
  }

  /**
   * Render the View to the given graphic context. This implementation render the interior first,
   * then the outline.
   */
  public void paint(Graphics2D g, Rectangle2D a) {
    if (!a.intersects(getBounds())) return;
    if (image != null) { // paint bitmap
      g.drawImage(image, text2ModelTr, null);
      // debug:
      g.setPaint(Color.red);
      g.draw(this.bounds);
      super.paint(g, a); // possibly paint framebox if non-null
    } else { // paint textlayout
      super.paint(g, a); // possibly paint framebox if non-null

      AffineTransform oldAT = g.getTransform();
      // paint text in black
      g.setPaint(Color.black);
      // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font
      // being mirrored...
      g.transform(text2ModelTr); // also include rotation
      textLayout.draw(g, 0.0f, 0.0f);
      // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre)
      // get back to previous transform
      g.setTransform(oldAT);
      if (DEBUG) {
        g.setPaint(Color.red);
        g.draw(bounds);
      }
    }
  }

  /**
   * This implementation calls <code>super.hitTest</code> and returns the result if non-null (this
   * should be a HitInfo.Point), then returns a HitInfo.Interior if the mouse-click occured inside
   * the text bound (as defined by text layout)
   *
   * @return a HitInfo corresponding to the given mouse-event
   */
  public HitInfo hitTest(PEMouseEvent e) {

    // from Bitmap:
    if (image != null) {
      if (getBounds().contains(e.getPicPoint())) {
        return new HitInfo.Interior((PicText) element, e);
      }
      return null;
    }

    // from TextLayout:
    if (!getBounds().contains(e.getPicPoint())) return null;

    PicText te = (PicText) element;
    // recompute textlayout b-box, but store it in a temporary field !
    Rectangle2D tb = textLayout.getBounds();
    Shape text_bounds = text2ModelTr.createTransformedShape(tb);
    if (text_bounds.contains(e.getPicPoint())) {
      // [SR:pending] for the hitInfo to be reliable, getPicPoint() should first be transformed by
      //              inverse text2ModelTr ! (especially when rotationAngle != 0)
      TextHitInfo thi =
          textLayout.hitTestChar(
              (float) (e.getPicPoint().x - strx),
              (float) (e.getPicPoint().y - stry)); // guaranteed to return a non-null thi
      return new HitInfo.Text((PicText) element, thi, e);
    }
    // test hit on textlayout's bounding rectangle :
    // else if (bounds.contains(e.getPicPoint())) return new HitInfo.Interior(element,e);
    return null;
  }

  /**
   * [SR:pending] make this view implement aka TextEditableView interface (or something like it),
   * where TextEditableView is a subinterface of View with text-editing specific capabilities.
   *
   * <p>Returns the TextLayout which is responsible for painting the textual content of this element
   */
  public TextLayout getTextLayout() {
    return textLayout;
  }

  /**
   * Return an affine transform which translat b/w the TextLayout coordinate system and the
   * jpicedt.graphic.model coordinate system. [SR:pending] refactor method name to something more
   * explanatory
   */
  public AffineTransform getTextToModelTransform() {
    return text2ModelTr;
  }
} // TextView
Пример #6
0
public class Board implements GLEventListener {
  private String mp3File, artist, album;
  private long time, timeGap;
  private ArrayList<Line> lines;
  private Music song;
  private boolean songIsPlaying, firstTime;
  private int lowestNoteToProcess, lowestNoteToRender;
  private int score;
  private boolean[] key;
  private long dt_timer;

  private int fretDuration; // number of milliseconds on the fret
  private int noteErrorDuration; // number of milliseconds to still accept a note. bidirectional.
  private float targetPos; // location of buttons to press
  private float length;
  float[][] colors;
  Note noteToDraw;

  private GLU glu = new GLU();
  private TextRenderer renderer;

  // test values///////////////////////
  // private float y =0.8624921f , z=-2.3839877f;
  // 1.9000014 0.35450974
  private long previous;
  private float y = 1.9000014f, z = 0.35450974f;

  public static Input1 input = new Input1();
  private File menuBG = new File(System.getProperty("user.dir") + "/menuBG.png");
  private Texture texture;
  private float zTest;
  private Note redNote = new Note(255f, 0f, 0f),
      yellowNote = new Note(255f, 255f, 0f),
      blueNote = new Note(0f, 0f, 255f),
      greenNote = new Note(0f, 255f, 0f),
      orangeNote = new Note();

  private long oldSongTime = 0;
  private long oldTime = 0;
  private long updateTime = 0;
  ////////////////////////////////////

  public Board() {
    time = 0;
    lines = new ArrayList<Line>();
    zTest = -10f;
    song = null;
    songIsPlaying = false;
    firstTime = true;
    lowestNoteToProcess = 0;
    lowestNoteToRender = 0;

    fretDuration = 4000;
    noteErrorDuration = 100;
    targetPos = -2.5f;
    length = 10f;
    dt_timer = 0;
    timeGap = 0;

    colors =
        new float[][] {
          {255f, 0f, 0f},
          {255f, 255f, 0f},
          {0f, 0f, 255f},
          {0f, 255f, 0f},
          {255f, 255f, 0f} // filler
        };
    key = new boolean[21];
  }

  public void loadData(String file) {
    try {
      Scanner txt = new Scanner(new File(file));
      mp3File = txt.nextLine();
      artist = txt.nextLine();
      album = txt.nextLine();
      while (txt.hasNext()) {
        long noteTime = txt.nextLong();
        int lengthThrowaway = txt.nextInt();
        String states = txt.next().trim();
        lines.add(new Line(noteTime, states));
      }
      song = new Music(mp3File);
      song.load();
    } catch (Exception e) {
      System.out.println(e);
    }
  } // end loadData

  public void playSong() {
    song.play();
  }

  public void pauseSong() {
    song.pause();
  }

  public void display(GLAutoDrawable gLDrawable) {
    key = Input.keysPressed();

    double dt = (System.currentTimeMillis() - dt_timer) / 1000.0;
    dt_timer = System.currentTimeMillis();

    // Start 3d Rendering
    GL gl = gLDrawable.getGL();

    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    gl.glLoadIdentity();

    GLU glu = new GLU();

    // Code to adjust camera
    if (input.getKey(KeyEvent.VK_UP)) z -= .5 * dt;
    if (input.getKey(KeyEvent.VK_DOWN)) z += .5 * dt;

    if (input.getKey(KeyEvent.VK_LEFT)) y -= .5 * dt;
    if (input.getKey(KeyEvent.VK_RIGHT)) y += .5 * dt;
    if (input.getKey(KeyEvent.VK_SPACE)) System.out.println(y + " " + z);

    glu.gluLookAt(0, y, z, 0, 0, -3, 0, 1, 0);

    // orangeNote.drawBar(gLDrawable, zTest);
    // redNote.draw(gLDrawable, -3f, -4f, zTest);
    // yellowNote.draw(gLDrawable, -1.5f, -4f, zTest);
    // blueNote.draw(gLDrawable, 0f, -4f, zTest);
    // greenNote.draw(gLDrawable, 1.5f, -4f, zTest);
    zTest += 0.005f;
    if (zTest > -2f) zTest = -10f;

    gl.glPushMatrix();
    gl.glEnable(GL.GL_BLEND);
    // gl.glRotatef(70,1,-2,1);

    gl.glBegin(GL.GL_QUADS);
    // Draw the Board
    // x goes basically from -1 to 1(camera changed tho)
    // y stays same
    // board length is -z
    gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f); // R,G,B,A
    gl.glVertex3f(-3f, -4f, 0f); // x,y,z

    gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f);
    gl.glVertex3f(3f, -4f, 0f);

    gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f);
    gl.glVertex3f(3f, -4f, -10f);

    gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f);
    gl.glVertex3f(-3f, -4f, -10f);

    // All y values on top of the Board must have at least
    // 0.0001f added for some reason
    // Bottom bar - Orange
    gl.glColor4f(255 / 256f, 165 / 256f, 0 / 256f, 1f);
    gl.glVertex3f(-3f, -4f + .0001f, -2.15f); // close left
    gl.glVertex3f(3f, -4f + .0001f, -2.15f); // close right
    gl.glVertex3f(3f, -4f + .0001f, -2.85f); // far right
    gl.glVertex3f(-3f, -4f + .0001f, -2.85f); // far left
    // RedNote
    gl.glColor4f(1f, 0f, 0f, 1f);
    gl.glVertex3f(-3f, -4f + .001f, -2.25f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.75f);
    gl.glVertex3f(-3f, -4f + .001f, -2.75f);
    // YellowNote
    gl.glColor4f(1f, 1f, 0f, 1f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(0f, -4f + .001f, -2.25f);
    gl.glVertex3f(0f, -4f + .001f, -2.75f);
    gl.glVertex3f(-1.5f, -4f + .001f, -2.75f);
    // BlueNote
    gl.glColor4f(0f, 0f, 1f, 1f);
    gl.glVertex3f(0f, -4f + .001f, -2.25f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.75f);
    gl.glVertex3f(0f, -4f + .001f, -2.75f);
    // GreenNote
    gl.glColor4f(0f, 1f, 0f, 1f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.25f);
    gl.glVertex3f(3f, -4f + .001f, -2.25f);
    gl.glVertex3f(3f, -4f + .001f, -2.75f);
    gl.glVertex3f(1.5f, -4f + .001f, -2.75f);
    // End Bottom Bar

    this.renderNotes(gLDrawable, dt);

    /////////////////////////////////////
    gl.glEnd();

    gl.glDisable(GL.GL_BLEND);
    gl.glPopMatrix();

    try {
      Thread.sleep(1);
    } catch (Exception e) {
    }
  }

  public void renderNotes(GLAutoDrawable gLDrawable, double dt) {
    // RENDER NOTES////////////////////////

    /*  OLD CODE TO CHECK/UPDATE TIME
    long songTime = song.getTime();
    long milliTime = System.currentTimeMillis();
    if(firstTime)
    {
    	time = songTime;
    	firstTime = false;
    }
    else
    {
    	if(songTime == oldSongTime)
    	{
    		updateTime += milliTime-oldTime;
    		System.out.println("update time: "+updateTime);

    	}
    	else
    	{
    		if (songTime == oldSongTime + updateTime)
    			System.out.println("WINWINWINWIWNWINWIWNWIN");
    		else
    			System.out.println("Difference: "+(songTime-oldSongTime - updateTime));


    		updateTime = 0;
    		System.out.println("New Time: "+time);
    	}
    	time = songTime + updateTime;
    }//end else

    	oldSongTime = songTime;
    	oldTime = milliTime;*/
    time = song.getTime();
    for (int i = lowestNoteToProcess; i < lines.size(); i++) {
      Line line = lines.get(i);
      if (line.getTime() - noteErrorDuration > time) break;
      if (line.getState() == 0) // not pressed
      {
        if (time > line.getTime() + noteErrorDuration) // missed line
        {
          // System.out.println("missed line");
          line.setState(3);
          score -= 1;
          lowestNoteToProcess++;
        }
      } // code below takes care of this
    } // end for

    // find closest line in bounds to be pressed
    // if a line exists
    // see if correct key combo was pressed
    // do the thing
    // else
    // play a bad line sound
    // if it doesnt exist
    // play a bad line sound
    Line closest = null;
    long closestDistance = 1000000;
    for (int i = lowestNoteToProcess; i < lines.size(); i++) {
      Line n = lines.get(i);
      if (n.getTime() - noteErrorDuration > time) break;
      if (n.getState()
          == 1) // user is holding down this line, so it is the only one that can be processed
      {
        closest = n;
        break;
      }
      if (Math.abs(time - n.getTime()) <= closestDistance
          && time >= n.getTime() - noteErrorDuration
          && time <= n.getTime() + noteErrorDuration) {
        closest = n;
        closestDistance = (long) Math.abs(time - n.getTime());
      }
    }
    if (closest != null) {
      if (closest.getState() == 0) // not pressed
      {
        boolean seq = true;
        for (int x = 0; x < 5; x++)
          if (key[x] != closest.getNotes()[x]) {
            seq = false;
            break;
          }
        if (seq) {
          // System.out.println("pressed button");
          closest.setState(2); // pressed button
          lowestNoteToProcess++;
        }
        score += 1;
      } else {
        // play bad line sound
      }
    }
    /*else if(closest.getState() == 1)
    { //holding and strummed, cant do that
    	closest.getState() = 2;
    	System.out.println("you interrupted the holding");
    	lowestNoteToProcess++;
    	//play bad line sound
    }*/
    // }
    else // (if closest == null)
    {
      // play bad line sound
    }

    // Part 2
    for (int i = lowestNoteToRender; i < lines.size(); i++) {
      Line line = lines.get(i);
      float posz =
          (line.getTime() + -targetPos / length * fretDuration - time)
              / fretDuration
              * length; // head
      if (posz > length) break; // not rendered yet
      float posz2 =
          (line.getTime() + -targetPos / length * fretDuration - time)
              / fretDuration
              * length; // tail
      if (posz2 <= 1) // will never be rendered again
      {
        lowestNoteToRender++;
        continue;
      }
      if (posz <= length)
        for (int x = 0; x < 5; x++) {
          if (!line.getNotes()[x]) continue;
          if (line.getState() == 2) continue; // pressed

          if (line.getState() == 3) // missed
          noteToDraw = new Note(127f, 127f, 127f);
          else noteToDraw = new Note(colors[x][0], colors[x][1], colors[x][2]);
          if (x < 4) noteToDraw.draw(gLDrawable, -3 + (1.5f * x), -4, -posz);
          else noteToDraw.drawBar(gLDrawable, -posz, false);
        }
    }
    // }//end if songIsPlaying
  }

  public void init(GLAutoDrawable gLDrawable) {
    renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36)); // creates textrenderer
    GL gl = gLDrawable.getGL();
    gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black Background
    gl.glClearDepth(1.0f); // Depth Buffer Setup
    gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing
    gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do
    // Really Nice Perspective Calculations
    gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
  }

  public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
    GL gl = gLDrawable.getGL();
    float h = (float) width / (float) height;
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-h, h, -1, 1, 1, 600);
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -6f);
  }

  public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
} // end class
Пример #7
0
 public browse_jsp() {
   myUtil = new ewebeditor.server.util();
   sFileSeparator = System.getProperty("file.separator");
 }