Scroll Camera Works

This commit is contained in:
Arthur 2021-03-01 12:41:47 +01:00
parent 3fe3b481d8
commit 41fc399f70
3 changed files with 15 additions and 5 deletions

View File

@ -9,7 +9,7 @@ public class Main {
MainFrame frame = new MainFrame();
frame.setVisible(true);
//SwingGLCanvas canvas = new SwingGLCanvas();
SwingGLCanvas canvas = new SwingGLCanvas();
}

View File

@ -71,6 +71,6 @@ public class DrawHelper {
gl.glRasterPos3f(canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1);
gl.glColor3f(1f,1f, 1f);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18,
"x=" + canvas.camera[0] + ", y=" + canvas.camera[1] + ", z=" + canvas.camera[2]);
"x=" + canvas.camera[0] + ", y=" + canvas.camera[1] + ", z=" + canvas.camera[2]+"\n yaw = " + canvas.camera[3] + " pitch = " + canvas.camera[4] + " roll = " + canvas.camera[5]);
}
}

View File

@ -75,9 +75,19 @@ public class JoglMouseListener implements MouseListener, MouseMotionListener, Mo
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
canvas.camera[0] += e.getWheelRotation() * 0.25 * canvas.camera[3];
canvas.camera[1] += e.getWheelRotation() * 0.25 * canvas.camera[4];
if( 45 > Math.abs(canvas.camera[3]))
canvas.camera[0] += e.getWheelRotation()*Math.tan(Math.toRadians(-canvas.camera[3]))*0.25;
else
canvas.camera[0] += e.getWheelRotation()*Math.tan(Math.toRadians(canvas.camera[3]))*0.25;
if(45>Math.abs(canvas.camera[4]))
canvas.camera[1] += e.getWheelRotation()*Math.tan(Math.toRadians(canvas.camera[4]))*0.25;
else
canvas.camera[1] += e.getWheelRotation()*Math.tan(Math.toRadians(-canvas.camera[4]))*0.25;
if( 45 < Math.abs(canvas.camera[3]) || 45<Math.abs(canvas.camera[4]))
canvas.camera[2] += -e.getWheelRotation()*0.25;
else
canvas.camera[2] += e.getWheelRotation()*0.25;
canvas.camera[2] += Math.sin(e.getWheelRotation() + Math.PI / 2) * 0.25;
}
}