package ru.dbotthepony.kstarbound.client.render

import org.lwjgl.glfw.GLFW.*
import ru.dbotthepony.kommons.vector.Vector2d
import ru.dbotthepony.kstarbound.client.StarboundClient

class Camera(val client: StarboundClient) {
	/**
	 * Позиция этой камеры в Starbound Unit'ах
	 */
	var pos = Vector2d()

	var pressedLeft = false
		private set

	var pressedRight = false
		private set

	var pressedUp = false
		private set

	var pressedDown = false
		private set

	fun userInput(key: Int, scancode: Int, action: Int, mods: Int) {
		when (key) {
			GLFW_KEY_LEFT -> pressedLeft = action > 0
			GLFW_KEY_RIGHT -> pressedRight = action > 0
			GLFW_KEY_UP -> pressedUp = action > 0
			GLFW_KEY_DOWN -> pressedDown = action > 0
		}
	}

	val velocity: Vector2d get() {
		var x = 0.0
		var y = 0.0

		if (pressedLeft) {
			x -= (FREEVIEW_SENS)
		}

		if (pressedRight) {
			x += (FREEVIEW_SENS)
		}

		if (pressedUp) {
			y += (FREEVIEW_SENS)
		}

		if (pressedDown) {
			y -= (FREEVIEW_SENS)
		}

		return Vector2d(x, y)
	}

	fun think(delta: Double) {
		pos += velocity * delta
	}

	companion object {
		const val FREEVIEW_SENS = 800.0
		const val MAX_ZOOM = 4f
		const val MIN_ZOOM = 0.1f
		const val ZOOM_STEP = 0.1f
	}
}
