Files
Plugin/Source/SenseGloveUtils/Private/SGUtils/SGArrayUtils.cpp
T

88 lines
2.7 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2022 SenseGlove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
*
*
*/
#include "SGUtils/SGArrayUtils.h"
TArray<FRotator> FSGArrayUtils::QuatsToRotators(const TArray<FQuat>& QuatsArray)
{
TArray<FRotator> RotatorsArray;
for (const FQuat& Quat: QuatsArray)
{
FRotator Rotator{Quat.Rotator()};
RotatorsArray.Add(MoveTemp(Rotator));
}
return MoveTemp(RotatorsArray);
}
TArray<TArray<FRotator>> FSGArrayUtils::QuatsToRotators(const TArray<TArray<FQuat>>& QuatsNestedArray)
{
TArray<TArray<FRotator>> RotatorsNestedArray;
for (const TArray<FQuat>& InnerQuatsArray: QuatsNestedArray)
{
TArray<FRotator> InnerRotatorsArray{QuatsToRotators(InnerQuatsArray)};
RotatorsNestedArray.Add(MoveTemp(InnerRotatorsArray));
}
return MoveTemp(RotatorsNestedArray);
}
TArray<FQuat> FSGArrayUtils::RotatorsToQuats(const TArray<FRotator>& RotatorsArray)
{
TArray<FQuat> QuatsArray;
for (const FRotator& Rotator: RotatorsArray)
{
FQuat Quat{Rotator.Quaternion()};
QuatsArray.Add(MoveTemp(Quat));
}
return MoveTemp(QuatsArray);
}
TArray<TArray<FQuat>> FSGArrayUtils::RotatorsToQuats(const TArray<TArray<FRotator>>& RotatorsNestedArray)
{
TArray<TArray<FQuat>> QuatsNestedArray;
for (const TArray<FRotator>& RotatorsInnerArray: RotatorsNestedArray)
{
TArray<FQuat> InnerQuatsArray{RotatorsToQuats(RotatorsInnerArray)};
QuatsNestedArray.Add(MoveTemp(InnerQuatsArray));
}
return MoveTemp(QuatsNestedArray);
}