Files
Plugin/Source/SenseGloveDebug/Private/SGDebug/SGDebugVirtualHand.cpp
T

120 lines
5.1 KiB
C++
Raw Normal View History

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2023 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 "SGDebug/SGDebugVirtualHand.h"
#include "DrawDebugHelpers.h"
#include "Kismet/GameplayStatics.h"
#include "Math/Color.h"
#include "Math/Rotator.h"
#include "Math/Vector.h"
#include "SGDebug/SGDebugGizmo.h"
void FSGDebugVirtualHand::Draw(const UWorld* World, const FVector& WristLocation, const FRotator& WristRotation,
const TArray<TArray<FVector>>& JointPositions,
const TArray<TArray<FRotator>>& JointRotations,
const FSGDebugVirtualHandSettings& Settings)
{
ensureAlwaysMsgf(Settings.DrawingMode != ESGDebugVirtualHandDrawingMode::None,
TEXT("Invalid virtual hand drawing mode!"));
const float LifeTime = UGameplayStatics::GetWorldDeltaSeconds(World) * Settings.LifeTimeModifier;
if (Settings.DrawingMode == ESGDebugVirtualHandDrawingMode::CubicJoints)
{
DrawDebugBox(World, WristLocation, Settings.CubeExtent,
WristRotation.Quaternion(), Settings.CubeColor,
Settings.bPersistentLines, LifeTime, Settings.DepthPriority, Settings.CubeThickness);
}
else if (Settings.DrawingMode == ESGDebugVirtualHandDrawingMode::GizmoJoints)
{
FSGDebugGizmo::Draw(World,
WristLocation, WristRotation,
FSGDebugGizmoSettings{
Settings.GizmoLength,
Settings.GizmoThickness,
Settings.GizmoXAxisColor,
Settings.GizmoYAxisColor,
Settings.GizmoZAxisColor,
!!Settings.bPersistentLines,
Settings.LifeTimeModifier,
Settings.DepthPriority
});
}
uint32 JointRotationsIndex = -1;
for (const TArray<FVector>& FingerJointPositions: JointPositions)
{
++JointRotationsIndex;
uint32 FingerJointRotationsIndex = -1;
const TArray<FRotator>& FingerJointRotations{JointRotations[JointRotationsIndex]};
for (const FVector& FingerJointPosition: FingerJointPositions)
{
++FingerJointRotationsIndex;
const FRotator& FingerJointRotation(FingerJointRotations[FingerJointRotationsIndex]);
const FVector DrawJointLocation(WristRotation.RotateVector(FingerJointPosition) + WristLocation);
const FQuat JointQuat{FingerJointRotation};
const FQuat WristQuat{WristRotation};
const FRotator DrawJointRotation{WristQuat * JointQuat};
if (Settings.DrawingMode == ESGDebugVirtualHandDrawingMode::CubicJoints)
{
DrawDebugBox(World, DrawJointLocation, Settings.CubeExtent,
DrawJointRotation.Quaternion(), Settings.CubeColor,
Settings.bPersistentLines, LifeTime, Settings.DepthPriority, Settings.CubeThickness);
}
else if (Settings.DrawingMode == ESGDebugVirtualHandDrawingMode::GizmoJoints)
{
FSGDebugGizmo::Draw(World,
DrawJointLocation, DrawJointRotation,
FSGDebugGizmoSettings{
Settings.GizmoLength,
Settings.GizmoThickness,
Settings.GizmoXAxisColor,
Settings.GizmoYAxisColor,
Settings.GizmoZAxisColor,
!!Settings.bPersistentLines,
Settings.LifeTimeModifier,
Settings.DepthPriority
});
}
}
}
}