108 lines
4.1 KiB
C++
108 lines
4.1 KiB
C++
|
/************************************************************************************//*!
|
||
|
\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));
|
||
|
}
|
||
|
Vector3 Transform::LocalRotation::get()
|
||
|
{
|
||
|
return Convert::ToCLI(GetNativeComponent()->GetLocalRotation());
|
||
|
}
|
||
|
void Transform::LocalRotation::set(Vector3 val)
|
||
|
{
|
||
|
GetNativeComponent()->SetLocalPosition(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));
|
||
|
}
|
||
|
Vector3 Transform::GlobalRotation::get()
|
||
|
{
|
||
|
return Convert::ToCLI(GetNativeComponent()->GetWorldRotation());
|
||
|
}
|
||
|
void Transform::GlobalRotation::set(Vector3 val)
|
||
|
{
|
||
|
GetNativeComponent()->SetWorldRotation(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);
|
||
|
}
|
||
|
}
|