/************************************************************************************//*! \file Transform.cxx \author Tng Kah Wei, kahwei.tng, 390009620 \par email: kahwei.tng\@digipen.edu \date Sep 23, 2022 \brief Contains the definition of the functions of the managed Transform class. Note: This file is written in C++17/CLI. Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or disclosure of this file or its contents without the prior written consent of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ // Precompiled Headers #include "SHpch.h" // Primary Header #include "Transform.hxx" namespace SHADE { /*---------------------------------------------------------------------------------*/ /* Properties */ /*---------------------------------------------------------------------------------*/ Vector3 Transform::LocalPosition::get() { return Convert::ToCLI(GetNativeComponent()->GetLocalPosition()); } void Transform::LocalPosition::set(Vector3 val) { GetNativeComponent()->SetLocalPosition(Convert::ToNative(val)); } Quaternion Transform::LocalRotation::get() { return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation()); } void Transform::LocalRotation::set(Quaternion val) { GetNativeComponent()->SetLocalOrientation(Convert::ToNative(val)); } Vector3 Transform::LocalScale::get() { return Convert::ToCLI(GetNativeComponent()->GetLocalScale()); } void Transform::LocalScale::set(Vector3 val) { GetNativeComponent()->SetLocalScale(Convert::ToNative(val)); } Vector3 Transform::GlobalPosition::get() { return Convert::ToCLI(GetNativeComponent()->GetWorldPosition()); } void Transform::GlobalPosition::set(Vector3 val) { GetNativeComponent()->SetWorldPosition(Convert::ToNative(val)); } Quaternion Transform::GlobalRotation::get() { return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation()); } void Transform::GlobalRotation::set(Quaternion val) { GetNativeComponent()->SetWorldOrientation(Convert::ToNative(val)); } Vector3 Transform::GlobalScale::get() { return Convert::ToCLI(GetNativeComponent()->GetWorldScale()); } void Transform::GlobalScale::set(Vector3 val) { GetNativeComponent()->SetWorldScale(Convert::ToNative(val)); } Transform^ Transform::Parent::get() { auto node = SHSceneManager::GetCurrentSceneGraph().GetNode(owner.GetEntity()); if (!node) throw gcnew System::InvalidOperationException("[Transform] Unable to retrieve SceneGraphNode for an Entity."); const auto PARENT = node->GetParent(); return PARENT ? gcnew Transform(PARENT->GetEntityID()) : nullptr; } /*---------------------------------------------------------------------------------*/ /* Constructors */ /*---------------------------------------------------------------------------------*/ Transform::Transform(Entity entity) : Component(entity) {} /*---------------------------------------------------------------------------------*/ /* Usage Functions */ /*---------------------------------------------------------------------------------*/ void Transform::SetParent(Transform^ parent, bool worldPositionStays) { auto& sceneGraph = SHSceneManager::GetCurrentSceneGraph(); auto node = sceneGraph.GetNode(owner.GetEntity()); if (!node) throw gcnew System::InvalidOperationException("[Transform] Unable to retrieve SceneGraphNode for an Entity."); if (parent) node->SetParent(sceneGraph.GetNode(parent->owner.GetEntity())); else sceneGraph.SetParent(parent->owner.GetEntity(), nullptr); } }