Skip to content

Commit

Permalink
Finalize project, remove unnecessary files
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostFoxSledgehammer committed Jun 4, 2021
1 parent 1926511 commit f3e1ca6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 48 deletions.
11 changes: 8 additions & 3 deletions src/main/java/PanoViewer/PanoViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import PanoViewer.Utils.IOUtils;
import PanoViewer.gui.PhotoSphere;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -22,18 +23,22 @@ public class PanoViewer {
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length < 1) {
return;
}
BufferedImage img;
try {
img = ImageIO.read(IOUtils.getFileFromResourceAsStream("test.jpg"));
img = ImageIO.read(new File(args[0]));
} catch (IOException ex) {
Logger.getLogger(PanoViewer.class.getName()).log(Level.SEVERE, null, ex);
return;
}
JFrame jFrame = new JFrame();
jFrame.setSize(600, 600);
jFrame.add(PhotoSphere.getInstance());
PhotoSphere ps = new PhotoSphere();
jFrame.add(ps);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setVisible(true);
PhotoSphere.getInstance().replaceImage(img);
ps.replaceImage(img);
}
}
19 changes: 0 additions & 19 deletions src/main/java/PanoViewer/Utils/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
*/
package PanoViewer.Utils;

import java.io.File;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
Expand All @@ -27,18 +22,4 @@ public static InputStream getFileFromResourceAsStream(String fileName) {
return inputStream;
}
}

public static File getFileFromResource(String fileName) {
File file = null;
Class currentClass = new Object() {
}.getClass().getEnclosingClass();
ClassLoader classLoader = currentClass.getClassLoader();
URL resource = classLoader.getResource(fileName);
try {
file = new File(resource.toURI());
} catch (URISyntaxException ex) {
Logger.getLogger(currentClass.getName()).log(Level.SEVERE, null, ex);
}
return file;
}
}
1 change: 0 additions & 1 deletion src/main/java/PanoViewer/Utils/imageutils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.awt.image.BufferedImage;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;

Expand Down
45 changes: 20 additions & 25 deletions src/main/java/PanoViewer/gui/PhotoSphere.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class PhotoSphere extends GLCanvas implements GLEventListener {
private final Vector3f sphereLoc;
private int numVerts;
private final ZoomPanLis listener;
private static PhotoSphere instance;
private int fov;
private static final int MAX_FOV = 110;
private static final int MIN_FOV = 20;
Expand All @@ -61,49 +60,29 @@ public class PhotoSphere extends GLCanvas implements GLEventListener {
private TextureData textureData;
private boolean updateImage;

private PhotoSphere() {
public PhotoSphere() {
addGLEventListener(this);
camera = new Camera();
sphereLoc = new Vector3f(0, 0, 0);
listener = new ZoomPanLis() {
@Override
void rotate(double yaw, double pitch) {
float newYaw = (float) (yaw * fov / IDEAL_FOV);
float newPitch = (float) (pitch * fov / IDEAL_FOV);
camera.rotate(newYaw, newPitch);
vMat = camera.getViewMatrix();
instance.repaint();
rotateCamera(yaw, pitch);
}

@Override
void zoom(int zoomAmount) {
fov += zoomAmount;
fov = Math.min(fov, MAX_FOV);
fov = Math.max(fov, MIN_FOV);
pMat.setPerspective((float) Math.toRadians(fov), aspect, 0.1f, 1000.0f);
instance.repaint();
zoomCamera(zoomAmount);
}
};
enableZoomPan();
fov = IDEAL_FOV;
}

public static PhotoSphere getInstance() {
if (instance == null) {
instance = new PhotoSphere();
}
return instance;
}

public static void destroyInstance() {
instance.destroy();
instance = null;
}

public void replaceImage(BufferedImage image) {
textureData = getTextureData(image);
updateImage = true;
instance.repaint();
repaint();
}

private void replaceTextureData(GL4 gl) {
Expand Down Expand Up @@ -225,4 +204,20 @@ private void disableZoomPan() {
this.removeMouseMotionListener(listener);
this.removeMouseWheelListener(listener);
}

public void rotateCamera(double yaw, double pitch) {
float newYaw = (float) (yaw * fov / IDEAL_FOV);
float newPitch = (float) (pitch * fov / IDEAL_FOV);
camera.rotate(newYaw, newPitch);
vMat = camera.getViewMatrix();
repaint();
}

private void zoomCamera(int zoomAmount) {
fov += zoomAmount;
fov = Math.min(fov, MAX_FOV);
fov = Math.max(fov, MIN_FOV);
pMat.setPerspective((float) Math.toRadians(fov), aspect, 0.1f, 1000.0f);
repaint();
}
}
Binary file removed src/main/resources/earth.jpg
Binary file not shown.
Binary file removed src/main/resources/earth2048.bmp
Binary file not shown.
Binary file removed src/main/resources/test.jpg
Binary file not shown.

0 comments on commit f3e1ca6

Please sign in to comment.