<commit_before>#include "Application.h"
#include "ComponentCamera.h"
#include "imgui\imgui.h"
#include "DebugDraw.h"
#include "GameObject.h"
#include "ComponentTransform.h"
#include "LayerSystem.h"
#include "ResourceFileRenderTexture.h"
#include "Assets.h"

#include "ModuleWindow.h"
#include "ModuleRenderer3D.h"
#include "ModuleGOManager.h"
#include "ModuleCamera3D.h"
#include "ModuleEditor.h"

ComponentCamera::ComponentCamera(ComponentType type, GameObject* game_object) : Component(type, game_object)
{
	//Init frustrum
	aspect_ratio = (float)App->window->GetScreenWidth() / (float)App->window->GetScreenHeight();
	float vertical_fov = DegToRad(fov);
	float horizontal_fov = 2.0f*atanf(tanf(vertical_fov / 2.0f) * aspect_ratio);

	frustum.SetPerspective(horizontal_fov, vertical_fov);
	frustum.SetKind(FrustumSpaceGL, FrustumRightHanded);

	if (game_object)
	{
		float4x4 matrix = game_object->GetGlobalMatrix();
		frustum.SetPos(matrix.TranslatePart());
		frustum.SetFront(matrix.WorldZ());
		frustum.SetUp(matrix.WorldY());
	}
	else
	{
		frustum.SetPos(float3(0, 0, 0));
		frustum.SetFront(float3::unitZ);
		frustum.SetUp(float3::unitY);
	}

	frustum.SetViewPlaneDistances(near_plane, far_plane);
	frustum.SetVerticalFovAndAspectRatio(DegToRad(fov), aspect_ratio);

	color = float3(0, 0, 0); //Black to clear the screen by default

	OnTransformModified();
	App->renderer3D->AddObserver(this);

	App->camera->AddSceneCamera(this);
}

ComponentCamera::~ComponentCamera()
{
	App->renderer3D->RemoveObserver(this);
	if(render_texture)
		render_texture->Unload();
	App->camera->RemoveSceneCamera(this);
}

void ComponentCamera::PreUpdate()
{
	UpdateCameraFrustum();
}

void ComponentCamera::Update()
{
	if (App->StartInGame() == false)
		g_Debug->AddFrustum(frustum, 30.0f, g_Debug->blue, 2.0f);
}

void ComponentCamera::OnInspector(bool debug)
{
	string str = (string("Camera") + string("##") + std::to_string(uuid));
	if (ImGui::CollapsingHeader(str.c_str(), ImGuiTreeNodeFlags_DefaultOpen))
	{
		if (ImGui::IsItemClicked(1))
		{
			ImGui::OpenPopup("delete##camera");<commit_msg>Camera debug draw disabled on play<commit_after>#include "Application.h"
#include "ComponentCamera.h"
#include "imgui\imgui.h"
#include "DebugDraw.h"
#include "GameObject.h"
#include "ComponentTransform.h"
#include "LayerSystem.h"
#include "ResourceFileRenderTexture.h"
#include "Assets.h"

#include "ModuleWindow.h"
#include "ModuleRenderer3D.h"
#include "ModuleGOManager.h"
#include "ModuleCamera3D.h"
#include "ModuleEditor.h"

ComponentCamera::ComponentCamera(ComponentType type, GameObject* game_object) : Component(type, game_object)
{
	//Init frustrum
	aspect_ratio = (float)App->window->GetScreenWidth() / (float)App->window->GetScreenHeight();
	float vertical_fov = DegToRad(fov);
	float horizontal_fov = 2.0f*atanf(tanf(vertical_fov / 2.0f) * aspect_ratio);

	frustum.SetPerspective(horizontal_fov, vertical_fov);
	frustum.SetKind(FrustumSpaceGL, FrustumRightHanded);

	if (game_object)
	{
		float4x4 matrix = game_object->GetGlobalMatrix();
		frustum.SetPos(matrix.TranslatePart());
		frustum.SetFront(matrix.WorldZ());
		frustum.SetUp(matrix.WorldY());
	}
	else
	{
		frustum.SetPos(float3(0, 0, 0));
		frustum.SetFront(float3::unitZ);
		frustum.SetUp(float3::unitY);
	}

	frustum.SetViewPlaneDistances(near_plane, far_plane);
	frustum.SetVerticalFovAndAspectRatio(DegToRad(fov), aspect_ratio);

	color = float3(0, 0, 0); //Black to clear the screen by default

	OnTransformModified();
	App->renderer3D->AddObserver(this);

	App->camera->AddSceneCamera(this);
}

ComponentCamera::~ComponentCamera()
{
	App->renderer3D->RemoveObserver(this);
	if(render_texture)
		render_texture->Unload();
	App->camera->RemoveSceneCamera(this);
}

void ComponentCamera::PreUpdate()
{
	UpdateCameraFrustum();
}

void ComponentCamera::Update()
{
	if (App->StartInGame() == false && App->IsGameRunning() == false)
			g_Debug->AddFrustum(frustum, 30.0f, g_Debug->blue, 2.0f);
}

void ComponentCamera::OnInspector(bool debug)
{
	string str = (string("Camera") + string("##") + std::to_string(uuid));
	if (ImGui::CollapsingHeader(str.c_str(), ImGuiTreeNodeFlags_DefaultOpen))
	{
		if (ImGui::IsItemClicked(1))
		{
			ImGui::OpenPopup("delete##camera");
{'fraction_non_alphanumeric': 0.15479289940828403, 'fraction_numerical': 0.012307692307692308, 'mean_word_length': 6.943609022556391, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '6771176', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1546, 'n_words': 234}