-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGenerateTraceLibrary.h
More file actions
82 lines (68 loc) · 2.35 KB
/
Copy pathGenerateTraceLibrary.h
File metadata and controls
82 lines (68 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/BoxComponent.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GenerateTraceLibrary.generated.h"
/**
*
*/
UCLASS(meta=(BlueprintThreadSafe, ScriptName = "Generate Trace Library"))
class CHARMINGCRAFT_API UGenerateTraceLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/*!
* Get the box low 4 conner
* @param Box The Box you wan to get its 4 conner
* @return The vector contain 4 conner location
*/
UFUNCTION(BlueprintCallable, Category = "Vector")
static TArray<FVector> GetBoxCornerVector(UBoxComponent* Box)
{
FVector BoxOrigin = Box->GetComponentLocation();
FVector BoxExtent = Box->GetScaledBoxExtent();
FRotator BoxRotation = Box->GetRelativeRotation();
TArray<FVector> Corners;
Corners.SetNum(4);
// Transform BoxExtent to local space rotation
FQuat QuatRotation = FQuat(BoxRotation);
// Bottom front right corner
Corners[0] = BoxOrigin + QuatRotation.RotateVector(FVector(BoxExtent.X, BoxExtent.Y, -BoxExtent.Z));
// Bottom front left corner
Corners[1] = BoxOrigin + QuatRotation.RotateVector(FVector(-BoxExtent.X, BoxExtent.Y, -BoxExtent.Z));
// Bottom back left corner
Corners[2] = BoxOrigin + QuatRotation.RotateVector(FVector(-BoxExtent.X, -BoxExtent.Y, -BoxExtent.Z));
// Bottom back right corner
Corners[3] = BoxOrigin + QuatRotation.RotateVector(FVector(BoxExtent.X, -BoxExtent.Y, -BoxExtent.Z));
return Corners;
}
UFUNCTION(BlueprintCallable, Category = "Array")
static bool AreAllElementsTheSame(const TArray<float>& Array)
{
if (Array.Num() <= 1)
{
// 如果数组为空或只有一个元素,则认为所有元素都是“相同的”
return true;
}
// 获取数组的第一个元素作为比较基准
const float& FirstElement = Array[0];
// 从第二个元素开始遍历数组
for (int32 Index = 1; Index < Array.Num(); ++Index)
{
if (!(Array[Index] == FirstElement))
{
// 如果发现有不同的元素,则立即返回false
return false;
}
}
// 如果所有元素都与第一个元素相同,则返回true
return true;
}
static float GetRandomYawRight()
{
const int32 RandomRotationIndex = FMath::RandRange(0, 3);
const float RandomYaw = RandomRotationIndex * 90.0f;
return RandomYaw;
}
};