package projectzombie.input;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWCursorPosCallbackI;

import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.util.gl.GlHelpers;

public class CursorPosCallback implements GLFWCursorPosCallbackI
{
	public static double mx, my;
	
	public static Vec2d getCursorPos() {
		return new Vec2d(mx, my);
	}
	
	@Override
	public void invoke(long window, double x, double y)
	{
		Main.window.setMouseVisibility(!Main.menu.keepMouse);
		InputMode.Controller = false;
		
		int wx = Main.window.getWidth();
		int wy = Main.window.getHeight();
		
		mx = (x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio();
		my = -y / Main.window.getHeight() * 20 + 10;
		
		if(!Main.menu.keepMouse) {
			return;
		}
		
		x = (x / wx - 0.5);
		y = (y / wy - 0.5);
		
		Main.menu.input.camera(true, x * 60);
		GLFW.glfwSetCursorPos(window, wx / 2, wy / 2);
	}

}
