2022-09-23 19:57:29 +08:00
|
|
|
/************************************************************************************//*!
|
|
|
|
\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));
|
|
|
|
}
|
2022-10-24 20:07:59 +08:00
|
|
|
Quaternion Transform::LocalRotation::get()
|
2022-09-23 19:57:29 +08:00
|
|
|
{
|
2022-10-24 20:07:59 +08:00
|
|
|
return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation());
|
2022-09-23 19:57:29 +08:00
|
|
|
}
|
2022-10-24 20:07:59 +08:00
|
|
|
void Transform::LocalRotation::set(Quaternion val)
|
2022-09-23 19:57:29 +08:00
|
|
|
{
|
2022-10-24 20:07:59 +08:00
|
|
|
GetNativeComponent()->SetLocalOrientation(Convert::ToNative(val));
|
2022-09-23 19:57:29 +08:00
|
|
|
}
|
|
|
|
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));
|
|
|
|
}
|
2022-10-24 20:07:59 +08:00
|
|
|
Quaternion Transform::GlobalRotation::get()
|
2022-09-23 19:57:29 +08:00
|
|
|
{
|
2022-10-24 20:07:59 +08:00
|
|
|
return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation());
|
2022-09-23 19:57:29 +08:00
|
|
|
}
|
2022-10-24 20:07:59 +08:00
|
|
|
void Transform::GlobalRotation::set(Quaternion val)
|
2022-09-23 19:57:29 +08:00
|
|
|
{
|
2022-10-24 20:07:59 +08:00
|
|
|
GetNativeComponent()->SetWorldOrientation(Convert::ToNative(val));
|
2022-09-23 19:57:29 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|