-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDynamicCube.cpp
More file actions
129 lines (107 loc) · 2.57 KB
/
DynamicCube.cpp
File metadata and controls
129 lines (107 loc) · 2.57 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "DynamicCube.h"
#include "UDynamicMesh.h"
#include "GeometryScript/MeshPrimitiveFunctions.h"
#include "GeometryScript/MeshBasicEditFunctions.h"
#include "MeshTransformUtilities.h"
void UDynamicCube::SetSize(const FVector& Size)
{
mSize = Size;
}
void UDynamicCube::AddToOrigin(const FVector& Delta)
{
mOrigin += Delta;
}
void UDynamicCube::AddToSize(const FVector& Delta)
{
mSize += Delta;
}
void UDynamicCube::AddToSizeInDirection(const float Size, const FVector& Direction)
{
FVector Normalized = Direction.GetSafeNormal();
FVector ChangeInSize = Size * Normalized.GetAbs();
// the change to the origin is half the size changed, in the opposite direction
FVector ChangeInOrigin = Normalized * Size * 0.5f * -1.f;
AddToSize(ChangeInSize);
AddToOrigin(ChangeInOrigin);
}
void UDynamicCube::SetTranslation(const FVector& Position)
{
mTranslation = Position;
}
void UDynamicCube::AddToTranslation(const FVector& Delta)
{
mTranslation += Delta;
}
void UDynamicCube::SetRotation(const FRotator& Rotation)
{
mRotation = Rotation;
}
void UDynamicCube::SetRotation(const FVector& Facing)
{
mRotation = Facing.Rotation();
}
void UDynamicCube::SetOrigin(const FVector& Origin)
{
mOrigin = Origin;
}
void UDynamicCube::SetGeometryOptions(const FGeometryScriptPrimitiveOptions Options)
{
mGeometryOptions = Options;
}
void UDynamicCube::SetOriginMode(const EGeometryScriptPrimitiveOriginMode Origin)
{
mOriginMode = Origin;
}
FVector UDynamicCube::GetSize()
{
return mSize;
}
FVector UDynamicCube::GetTranslation()
{
// an origin of x=-5 is a translation of x=5
return (mOrigin * -1) + mTranslation;
}
FRotator UDynamicCube::GetRotation()
{
return mRotation;
}
void UDynamicCube::SetTransform(const FTransform& Transform)
{
mRotation = Transform.GetRotation().Rotator();
mTranslation = Transform.GetTranslation();
mScale = Transform.GetScale3D();
}
FTransform UDynamicCube::GetTransform()
{
return FTransform(
FQuat(GetRotation()),
GetTranslation(),
mScale
);
}
void UDynamicCube::GenerateMesh(UDynamicMesh* Mesh, const bool ApplyTransform)
{
// construct our mesh
FTransform Transform = ApplyTransform ? GetTransform() : FTransform();
UGeometryScriptLibrary_MeshPrimitiveFunctions::AppendBox(
Mesh,
mGeometryOptions,
Transform,
mSize.X,
mSize.Y,
mSize.Z,
0,
0,
0,
mOriginMode
);
}
void UDynamicCube::Reset()
{
mTranslation = FVector::Zero();
mRotation = FRotator(0.f, 0.f, 0.f);
mSize = FVector(100.f, 100.f, 100.f);
mScale = FVector(1.f);
mGeometryOptions = FGeometryScriptPrimitiveOptions();
mOriginMode = EGeometryScriptPrimitiveOriginMode::Base;
}