2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2019-10-01 20:41:42 -04:00
|
|
|
|
|
|
|
|
#include "BaseGizmos/AxisSources.h"
|
|
|
|
|
#include "Components/SceneComponent.h"
|
|
|
|
|
|
|
|
|
|
FVector UGizmoComponentAxisSource::GetOrigin() const
|
|
|
|
|
{
|
|
|
|
|
const FTransform& WorldTransform = Component->GetComponentToWorld();
|
|
|
|
|
return WorldTransform.GetLocation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FVector UGizmoComponentAxisSource::GetDirection() const
|
|
|
|
|
{
|
|
|
|
|
const FTransform& WorldTransform = Component->GetComponentToWorld();
|
|
|
|
|
FVector Axis(0, 0, 0);
|
|
|
|
|
Axis[FMath::Clamp(AxisIndex, 0, 2)] = 1.0;
|
|
|
|
|
if (bLocalAxes)
|
|
|
|
|
{
|
|
|
|
|
return WorldTransform.GetRotation().RotateVector(Axis);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Axis;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UGizmoComponentAxisSource::GetTangentVectors(FVector& TangentXOut, FVector& TangentYOut) const
|
|
|
|
|
{
|
2021-01-14 19:07:52 -04:00
|
|
|
// Note that in giving the tangent vectors, we need to give them in an order that
|
|
|
|
|
// preserves the handedness of our coordinate system so that we can use the function
|
|
|
|
|
// for generating planes in which we can measure rotation angles about the input axis.
|
|
|
|
|
// So, TangentXOut, TangentYOut, and Input(Z) should give a left-handed frame (since
|
|
|
|
|
// unreal is left handed).
|
|
|
|
|
|
2019-10-01 20:41:42 -04:00
|
|
|
const FTransform& WorldTransform = Component->GetComponentToWorld();
|
|
|
|
|
TangentXOut = FVector(0, 1, 0);
|
|
|
|
|
TangentYOut = FVector(0, 0, 1);
|
|
|
|
|
int Index = FMath::Clamp(AxisIndex, 0, 2);
|
|
|
|
|
if (Index == 1)
|
|
|
|
|
{
|
2021-01-14 19:07:52 -04:00
|
|
|
TangentXOut = FVector(0, 0, 1);
|
|
|
|
|
TangentYOut = FVector(1, 0, 0);
|
2019-10-01 20:41:42 -04:00
|
|
|
}
|
|
|
|
|
else if (Index == 2)
|
|
|
|
|
{
|
|
|
|
|
TangentXOut = FVector(1, 0, 0);
|
|
|
|
|
TangentYOut = FVector(0, 1, 0);
|
|
|
|
|
}
|
|
|
|
|
if (bLocalAxes)
|
|
|
|
|
{
|
|
|
|
|
TangentXOut = WorldTransform.GetRotation().RotateVector(TangentXOut);
|
|
|
|
|
TangentYOut = WorldTransform.GetRotation().RotateVector(TangentYOut);
|
|
|
|
|
}
|
|
|
|
|
}
|