protected double computeScale(java.awt.Rectangle viewport) { if (this.resizeBehavior.equals(AVKey.RESIZE_SHRINK_ONLY)) { return Math.min(1d, (this.toViewportScale) * viewport.width / this.getScaledIconWidth()); } else if (this.resizeBehavior.equals(AVKey.RESIZE_STRETCH)) { return (this.toViewportScale) * viewport.width / this.getScaledIconWidth(); } else if (this.resizeBehavior.equals(AVKey.RESIZE_KEEP_FIXED_SIZE)) { return 1d; } else { return 1d; } }
/** * Compute the view range footprint on the globe. * * @param dc the current <code>DrawContext</code> * @param steps the number of steps. * @return an array list of <code>LatLon</code> forming a closed shape. */ protected ArrayList<LatLon> computeViewFootPrint(DrawContext dc, int steps) { ArrayList<LatLon> positions = new ArrayList<LatLon>(); Position eyePos = dc.getView().getEyePosition(); Angle distance = Angle.fromRadians( Math.asin( dc.getView().getFarClipDistance() / (dc.getGlobe().getRadius() + eyePos.getElevation()))); if (distance.degrees > 10) { double headStep = 360d / steps; Angle heading = Angle.ZERO; for (int i = 0; i <= steps; i++) { LatLon p = LatLon.greatCircleEndPosition(eyePos, heading, distance); positions.add(p); heading = heading.addDegrees(headStep); } return positions; } else return null; }
private void renderOneside(Point2D a, Point2D b, GL gl, double d) { gl.glClear(0); Vector3D t = new Vector3D(b.x - a.x, 0, b.y - a.y); Vector3D n = new Vector3D(0, 1, 0); Vector3D cross = n.cross(t); gl.glNormal3d(cross.x, cross.y, cross.z); // Texture adjustment vars double length = scale * Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) / 100 + 0.1; double height = scale; // draw the 4 points of it gl.glBegin(GL.GL_POLYGON); gl.glTexCoord2d(0, 0); gl.glVertex3d(a.x, d, a.y); gl.glTexCoord2d(0, height); gl.glVertex3d(a.x, d + 100, a.y); gl.glTexCoord2d(length, height); gl.glVertex3d(b.x, d + 100, b.y); gl.glTexCoord2d(length, 0); gl.glVertex3d(b.x, d, b.y); gl.glEnd(); }
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 }
// utility for contains takes an offset so we can check the two parts of the portal public boolean contains(int offset, int x, int y) { Edge2D e = new Edge2D(pts2d.get(offset), pts2d.get(offset + 1)); Point2D pe = e.toLineSpace(new Point(x, y)); return (pe.getX() > 0 && pe.getX() < 1 && Math.abs(pe.getY()) < EPSILON); }