CSC8503_Advanced_Game_Technologies / CSC8503 / CSC8503Common / HingeConstraint.cpp
HingeConstraint.cpp
Raw
#include "HingeConstraint.h"
#include "GameObject.h"
#include "../../Common/Vector3.h"
#include "../../Common/Maths.h"

using namespace NCL;
using namespace CSC8503;

HingeConstraint::HingeConstraint(GameObject* a, GameObject* b)
{
	objectA = a;
	objectB = b;
}

void HingeConstraint::UpdateConstraint(float dt)
{
	Vector3 relativePos = objectA->GetTransform().GetPosition() - objectB->GetTransform().GetPosition();
	relativePos.y = 0;
	Vector3 dir = relativePos.Normalised();

	//Set rotation
	objectA->GetTransform().SetOrientation(Quaternion::EulerAnglesToQuaternion(0, -Maths::RadiansToDegrees(atan2f(dir.z, dir.x)), 0));
	objectB->GetTransform().SetOrientation(Quaternion::EulerAnglesToQuaternion(0, Maths::RadiansToDegrees(atan2f(-dir.z, dir.x)), 0));
}