<commit_before>#include "Globals.h"
#include "Application.h"
#include "ModuleCar.h"

#include "ModuleResourceManager.h"
#include "ModuleGOManager.h"
#include "ComponentTransform.h"
#include "Editor.h"
#include "Assets.h"
#include "GameObject.h"
#include "RaycastHit.h"

#include "ModuleInput.h"

#include "glmath.h"

#include "imgui\imgui.h"

ModuleCar::ModuleCar(const char* name, bool start_enabled) : Module(name, start_enabled)
{
}

// Destructor
ModuleCar::~ModuleCar()
{
}

// Called before render is available
bool ModuleCar::Init(Data& config)
{
	bool ret = true;
	return ret;
}

bool ModuleCar::Start()
{
	return true;
}

// Called every draw update
update_status ModuleCar::PreUpdate()
{
	if (loaded == false)
	{
		FindKartGOs();

		if (kart == nullptr || kart_trs == nullptr)
		{
			AssetFile* kartFile = App->editor->assets->FindAssetFile("/Assets/kart.fbx");
			if (kartFile != nullptr)
			{
				App->resource_manager->LoadFile(kartFile->content_path, FileType::MESH);
			}
		}
		if (track == nullptr)
		{
			AssetFile* trackFile = App->editor->assets->FindAssetFile("/Assets/track_test.fbx");
			if (trackFile != nullptr)
			{
				App->resource_manager->LoadFile(trackFile->content_path, FileType::MESH);
			}
		}

		if (light == nullptr)
		{
			light = App->go_manager->CreateGameObject(NULL);
			light->name = "Directional_Light";
			light->AddComponent(ComponentType::C_LIGHT);
			ComponentTransform* tmp = (ComponentTransform*)light->GetComponent(C_TRANSFORM);
			tmp->SetRotation(float3(50, -10, -50));
		}
		if (cam != nullptr)
		{
			if (cam->GetComponent(C_CAMERA) == nullptr)
			{
				camera = (ComponentCamera*)cam->AddComponent(C_CAMERA);
			}
		}
		loaded = true;
	}

	return UPDATE_CONTINUE;
}

update_status ModuleCar::Update()
{
	if (App->IsGameRunning())
	{
		if (firstFrameOfExecution)
		{
			App->renderer3D->SetCamera(camera);
			firstFrameOfExecution = false;
		}

		Car_Debug_Ui();

		if (kart && kart_trs)
		{
			KartLogic();
		}
	}
	else
	{
		if (firstFrameOfExecution == false)
		{
			App->renderer3D->SetCamera(App->camera->GetEditorCamera());
			FindKartGOs();
			firstFrameOfExecution = true;
		}
	}
	return UPDATE_CONTINUE;
}

update_status ModuleCar::PostUpdate()
{
	return UPDATE_CONTINUE;
}

// Called before quitting
bool ModuleCar::CleanUp()
{
	return true;
}

void ModuleCar::KartLogic()
{
	math::Ray rayF;
	rayF.dir = -kart_trs->GetGlobalMatrix().WorldY();
	rayF.pos = kart_trs->GetPosition();
	rayF.pos += kart_trs->GetGlobalMatrix().WorldY() + kart_trs->GetGlobalMatrix().WorldZ();
	RaycastHit hitF = App->go_manager->Raycast(rayF, std::vector<int>(1, track->layer));

	math::Ray rayB;
	rayB.dir = -kart_trs->GetGlobalMatrix().WorldY();
	rayB.pos = kart_trs->GetPosition();
	rayB.pos += kart_trs->GetGlobalMatrix().WorldY() - kart_trs->GetGlobalMatrix().WorldZ();
	RaycastHit hitB = App->go_manager->Raycast(rayB, std::vector<int>(1, track->layer));

	desiredUp = float3::zero;
	if ((hitF.object != nullptr && hitF.distance < 5) && (hitB.object != nullptr && hitB.distance < 5))
	{
		desiredUp = hitF.normal.Lerp(hitB.normal, 0.5f);
	}
	else if ((hitF.object != nullptr && hitF.distance < 5) && !(hitB.object != nullptr && hitB.distance < 5))
	{
		desiredUp = hitF.normal;
	}
	else if (!(hitF.object != nullptr && hitF.distance < 5) && (hitB.object != nullptr && hitB.distance < 5))
	{
		desiredUp = hitB.normal;
	}
	else
	{
		desiredUp = float3(0, 1, 0);
	}
	desiredUp.Normalize();

	float3 nextStep = kart_trs->GetGlobalMatrix().WorldY().Lerp(desiredUp, 0.1f);

	App->renderer3D->DrawLine(kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY(), kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY() + desiredUp, float4(1,0,0,1));
	App->renderer3D->DrawLine(kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY(), kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY() * 2, float4(0,0,1,1));	
	App->renderer3D->DrawLine(kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY(), kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY() + nextStep, float4(0, 1, 0, 1));

	App->renderer3D->DrawLine(kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldZ() * 2 - kart_trs->GetGlobalMatrix().WorldY() * 4, kart_trs->GetPosition() - kart_trs->GetGlobalMatrix().WorldZ() * 2 - kart_trs->GetGlobalMatrix().WorldY() * 4, float4(1, 0, 0, 1));

	//Quat normal_rot = Quat::RotateFromTo(kart_trs->GetRotation().WorldY(), nextStep);
	//kart_trs->SetRotation(kart_trs->GetRotation() * normal_rot);

	float3 pos = kart_trs->GetPosition();
	float3 newPos = pos;
	float acceleration = 0.0f;

	if (App->input->GetKey(SDL_SCANCODE_W) == KEY_REPEAT || App->input->GetJoystickButton(0, JOY_BUTTON::A))
	{
		if (speed < -0.01f)
		{
			if (speed < -brakePower * time->DeltaTime())
			{<commit_msg>Still car<commit_after>#include "Globals.h"
#include "Application.h"
#include "ModuleCar.h"

#include "ModuleResourceManager.h"
#include "ModuleGOManager.h"
#include "ComponentTransform.h"
#include "Editor.h"
#include "Assets.h"
#include "GameObject.h"
#include "RaycastHit.h"

#include "ModuleInput.h"

#include "glmath.h"

#include "imgui\imgui.h"

ModuleCar::ModuleCar(const char* name, bool start_enabled) : Module(name, start_enabled)
{
}

// Destructor
ModuleCar::~ModuleCar()
{
}

// Called before render is available
bool ModuleCar::Init(Data& config)
{
	bool ret = true;
	return ret;
}

bool ModuleCar::Start()
{
	return true;
}

// Called every draw update
update_status ModuleCar::PreUpdate()
{
	if (loaded == false)
	{
		FindKartGOs();

		if (kart == nullptr || kart_trs == nullptr)
		{
			AssetFile* kartFile = App->editor->assets->FindAssetFile("/Assets/kart.fbx");
			if (kartFile != nullptr)
			{
				App->resource_manager->LoadFile(kartFile->content_path, FileType::MESH);
			}
		}
		if (track == nullptr)
		{
			AssetFile* trackFile = App->editor->assets->FindAssetFile("/Assets/track_test.fbx");
			if (trackFile != nullptr)
			{
				App->resource_manager->LoadFile(trackFile->content_path, FileType::MESH);
			}
		}

		if (light == nullptr)
		{
			light = App->go_manager->CreateGameObject(NULL);
			light->name = "Directional_Light";
			light->AddComponent(ComponentType::C_LIGHT);
			ComponentTransform* tmp = (ComponentTransform*)light->GetComponent(C_TRANSFORM);
			tmp->SetRotation(float3(50, -10, -50));
		}
		if (cam != nullptr)
		{
			if (cam->GetComponent(C_CAMERA) == nullptr)
			{
				camera = (ComponentCamera*)cam->AddComponent(C_CAMERA);
			}
		}
		loaded = true;
	}

	return UPDATE_CONTINUE;
}

update_status ModuleCar::Update()
{
	if (App->IsGameRunning())
	{
		if (firstFrameOfExecution)
		{
			App->renderer3D->SetCamera(camera);
			firstFrameOfExecution = false;
		}

		Car_Debug_Ui();

		if (kart && kart_trs)
		{
			KartLogic();
		}
	}
	else
	{
		if (firstFrameOfExecution == false)
		{
			App->renderer3D->SetCamera(App->camera->GetEditorCamera());
			FindKartGOs();
			firstFrameOfExecution = true;
		}
	}
	return UPDATE_CONTINUE;
}

update_status ModuleCar::PostUpdate()
{
	return UPDATE_CONTINUE;
}

// Called before quitting
bool ModuleCar::CleanUp()
{
	return true;
}

void ModuleCar::KartLogic()
{
	float3 pos = kart_trs->GetPosition();
	float3 newPos = pos;

	math::Ray rayF;
	rayF.dir = -kart_trs->GetGlobalMatrix().WorldY();
	rayF.pos = kart_trs->GetPosition();
	rayF.pos += kart_trs->GetGlobalMatrix().WorldY() + kart_trs->GetGlobalMatrix().WorldZ();
	RaycastHit hitF = App->go_manager->Raycast(rayF, std::vector<int>(1, track->layer));

	math::Ray rayB;
	rayB.dir = -kart_trs->GetGlobalMatrix().WorldY();
	rayB.pos = kart_trs->GetPosition();
	rayB.pos += kart_trs->GetGlobalMatrix().WorldY() - kart_trs->GetGlobalMatrix().WorldZ();
	RaycastHit hitB = App->go_manager->Raycast(rayB, std::vector<int>(1, track->layer));

	desiredUp = float3::zero;
	if ((hitF.object != nullptr && hitF.distance < 5) && (hitB.object != nullptr && hitB.distance < 5))
	{
		desiredUp = hitF.normal.Lerp(hitB.normal, 0.5f);
	}
	else if ((hitF.object != nullptr && hitF.distance < 5) && !(hitB.object != nullptr && hitB.distance < 5))
	{
		desiredUp = hitF.normal;
	}
	else if (!(hitF.object != nullptr && hitF.distance < 5) && (hitB.object != nullptr && hitB.distance < 5))
	{
		desiredUp = hitB.normal;
	}
	else
	{
		desiredUp = float3(0, 1, 0);
	}
	desiredUp.Normalize();

	float3 nextStep = kart_trs->GetGlobalMatrix().WorldY().Lerp(desiredUp, 4.0f * time->DeltaTime());

	App->renderer3D->DrawLine(kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY(), kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY() + desiredUp, float4(1,0,0,1));
	App->renderer3D->DrawLine(kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY(), kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY() * 2, float4(0,0,1,1));	
	App->renderer3D->DrawLine(kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY(), kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldY() + nextStep, float4(0, 1, 0, 1));

	App->renderer3D->DrawLine(kart_trs->GetPosition() + kart_trs->GetGlobalMatrix().WorldZ() * 2 - kart_trs->GetGlobalMatrix().WorldY() * 4, kart_trs->GetPosition() - kart_trs->GetGlobalMatrix().WorldZ() * 2 - kart_trs->GetGlobalMatrix().WorldY() * 4, float4(1, 0, 0, 1));

	float3 __tmp = kart_trs->GetRotation().WorldY();

	Quat normal_rot = Quat::RotateFromTo(kart_trs->GetRotation().WorldY(), nextStep);
	float aaa = normal_rot.Angle();
	if (normal_rot.Angle() > 0.01f)
	{
		kart_trs->SetRotation(kart_trs->GetRotation() * normal_rot);
	}

	float acceleration = 0.0f;

	if (App->input->GetKey(SDL_SCANCODE_W) == KEY_REPEAT || App->input->GetJoystickButton(0, JOY_BUTTON::A))
	{
		if (speed < -0.01f)
		{
			if (speed < -brakePower * time->DeltaTime())
			{
{'fraction_non_alphanumeric': 0.17731448033852823, 'fraction_numerical': 0.01362369697595211, 'mean_word_length': 4.809352517985611, 'pattern_counts': {'":': 0, '<': 23, '<?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': '1298222', 'n_tokens_mistral': 3964, 'n_tokens_neox': 3703, 'n_words': 585}