Skip to content

Commit 8be7703

Browse files
committed
Initial commit
0 parents  commit 8be7703

File tree

5 files changed

+528
-0
lines changed

5 files changed

+528
-0
lines changed

BlueprintRotationLibrary.cpp

Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
#include "BlueprintRotationLibrary.h"
2+
3+
FQuat UBlueprintRotationLibrary::Lerp(const FQuat& A, const FQuat& B, const float& Alpha)
4+
{
5+
return FMath::Lerp(A, B, Alpha);
6+
}
7+
8+
FQuat UBlueprintRotationLibrary::FastLerp(const FQuat& A, const FQuat& B, const float& Alpha)
9+
{
10+
return FQuat::FastLerp(A, B, Alpha);
11+
}
12+
13+
FQuat UBlueprintRotationLibrary::BiLerp(const FQuat& P00, const FQuat& P10, const FQuat& P01, const FQuat& P11, const float & FracX, const float & FracY)
14+
{
15+
return FMath::BiLerp(P00, P10, P01, P11, FracX, FracY);
16+
}
17+
18+
FQuat UBlueprintRotationLibrary::FastBiLerp(const FQuat& P00, const FQuat& P10, const FQuat& P01, const FQuat& P11, const float & FracX, const float & FracY)
19+
{
20+
return FQuat::FastBilerp(P00, P10, P01, P11, FracX, FracY);
21+
}
22+
23+
FQuat UBlueprintRotationLibrary::Slerp(const FQuat& A, const FQuat& B, const float & Slerp)
24+
{
25+
return FQuat::Slerp(A, B, Slerp);
26+
}
27+
28+
FQuat UBlueprintRotationLibrary::Slerp_NotNormalized(const FQuat& A, const FQuat& B, const float & Slerp)
29+
{
30+
return FQuat::Slerp_NotNormalized(A, B, Slerp);
31+
}
32+
33+
float UBlueprintRotationLibrary::Dot(const FQuat& A, const FQuat& B)
34+
{
35+
return A | B;
36+
}
37+
38+
FQuat UBlueprintRotationLibrary::VectorToOrientationQuat(const FVector Vector)
39+
{
40+
return Vector.ToOrientationQuat();
41+
}
42+
43+
FRotator UBlueprintRotationLibrary::VectorToOrientationRotator(const FVector Vector)
44+
{
45+
return Vector.ToOrientationRotator();
46+
}
47+
48+
FQuat UBlueprintRotationLibrary::RotatorToQuat(const FRotator Rotator)
49+
{
50+
return Rotator.Quaternion();
51+
}
52+
53+
FRotator UBlueprintRotationLibrary::QuatToRotator(const FQuat& Quat)
54+
{
55+
return FRotator(Quat);
56+
}
57+
58+
float UBlueprintRotationLibrary::AngleBetweenDirectionVectorsRad(FVector A, FVector B)
59+
{
60+
A.Normalize(1.0f);
61+
B.Normalize(1.0f);
62+
63+
return FGenericPlatformMath::Acos(FVector::DotProduct(A, B));
64+
}
65+
66+
float UBlueprintRotationLibrary::AngleBetweenDirectionVectorsDeg(FVector A, FVector B)
67+
{
68+
A.Normalize(1.0f);
69+
B.Normalize(1.0f);
70+
71+
return FMath::RadiansToDegrees(FGenericPlatformMath::Acos(FVector::DotProduct(A, B)));
72+
}
73+
74+
float UBlueprintRotationLibrary::AngleBetweenQuatsRad(FQuat A, FQuat B)
75+
{
76+
return A.AngularDistance(B);
77+
}
78+
79+
float UBlueprintRotationLibrary::AngleBetweenQuatsDeg(FQuat A, FQuat B)
80+
{
81+
return FMath::RadiansToDegrees(A.AngularDistance(B));
82+
}
83+
84+
FQuat UBlueprintRotationLibrary::EulerDegToQuat(const FVector Euler)
85+
{
86+
return FQuat::MakeFromEuler(Euler);
87+
}
88+
89+
FVector UBlueprintRotationLibrary::QuatToEulerDeg(const FQuat& Quat)
90+
{
91+
return Quat.Euler();
92+
}
93+
94+
FQuat UBlueprintRotationLibrary::QuatPlusQuat(const FQuat& A, const FQuat& B)
95+
{
96+
return A + B;
97+
}
98+
99+
FQuat UBlueprintRotationLibrary::QuatMinusQuat(const FQuat& A, const FQuat& B)
100+
{
101+
return A - B;
102+
}
103+
104+
FQuat UBlueprintRotationLibrary::QuatMultiplyQuat(const FQuat& A, const FQuat& B)
105+
{
106+
return A * B;
107+
}
108+
109+
FQuat UBlueprintRotationLibrary::QuatMultiplyFloatScale(const FQuat& A, const float B)
110+
{
111+
return A * B;
112+
}
113+
114+
FQuat UBlueprintRotationLibrary::QuatDivFloatScale(const FQuat& A, const float B)
115+
{
116+
return A / B;
117+
}
118+
119+
bool UBlueprintRotationLibrary::AreQuatsEqual(const FQuat& A, const FQuat& B)
120+
{
121+
return A == B;
122+
}
123+
124+
FString UBlueprintRotationLibrary::QuatToString(const FQuat& Quat)
125+
{
126+
return FString::Printf(TEXT("X=%f,Y=%f,Z=%f,W=%f"), Quat.X, Quat.Y, Quat.Z, Quat.W);
127+
}
128+
129+
void UBlueprintRotationLibrary::AddActorLocalRotation(AActor* Actor, const FQuat& Quat, bool bSweep, FHitResult& OutSweepHitResult, bool bTeleport)
130+
{
131+
ETeleportType Teleport;
132+
133+
if (bTeleport)
134+
{
135+
Teleport = ETeleportType::TeleportPhysics;
136+
}
137+
else
138+
{
139+
Teleport = ETeleportType::None;
140+
}
141+
142+
Actor->AddActorLocalRotation(Quat, bSweep, &OutSweepHitResult, Teleport);
143+
}
144+
145+
void UBlueprintRotationLibrary::AddActorWorldRotation(AActor* Actor, const FQuat& Quat, bool bSweep, FHitResult& OutSweepHitResult, bool bTeleport)
146+
{
147+
ETeleportType Teleport;
148+
149+
if (bTeleport)
150+
{
151+
Teleport = ETeleportType::TeleportPhysics;
152+
}
153+
else
154+
{
155+
Teleport = ETeleportType::None;
156+
}
157+
158+
Actor->AddActorWorldRotation(Quat, bSweep, &OutSweepHitResult, Teleport);
159+
}
160+
161+
void UBlueprintRotationLibrary::AddComponentLocalRotation(USceneComponent* Component, const FQuat& Quat, bool bSweep, FHitResult& OutSweepHitResult, bool bTeleport)
162+
{
163+
ETeleportType Teleport;
164+
165+
if (bTeleport)
166+
{
167+
Teleport = ETeleportType::TeleportPhysics;
168+
}
169+
else
170+
{
171+
Teleport = ETeleportType::None;
172+
}
173+
174+
Component->AddLocalRotation(Quat, bSweep, &OutSweepHitResult, Teleport);
175+
}
176+
177+
void UBlueprintRotationLibrary::AddComponentRelativeRotation(USceneComponent* Component, const FQuat& Quat, bool bSweep, FHitResult& OutSweepHitResult, bool bTeleport)
178+
{
179+
ETeleportType Teleport;
180+
181+
if (bTeleport)
182+
{
183+
Teleport = ETeleportType::TeleportPhysics;
184+
}
185+
else
186+
{
187+
Teleport = ETeleportType::None;
188+
}
189+
190+
Component->AddRelativeRotation(Quat, bSweep, &OutSweepHitResult, Teleport);
191+
}
192+
193+
void UBlueprintRotationLibrary::AddComponentWorldRotation(USceneComponent* Component, const FQuat& Quat, bool bSweep, FHitResult& OutSweepHitResult, bool bTeleport)
194+
{
195+
ETeleportType Teleport;
196+
197+
if (bTeleport)
198+
{
199+
Teleport = ETeleportType::TeleportPhysics;
200+
}
201+
else
202+
{
203+
Teleport = ETeleportType::None;
204+
}
205+
206+
Component->AddWorldRotation(Quat, bSweep, &OutSweepHitResult, Teleport);
207+
}
208+
209+
void UBlueprintRotationLibrary::SetActorRelativeRotation(AActor* Actor, const FQuat& Quat, bool bSweep, FHitResult& OutSweepHitResult, bool bTeleport)
210+
{
211+
ETeleportType Teleport;
212+
213+
if (bTeleport)
214+
{
215+
Teleport = ETeleportType::TeleportPhysics;
216+
}
217+
else
218+
{
219+
Teleport = ETeleportType::None;
220+
}
221+
222+
Actor->SetActorRelativeRotation(Quat, bSweep, &OutSweepHitResult, Teleport);
223+
}
224+
225+
void UBlueprintRotationLibrary::SetActorRotation(AActor* Actor, const FQuat& Quat, bool bTeleport)
226+
{
227+
ETeleportType Teleport;
228+
229+
if (bTeleport)
230+
{
231+
Teleport = ETeleportType::TeleportPhysics;
232+
}
233+
else
234+
{
235+
Teleport = ETeleportType::None;
236+
}
237+
238+
Actor->SetActorRotation(Quat, Teleport);
239+
}
240+
241+
void UBlueprintRotationLibrary::SetComponentRelativeRotation(USceneComponent* Component, const FQuat& Quat, bool bSweep, FHitResult& OutSweepHitResult, bool bTeleport)
242+
{
243+
ETeleportType Teleport;
244+
245+
if (bTeleport)
246+
{
247+
Teleport = ETeleportType::TeleportPhysics;
248+
}
249+
else
250+
{
251+
Teleport = ETeleportType::None;
252+
}
253+
254+
Component->SetRelativeRotation(Quat, bSweep, &OutSweepHitResult, Teleport);
255+
}
256+
257+
void UBlueprintRotationLibrary::SetComponentWorldRotation(USceneComponent* Component, const FQuat& Quat, bool bSweep, FHitResult& OutSweepHitResult, bool bTeleport)
258+
{
259+
ETeleportType Teleport;
260+
261+
if (bTeleport)
262+
{
263+
Teleport = ETeleportType::TeleportPhysics;
264+
}
265+
else
266+
{
267+
Teleport = ETeleportType::None;
268+
}
269+
270+
Component->SetWorldRotation(Quat, bSweep, &OutSweepHitResult, Teleport);
271+
}
272+
273+
FQuat UBlueprintRotationLibrary::GetTransformQuat(const FTransform Transform)
274+
{
275+
return Transform.GetRotation();
276+
}
277+
278+
void UBlueprintRotationLibrary::BreakTransformQuat(const FTransform Transform, FVector& Location, FQuat& RotationQuat, FVector& Scale)
279+
{
280+
Location = Transform.GetLocation();
281+
RotationQuat = Transform.GetRotation();
282+
Scale = Transform.GetScale3D();
283+
}
284+
285+
void UBlueprintRotationLibrary::QuatAxisAngleRad(const FQuat& Quat, float& OutAngleRad, FVector& OutAxis)
286+
{
287+
OutAngleRad = Quat.GetAngle();
288+
OutAxis = Quat.GetRotationAxis();
289+
}
290+
291+
void UBlueprintRotationLibrary::QuatAxisAngleDeg(const FQuat& Quat, float& OutAngleDeg, FVector& OutAxis)
292+
{
293+
OutAngleDeg = FMath::RadiansToDegrees(Quat.GetAngle());
294+
OutAxis = Quat.GetRotationAxis();
295+
}
296+
297+
FQuat UBlueprintRotationLibrary::FindBetweenNormals(const FVector& Normal1, const FVector& Normal2)
298+
{
299+
return FQuat::FindBetweenNormals(Normal1, Normal2);
300+
}
301+
302+
FVector UBlueprintRotationLibrary::GetForwardVector(const FQuat& Quat)
303+
{
304+
return Quat.GetForwardVector();
305+
}
306+
307+
FVector UBlueprintRotationLibrary::GetRightVector(const FQuat& Quat)
308+
{
309+
return Quat.GetRightVector();
310+
}
311+
312+
FVector UBlueprintRotationLibrary::GetUpVector(const FQuat& Quat)
313+
{
314+
return Quat.GetUpVector();
315+
}
316+
317+
FQuat UBlueprintRotationLibrary::Inverse(const FQuat& Quat)
318+
{
319+
return Quat.Inverse();
320+
}
321+
322+
FVector UBlueprintRotationLibrary::QuatToVector(const FQuat& Quat)
323+
{
324+
return Quat.Vector();
325+
}

0 commit comments

Comments
 (0)