/*
PolyGun

Copyright (c) 2023 kacperks https://kacperks.cubesoftware.xyz
Copyright (c) 2023 Looki2000 https://looki2000.cubesoftware.xyz
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef POLYGUN_ENGINE_CAMERA_H
#define POLYGUN_ENGINE_CAMERA_H

#include "game/renderer/camera.hpp"

namespace polygun::window {
	struct Event;
}

namespace polygun::engine {
	enum camera_movement {
		FORWARD,
		BACKWARD,
		LEFT,
		RIGHT,
		UP,
		DOWN
	};

	const float YAW         = 45.0f;
	const float PITCH       =  0.0f;
	const float SPEED       =  2.5f;
	const float SENSITIVITY =  0.1f;
	const float FOV        =  90.0f;

	class PlayerCamera final : public renderer::Camera {
	public:
		glm::vec3 m_position;
		glm::vec3 m_front;
		glm::vec2 m_movement_front;
		glm::vec3 m_up;
		glm::vec3 m_right;
		glm::vec3 m_worldup;
		float m_yaw;
		float m_pitch;
		float m_movement_speed;
		float m_mouse_sensitivity;
		float m_fov;

	public:
		PlayerCamera(glm::vec3 position = glm::vec3(-0.5f, 0.25f, -0.5f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH);
		PlayerCamera(float pos_x, float pos_y, float pos_z, float up_x, float up_y, float up_z, float yaw, float pitch);

		void update(bool reset);
		void event(const window::Event& ev);
		void process_movement(camera_movement direction, float delta_time);
		void process_mouse_movement(float x_offset, float y_offset, bool constrain_pitch = true);
		void process_mouse_scroll(float y_offset);

	private:
		void update_camera_vectors();

		float m_x;
		float m_y;
		float m_last_x;
		float m_last_y;
		bool m_first_mouse;
	};
}

#endif // POLYGUN_ENGINE_CAMERA_H
