<commit_before>#include "Globals.h"
#include "Application.h"
#include "PhysBody3D.h"
#include "ModuleCamera3D.h"
#include "GameObject.h"
#include "cMesh.h"

ModuleCamera3D::ModuleCamera3D(Application* app, bool start_enabled) : Module(app, start_enabled)
{
	CalculateViewMatrix();

	X = vec3(1.0f, 0.0f, 0.0f);
	Y = vec3(0.0f, 1.0f, 0.0f);
	Z = vec3(0.0f, 0.0f, 1.0f);

	Position = vec3(0.0f, 0.0f, 5.0f);
	Reference = vec3(0.0f, 0.0f, 0.0f);

	following = NULL;
}

ModuleCamera3D::~ModuleCamera3D()
{}

// -----------------------------------------------------------------
bool ModuleCamera3D::Start()
{
	MYLOG("Setting up the camera");
	bool ret = true;

	camera = true;
	return ret;
}

// -----------------------------------------------------------------
bool ModuleCamera3D::CleanUp()
{
	MYLOG("Cleaning camera");

	return true;
}

// -----------------------------------------------------------------
update_status ModuleCamera3D::Update(float dt)
{
	cameraDistance = { -20.0f, 10.0f, -20.0f };

	if (camera){
		vec3 newPos(0, 0, 0);
		float speed = 3.0f * dt;
		if (App->input->GetKey(SDL_SCANCODE_LSHIFT) == KEY_REPEAT)
			speed = 8.0f * dt;

		if (App->input->GetKey(SDL_SCANCODE_Q) == KEY_REPEAT) newPos.y -= speed * 2;
		if (App->input->GetKey(SDL_SCANCODE_E) == KEY_REPEAT) newPos.y += speed * 2;

		if (App->input->GetKey(SDL_SCANCODE_W) == KEY_REPEAT) newPos -= Z * speed * 2;
		if (App->input->GetKey(SDL_SCANCODE_S) == KEY_REPEAT) newPos += Z * speed * 2;


		if (App->input->GetKey(SDL_SCANCODE_A) == KEY_REPEAT) newPos -= X * speed * 2;
		if (App->input->GetKey(SDL_SCANCODE_D) == KEY_REPEAT) newPos += X * speed * 2;
		
		if (!ImGui::IsMouseHoveringAnyWindow())
		{
			if (App->input->GetMouseZ() == 1)
			{
				newPos -= Z * speed * 10;
			}

			if (App->input->GetMouseZ() == -1)
			{
				newPos += Z * speed * 10;
			}
		}


		if (App->input->GetKey(SDL_SCANCODE_F) == KEY_DOWN)
		{
			if (App->scene->root != nullptr)
			{
				
				Position.x = ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.maxPoint.x * 2;
				Position.y = ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.maxPoint.y * 2;
				Position.z = ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.maxPoint.z * 2;
				LookAt(vec3(((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().x, ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().y, ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().z));
		
			}
			
		}


		Position += newPos;
		Reference += newPos;

		// Mouse motion ----------------
			int dx = -App->input->GetMouseXMotion();
			int dy = -App->input->GetMouseYMotion();

		if (App->input->GetKey(SDL_SCANCODE_LALT) == KEY_REPEAT)
		{
			referenceDone = true;
		}
		if (!ImGui::IsMouseHoveringAnyWindow())
		{
			if (App->input->GetMouseButton(SDL_BUTTON_RIGHT) == KEY_REPEAT)
			{
				float Sensitivity = 0.25f;

				if (dx != 0)
				{
					float DeltaX = (float)dx * Sensitivity;

					X = rotate(X, DeltaX, vec3(0.0f, 1.0f, 0.0f));
					Y = rotate(Y, DeltaX, vec3(0.0f, 1.0f, 0.0f));
					Z = rotate(Z, DeltaX, vec3(0.0f, 1.0f, 0.0f));
				}

				if (dy != 0)
				{
					float DeltaY = (float)dy * Sensitivity;

					Y = rotate(Y, DeltaY, X);
					Z = rotate(Z, DeltaY, X);

					if (Y.y < 0.0f)
					{
						Z = vec3(0.0f, Z.y > 0.0f ? 1.0f : -1.0f, 0.0f);
						Y = cross(Z, X);
					}
				}

				//Reference = Position - (Reference - Position);
				Reference = Position - Reference;
			}
			else if (App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_REPEAT && App->input->GetKey(SDL_SCANCODE_LALT) == KEY_REPEAT)
			{
				float Sensitivity = 0.25f;

				if (((cMesh*)App->editor->selected->FindComponent(MESH)) != nullptr && referenceDone)
				{

					//Reference = vec3((*it)->aabbBox.CenterPoint().x, (*it)->aabbBox.CenterPoint().y, (*it)->aabbBox.CenterPoint().z);
					Reference = vec3(((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().x, ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().y, ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().z);
					referenceDone = false;
				}

				Position -= Reference;

				if (dx != 0)
				{
					float DeltaX = (float)dx * Sensitivity;

					X = rotate(X, DeltaX, vec3(0.0f, 1.0f, 0.0f));
					Y = rotate(Y, DeltaX, vec3(0.0f, 1.0f, 0.0f));
					Z = rotate(Z, DeltaX, vec3(0.0f, 1.0f, 0.0f));
				}<commit_msg>BUG press f without fbx loaded FIXED<commit_after>#include "Globals.h"
#include "Application.h"
#include "PhysBody3D.h"
#include "ModuleCamera3D.h"
#include "GameObject.h"
#include "cMesh.h"

ModuleCamera3D::ModuleCamera3D(Application* app, bool start_enabled) : Module(app, start_enabled)
{
	CalculateViewMatrix();

	X = vec3(1.0f, 0.0f, 0.0f);
	Y = vec3(0.0f, 1.0f, 0.0f);
	Z = vec3(0.0f, 0.0f, 1.0f);

	Position = vec3(0.0f, 0.0f, 5.0f);
	Reference = vec3(0.0f, 0.0f, 0.0f);

	following = NULL;
}

ModuleCamera3D::~ModuleCamera3D()
{}

// -----------------------------------------------------------------
bool ModuleCamera3D::Start()
{
	MYLOG("Setting up the camera");
	bool ret = true;

	camera = true;
	return ret;
}

// -----------------------------------------------------------------
bool ModuleCamera3D::CleanUp()
{
	MYLOG("Cleaning camera");

	return true;
}

// -----------------------------------------------------------------
update_status ModuleCamera3D::Update(float dt)
{
	cameraDistance = { -20.0f, 10.0f, -20.0f };

	if (camera){
		vec3 newPos(0, 0, 0);
		float speed = 3.0f * dt;
		if (App->input->GetKey(SDL_SCANCODE_LSHIFT) == KEY_REPEAT)
			speed = 8.0f * dt;

		if (App->input->GetKey(SDL_SCANCODE_Q) == KEY_REPEAT) newPos.y -= speed * 2;
		if (App->input->GetKey(SDL_SCANCODE_E) == KEY_REPEAT) newPos.y += speed * 2;

		if (App->input->GetKey(SDL_SCANCODE_W) == KEY_REPEAT) newPos -= Z * speed * 2;
		if (App->input->GetKey(SDL_SCANCODE_S) == KEY_REPEAT) newPos += Z * speed * 2;


		if (App->input->GetKey(SDL_SCANCODE_A) == KEY_REPEAT) newPos -= X * speed * 2;
		if (App->input->GetKey(SDL_SCANCODE_D) == KEY_REPEAT) newPos += X * speed * 2;
		
		if (!ImGui::IsMouseHoveringAnyWindow())
		{
			if (App->input->GetMouseZ() == 1)
			{
				newPos -= Z * speed * 10;
			}

			if (App->input->GetMouseZ() == -1)
			{
				newPos += Z * speed * 10;
			}
		}


		if (App->input->GetKey(SDL_SCANCODE_F) == KEY_DOWN)
		{
			if (App->scene->root != nullptr)
			{
				if (App->editor->selected != nullptr)
				{
					if (((cMesh*)App->editor->selected->FindComponent(MESH)) != nullptr)
					{
						Position.x = ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.maxPoint.x * 2;
						Position.y = ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.maxPoint.y * 2;
						Position.z = ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.maxPoint.z * 2;
						LookAt(vec3(((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().x, ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().y, ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().z));

					}
				}
			}		
		}


		Position += newPos;
		Reference += newPos;

		// Mouse motion ----------------
			int dx = -App->input->GetMouseXMotion();
			int dy = -App->input->GetMouseYMotion();

		if (App->input->GetKey(SDL_SCANCODE_LALT) == KEY_REPEAT)
		{
			referenceDone = true;
		}
		if (!ImGui::IsMouseHoveringAnyWindow())
		{
			if (App->input->GetMouseButton(SDL_BUTTON_RIGHT) == KEY_REPEAT)
			{
				float Sensitivity = 0.25f;

				if (dx != 0)
				{
					float DeltaX = (float)dx * Sensitivity;

					X = rotate(X, DeltaX, vec3(0.0f, 1.0f, 0.0f));
					Y = rotate(Y, DeltaX, vec3(0.0f, 1.0f, 0.0f));
					Z = rotate(Z, DeltaX, vec3(0.0f, 1.0f, 0.0f));
				}

				if (dy != 0)
				{
					float DeltaY = (float)dy * Sensitivity;

					Y = rotate(Y, DeltaY, X);
					Z = rotate(Z, DeltaY, X);

					if (Y.y < 0.0f)
					{
						Z = vec3(0.0f, Z.y > 0.0f ? 1.0f : -1.0f, 0.0f);
						Y = cross(Z, X);
					}
				}

				//Reference = Position - (Reference - Position);
				Reference = Position - Reference;
			}
			else if (App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_REPEAT && App->input->GetKey(SDL_SCANCODE_LALT) == KEY_REPEAT)
			{
				float Sensitivity = 0.25f;

				if (App->editor->selected != nullptr)
				{
					if (((cMesh*)App->editor->selected->FindComponent(MESH)) != nullptr && referenceDone)
					{

						//Reference = vec3((*it)->aabbBox.CenterPoint().x, (*it)->aabbBox.CenterPoint().y, (*it)->aabbBox.CenterPoint().z);
						Reference = vec3(((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().x, ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().y, ((cMesh*)App->editor->selected->FindComponent(MESH))->aabbBox.CenterPoint().z);
						referenceDone = false;
					}
				}

				Position -= Reference;

				if (dx != 0)
				{
					float DeltaX = (float)dx * Sensitivity;

					X = rotate(X, DeltaX, vec3(0.0f, 1.0f, 0.0f));
					Y = rotate(Y, DeltaX, vec3(0.0f, 1.0f, 0.0f));
					Z = rotate(Z, DeltaX, vec3(0.0f, 1.0f, 0.0f));
				}
{'fraction_non_alphanumeric': 0.23233099209833186, 'fraction_numerical': 0.031387181738366986, 'mean_word_length': 2.7317772317772318, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 164, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1854439', 'n_tokens_mistral': 4179, 'n_tokens_neox': 3498, 'n_words': 601}