CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Math
DVector.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB).
2
// This work is licensed under the terms of the MIT license.
3
// For a copy, see <https://opensource.org/licenses/MIT>.
4
5
#pragma once
6
7
#include <cmath>
8
9
// Ideally, this could be included in unreal directly but it would be slow to work with
10
struct
FDVector
11
{
12
13
double
X
= 0.0;
14
double
Y
= 0.0;
15
double
Z
= 0.0;
16
17
FDVector
() :
X
(0.0),
Y
(0.0),
Z
(0.0) {}
18
19
FDVector
(
float
InX,
float
InY,
float
InZ) :
X
(InX),
Y
(InY),
Z
(InZ) {}
20
21
FDVector
(
double
InX,
double
InY,
double
InZ) :
X
(InX),
Y
(InY),
Z
(InZ) {}
22
23
FDVector
(
const
FVector& V) :
X
(V.
X
),
Y
(V.
Y
),
Z
(V.
Z
) {}
24
25
FDVector
(
const
FIntVector& V) :
X
(V.
X
),
Y
(V.
Y
),
Z
(V.
Z
) {}
26
27
double
Size
()
const
28
{
29
return
std::sqrt(
X
*
X
+
Y
*
Y
+
Z
*
Z
);
30
}
31
32
double
SizeSquared
()
const
33
{
34
return
X
*
X
+
Y
*
Y
+
Z
*
Z
;
35
}
36
37
static
double
Dist
(
const
FDVector
&V1,
const
FDVector
&V2)
38
{
39
return
std::sqrt(
FDVector::DistSquared
(V1, V2));
40
}
41
42
static
double
DistSquared
(
const
FDVector
&V1,
const
FDVector
&V2)
43
{
44
return
FMath::Square(V2.
X
-V1.
X
) + FMath::Square(V2.
Y
-V1.
Y
) + FMath::Square(V2.
Z
-V1.
Z
);
45
}
46
47
FVector
ToFVector
()
const
48
{
49
return
FVector(
X
,
Y
,
Z
);
50
}
51
52
FString
ToString
()
const
53
{
54
return
FString::Printf(TEXT(
"X=%.2lf Y=%.2lf Z=%.2lf"
),
X
,
Y
,
Z
);
55
}
56
57
FIntVector
ToFIntVector
()
const
58
{
59
return
FIntVector((int32)
X
, (int32)
Y
, (int32)
Z
);
60
}
61
62
FDVector
&
operator=
(
const
FDVector
& Other)
63
{
64
this->X =
Other
.X;
65
this->Y =
Other
.Y;
66
this->Z =
Other
.Z;
67
return
*
this
;
68
}
69
70
bool
operator==
(
const
FDVector
& Other)
71
{
72
return
X
==
Other
.X &&
73
Y
==
Other
.Y &&
74
Z
==
Other
.Z;
75
}
76
77
FDVector
operator+
(
const
FDVector
& V)
const
78
{
79
return
FDVector
(
X
+ V.
X
,
Y
+ V.
Y
,
Z
+ V.
Z
);
80
}
81
82
FDVector
&
operator+=
(
float
Scalar)
83
{
84
this->X += Scalar;
85
this->Y += Scalar;
86
this->Z += Scalar;
87
return
*
this
;
88
}
89
90
FDVector
operator-
(
const
FDVector
& V)
const
91
{
92
return
FDVector
(
X
- V.
X
,
Y
- V.
Y
,
Z
- V.
Z
);
93
}
94
95
FDVector
operator-=
(
const
FIntVector& V)
const
96
{
97
return
FDVector
(
X
- V.X,
Y
- V.Y,
Z
- V.Z);
98
}
99
100
FDVector
&
operator-=
(
const
FIntVector& V)
101
{
102
this->X -= V.X;
103
this->Y -= V.Y;
104
this->Z -= V.Z;
105
return
*
this
;
106
}
107
108
FDVector
operator/
(
float
Scale)
const
109
{
110
const
float
RScale = 1.f/Scale;
111
return
FDVector
(
X
* RScale,
Y
* RScale,
Z
* RScale);
112
}
113
114
FDVector
operator*
(
float
Scale)
const
115
{
116
return
FDVector
(
X
* Scale,
Y
* Scale,
Z
* Scale);
117
}
118
119
FDVector
operator*=
(
float
Scale)
120
{
121
this->X *= Scale;
122
this->Y *= Scale;
123
this->Z *= Scale;
124
return
*
this
;
125
}
126
127
FDVector
operator*=
(
double
Scale)
128
{
129
this->X *= Scale;
130
this->Y *= Scale;
131
this->Z *= Scale;
132
return
*
this
;
133
}
134
};
ELightType::Other
@ Other
Definition
CarlaLight.h:35
FDVector::operator==
bool operator==(const FDVector &Other)
Definition
DVector.h:70
FDVector::X
double X
Definition
DVector.h:13
FDVector::ToFIntVector
FIntVector ToFIntVector() const
Definition
DVector.h:57
FDVector::operator*=
FDVector operator*=(double Scale)
Definition
DVector.h:127
FDVector::operator+
FDVector operator+(const FDVector &V) const
Definition
DVector.h:77
FDVector::operator+=
FDVector & operator+=(float Scalar)
Definition
DVector.h:82
FDVector::operator-=
FDVector operator-=(const FIntVector &V) const
Definition
DVector.h:95
FDVector::Z
double Z
Definition
DVector.h:15
FDVector::operator/
FDVector operator/(float Scale) const
Definition
DVector.h:108
FDVector::operator=
FDVector & operator=(const FDVector &Other)
Definition
DVector.h:62
FDVector::operator-=
FDVector & operator-=(const FIntVector &V)
Definition
DVector.h:100
FDVector::FDVector
FDVector(const FIntVector &V)
Definition
DVector.h:25
FDVector::FDVector
FDVector(const FVector &V)
Definition
DVector.h:23
FDVector::Size
double Size() const
Definition
DVector.h:27
FDVector::FDVector
FDVector()
Definition
DVector.h:17
FDVector::FDVector
FDVector(double InX, double InY, double InZ)
Definition
DVector.h:21
FDVector::operator*
FDVector operator*(float Scale) const
Definition
DVector.h:114
FDVector::operator*=
FDVector operator*=(float Scale)
Definition
DVector.h:119
FDVector::FDVector
FDVector(float InX, float InY, float InZ)
Definition
DVector.h:19
FDVector::DistSquared
static double DistSquared(const FDVector &V1, const FDVector &V2)
Definition
DVector.h:42
FDVector::operator-
FDVector operator-(const FDVector &V) const
Definition
DVector.h:90
FDVector::ToString
FString ToString() const
Definition
DVector.h:52
FDVector::Dist
static double Dist(const FDVector &V1, const FDVector &V2)
Definition
DVector.h:37
FDVector::Y
double Y
Definition
DVector.h:14
FDVector::SizeSquared
double SizeSquared() const
Definition
DVector.h:32
FDVector::ToFVector
FVector ToFVector() const
Definition
DVector.h:47
Generated by
1.18.0