<commit_before>//#include <pch.h>
#include "Physics.h"
#include <include/havok.h>

#include <Component/AABB.h>
#include <Component/Transform.h>
#include <Core/GameObject.h>

#include <Manager/Manager.h>
#include <Manager/SceneManager.h>
#include <Manager/PhysicsManager.h>
#include <Manager/HavokCore.h>

Physics::Physics(GameObject *parent) :
	parent(parent)
{
}

Physics::Physics(Physics &physics)
{

}

Physics::~Physics() {
	RemoveFromWorld();
}

void Physics::LoadHavokFile(const char *fileName) {
	body = Manager::Physics->GetFirstRigidBody(fileName);
}

void Physics::Update() {
	// Test if was removed from world and skip updating
	if (body->getReferenceCount() == 0) {
		Manager::Scene->RemoveObject(this->parent);
		return;
	}
	if (body->isActive()) {
		float q[4];
		float p[4];
		hkVector4 pos = body->getPosition();
		hkQuaternionf qrot = body->getRotation();
		memcpy(q, &qrot.m_vec, 4 * sizeof(float));
		memcpy(p, &pos, 4 * sizeof(float));

		parent->transform->rotationQ = glm::quat(q[3], q[0], q[1], q[2]);
		parent->transform->position = glm::vec3(p[0], p[1], p[2]);
		parent->transform->Update();
	}
}

void Physics::AddToWorld() {
	Transform *T = parent->transform;
	hkVector4 pos(T->position.x, T->position.y, T->position.z, 0);
	hkQuaternion rot(T->rotationQ.x, T->rotationQ.y, T->rotationQ.z, T->rotationQ.w);
	body->setPositionAndRotation(pos, rot);
	Manager::Havok->AddIntoTheWorld(body);
}

void Physics::RemoveFromWorld() {
	if (body->isAddedToWorld()) {
		Manager::Havok->RemoveFromTheWorld(this->body);<commit_msg>code re-factoring<commit_after>//#include <pch.h>
#include "Physics.h"
#include <include/havok.h>

#include <Component/AABB.h>
#include <Component/Transform.h>
#include <Core/GameObject.h>

#include <Manager/Manager.h>
#include <Manager/SceneManager.h>
#include <Manager/PhysicsManager.h>
#include <Manager/HavokCore.h>

Physics::Physics(GameObject *parent) :
	parent(parent)
{
}

Physics::Physics(Physics &physics)
{

}

Physics::~Physics() {
	RemoveFromWorld();
}

void Physics::LoadHavokFile(const char *fileName) {
	body = Manager::Physics->GetFirstRigidBody(fileName);
}

void Physics::Update() {
	// Test if was removed from world and skip updating
	if (body->getReferenceCount() == 0) {
		Manager::Scene->RemoveObject(this->parent);
		return;
	}
	if (body->isActive()) {
		float val[4];
		hkVector4 pos = body->getPosition();
		memcpy(val, &pos, 4 * sizeof(float));
		parent->transform->position = glm::vec3(val[0], val[1], val[2]);

		hkQuaternionf qrot = body->getRotation();
		memcpy(val, &qrot.m_vec, 4 * sizeof(float));
		parent->transform->rotationQ = glm::quat(val[3], val[0], val[1], val[2]);

		parent->transform->Update();
	}
}

void Physics::AddToWorld() {
	Transform *T = parent->transform;
	hkVector4 pos(T->position.x, T->position.y, T->position.z, 0);
	hkQuaternion rot(T->rotationQ.x, T->rotationQ.y, T->rotationQ.z, T->rotationQ.w);
	body->setPositionAndRotation(pos, rot);
	Manager::Havok->AddIntoTheWorld(body);
}

void Physics::RemoveFromWorld() {
	if (body->isAddedToWorld()) {
		Manager::Havok->RemoveFromTheWorld(this->body);
{'fraction_non_alphanumeric': 0.18780251694094868, 'fraction_numerical': 0.010003226847370119, 'mean_word_length': 5.595744680851064, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 73, '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': '5197710', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1155, 'n_words': 202}