<commit_before>#include "ComponentTransform.h"
#include "ImGui\imgui.h"
#include "ImGui\ImGuizmo.h"
#include "ComponentCamera.h"
#include "Application.h"
#include "Object.h"

ComponentTransform::ComponentTransform(aiVector3D pos, aiQuaternion rot, aiVector3D sc, GameObject* obj_parent){
	translation = float3(pos.x,pos.y,pos.z) ;
	rotation = Quat(rot.x, rot.y, rot.z, rot.w);
	scale = float3(sc.x, sc.y, sc.z);
	SetParent(obj_parent);
	comp_type = ComponentType::transform;
	matrix = float4x4::FromTRS(translation, rotation, scale);
}

ComponentTransform::ComponentTransform(float3 pos, float4 rot, float3 sc, GameObject* obj_parent) {
	translation = float3(pos.x, pos.y, pos.z);
	rotation = Quat(rot.x, rot.y, rot.z, rot.w);
	scale = float3(sc.x, sc.y, sc.z);
	SetParent(obj_parent);
	comp_type = ComponentType::transform;
	matrix = GetMatrix();
}


void ComponentTransform::UpdateComponent()
{
	matrix.Decompose(translation, rotation, scale);
	if ( App->world->GetSelectedObject() != nullptr) {
		if (App->world->GetSelectedObject()->GetTransform() == this) {
			float4x4 mat = App->camera->dummyfrustum->cam_frustum.ViewMatrix(); mat.Transpose();
			float4x4 proj = App->camera->dummyfrustum->cam_frustum.ProjectionMatrix(); proj.Transpose();
			float4x4 obj_mat =GetMatrix().Transposed();
			ImGuiIO& io = ImGui::GetIO();
			
			float4x4 temp_mat;
			ImGuizmo::SetRect(App->world->world_tex_vec.x, App->world->world_tex_vec.y, App->world->world_tex_vec.z, App->world->world_tex_vec.w);
			ImGuizmo::Manipulate(mat.ptr(), proj.ptr(), ImGuizmo::TRANSLATE, ImGuizmo::LOCAL, obj_mat.ptr());
			
			if (ImGuizmo::IsUsing())
			{
				obj_mat.Transpose();
				float3 trans, sca;
				Quat rot;
				obj_mat.Decompose(trans, rot, sca);

				translation = trans;		

				//rotation = rot;
				//matrix = float4x4::FromTRS(translation, rotation, scale);
			}
			
		
		}
	}
	
}

void ComponentTransform::ShowInspectorComponents()
{
	
	if (ImGui::CollapsingHeader("Transform", &header_open)) {
		ImGui::DragFloat3("Position", &translation[0],0.2f);

		float3 before_scale = scale;
		float3 euler = rotation.ToEulerXYZ();
		euler *= RADTODEG;
		ImGui::DragFloat3("Rotation", &euler[0], 0.2f);
		ImGui::DragFloat3("Scale", &scale[0], 0.2f,0.0001);
		ImGui::SameLine();<commit_msg>guizmos working<commit_after>#include "ComponentTransform.h"
#include "ImGui\imgui.h"
#include "ImGui\ImGuizmo.h"
#include "ComponentCamera.h"
#include "Application.h"
#include "Object.h"

ComponentTransform::ComponentTransform(aiVector3D pos, aiQuaternion rot, aiVector3D sc, GameObject* obj_parent){
	translation = float3(pos.x,pos.y,pos.z) ;
	rotation = Quat(rot.x, rot.y, rot.z, rot.w);
	scale = float3(sc.x, sc.y, sc.z);
	SetParent(obj_parent);
	comp_type = ComponentType::transform;
	matrix = float4x4::FromTRS(translation, rotation, scale);
}

ComponentTransform::ComponentTransform(float3 pos, float4 rot, float3 sc, GameObject* obj_parent) {
	translation = float3(pos.x, pos.y, pos.z);
	rotation = Quat(rot.x, rot.y, rot.z, rot.w);
	scale = float3(sc.x, sc.y, sc.z);
	SetParent(obj_parent);
	comp_type = ComponentType::transform;
	matrix = GetMatrix();
}


void ComponentTransform::UpdateComponent()
{
	matrix.Decompose(translation, rotation, scale);
	if ( App->world->GetSelectedObject() != nullptr) {
		if (App->world->GetSelectedObject()->GetTransform() == this) {
			float4x4 mat = App->camera->dummyfrustum->cam_frustum.ViewMatrix(); mat.Transpose();
			float4x4 proj = App->camera->dummyfrustum->cam_frustum.ProjectionMatrix(); proj.Transpose();
			float4x4 obj_mat =GetMatrix().Transposed();
			ImGuiIO& io = ImGui::GetIO();
			
			float4x4 temp_mat;
			ImGuizmo::SetRect(App->world->world_tex_vec.x, App->world->world_tex_vec.y, App->world->world_tex_vec.z, App->world->world_tex_vec.w);
			ImGuizmo::Manipulate(mat.ptr(), proj.ptr(), ImGuizmo::ROTATE, ImGuizmo::LOCAL, obj_mat.ptr());
			
			if (ImGuizmo::IsUsing())
			{
				obj_mat.Transpose();
				float3 trans, sca;
				Quat rot;
				obj_mat.Decompose(trans, rot, sca);


				//float4x4 new_mat = float4x4::FromTRS(trans, rot, sca);
				if (GetParent()->obj_parent != nullptr) {
					obj_mat = GetParent()->obj_parent->GetTransform()->GetMatrix().Inverted() * obj_mat;
				}
				
				obj_mat.Decompose(translation, rotation, scale);
				//rotation = rot;
				
			}
			
		
		}
	}
	
}

void ComponentTransform::ShowInspectorComponents()
{
	
	if (ImGui::CollapsingHeader("Transform", &header_open)) {
		ImGui::DragFloat3("Position", &translation[0],0.2f);

		float3 before_scale = scale;
		float3 euler = rotation.ToEulerXYZ();
		euler *= RADTODEG;
		ImGui::DragFloat3("Rotation", &euler[0], 0.2f);
		ImGui::DragFloat3("Scale", &scale[0], 0.2f,0.0001);
		ImGui::SameLine();
{'fraction_non_alphanumeric': 0.16687898089171974, 'fraction_numerical': 0.017834394904458598, 'mean_word_length': 5.063063063063063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '3490057', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1734, 'n_words': 290}