/*     */ package org.view;
/*     */ 
/*     */ import org.lwjgl.glfw.GLFW;
/*     */ import org.lwjgl.glfw.GLFWCursorPosCallback;
/*     */ import org.lwjgl.glfw.GLFWCursorPosCallbackI;
/*     */ import org.lwjgl.glfw.GLFWMouseButtonCallback;
/*     */ import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
/*     */ import org.lwjgl.glfw.GLFWScrollCallback;
/*     */ import org.lwjgl.glfw.GLFWScrollCallbackI;
/*     */ import org.lwjgl.glfw.GLFWVidMode;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Camera
/*     */   implements AutoCloseable
/*     */ {
/*     */   private static final float MIN_CAMERA_ZOOM = -8.0F;
/*     */   private static final float MAX_CAMERA_ZOOM = -0.5F;
/*     */   private static final float MAX_CAMERA_ROT_Y = -1.5707964F;
/*     */   private static final float MIN_CAMERA_ROT_Y = -3.1415927F;
/*     */   private GLFWCursorPosCallback cursorPosCallback;
/*     */   private GLFWMouseButtonCallback mouseButtonCallback;
/*     */   private GLFWScrollCallback scrollCallback;
/*     */   private boolean isMouseButton1Down;
/*  37 */   private float cameraZoom = -0.5F;
/*     */   
/*  39 */   private float cameraRotationX = 1.3F;
/*  40 */   private float cameraRotationY = -2.3F;
/*     */ 
/*     */   
/*     */   private float deltaRotationX;
/*     */ 
/*     */   
/*     */   private float deltaRotationY;
/*     */ 
/*     */   
/*     */   private float cameraRotationVelocityX;
/*     */   
/*     */   private float cameraRotationVelocityY;
/*     */   
/*     */   private float cameraZoomVelocity;
/*     */ 
/*     */   
/*     */   public Camera(long windowHandle) {
/*  57 */     GLFW.glfwSetMouseButtonCallback(windowHandle, (GLFWMouseButtonCallbackI)(this.mouseButtonCallback = new GLFWMouseButtonCallback()
/*     */         {
/*     */           
/*     */           public void invoke(long arg0, int arg1, int arg2, int arg3)
/*     */           {
/*  62 */             Camera.this.isMouseButton1Down = ((arg1 == 0)) ^ ((arg2 == 0));
/*     */           }
/*     */         }));
/*     */ 
/*     */     
/*  67 */     GLFW.glfwSetScrollCallback(windowHandle, (GLFWScrollCallbackI)(this.scrollCallback = new GLFWScrollCallback()
/*     */         {
/*     */           public void invoke(long window, double dx, double dy)
/*     */           {
/*  71 */             Camera.this.cameraZoomVelocity = (float)(Camera.this.cameraZoomVelocity + dy * 0.019999999552965164D);
/*     */           }
/*     */         }));
/*     */ 
/*     */     
/*  76 */     GLFW.glfwSetCursorPosCallback(windowHandle, (GLFWCursorPosCallbackI)(this.cursorPosCallback = new GLFWCursorPosCallback()
/*     */         {
/*     */           
/*     */           public void invoke(long window, double cursorX, double cursorY)
/*     */           {
/*  81 */             GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
/*     */             
/*  83 */             float rotationDifferenceX = (float)(cursorX / vidmode.width());
/*  84 */             float rotationDifferenceY = (float)(cursorY / vidmode.height());
/*     */ 
/*     */             
/*  87 */             if (Camera.this.isMouseButton1Down) {
/*     */ 
/*     */               
/*  90 */               Camera.this.cameraRotationVelocityX = (Camera.this.deltaRotationX - rotationDifferenceX) * 2.0F;
/*     */               
/*  92 */               Camera.this.cameraRotationVelocityY = (Camera.this.deltaRotationY - rotationDifferenceY) * 1.8F;
/*     */             } 
/*     */             
/*  95 */             Camera.this.deltaRotationX = rotationDifferenceX;
/*  96 */             Camera.this.deltaRotationY = rotationDifferenceY;
/*     */           }
/*     */         }));
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void update(float elapsedTime) {
/* 108 */     float timeStep = elapsedTime * 100.0F;
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 113 */     this.cameraRotationY = Math.min(Math.max(this.cameraRotationY + this.cameraRotationVelocityY * timeStep, -3.1415927F), -1.5707964F);
/* 114 */     this.cameraRotationX += this.cameraRotationVelocityX * timeStep;
/*     */ 
/*     */     
/* 117 */     this.cameraRotationVelocityX += -this.cameraRotationVelocityX * 0.08F * timeStep;
/* 118 */     this.cameraRotationVelocityY += -this.cameraRotationVelocityY * 0.05F * timeStep;
/*     */ 
/*     */     
/* 121 */     this.cameraZoom = Math.max(Math.min(this.cameraZoom + this.cameraZoomVelocity, -0.5F), -8.0F);
/*     */     
/* 123 */     this.cameraZoomVelocity += -this.cameraZoomVelocity * 0.04F * timeStep * Math.abs(2.0F / this.cameraZoom);
/*     */   }
/*     */ 
/*     */   
/*     */   public final void close() {
/* 128 */     this.cursorPosCallback.free();
/* 129 */     this.mouseButtonCallback.free();
/* 130 */     this.scrollCallback.free();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public final float getCameraZoom() {
/* 137 */     return this.cameraZoom;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public final float getCameraRotationX() {
/* 144 */     return this.cameraRotationX;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public final float getCameraRotationY() {
/* 151 */     return this.cameraRotationY;
/*     */   }
/*     */ }


/* Location:              /home/teridax/Projects/Gytebot/GYTEBOT.jar!/org/view/Camera.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */