CARLA
 
载入中...
搜索中...
未找到
Vector3DInt.h
浏览该文件的文档.
1// Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "carla/MsgPack.h" // 包含消息打包库
10
11#include <cmath>
12#include <limits>
13
14namespace carla {
15namespace geom {
16
18 public:
19
20 // =========================================================================
21 // -- 公共数据成员 --------------------------------------------------
22 // =========================================================================
23
24 int32_t x = 0; // X轴的整数值,默认为0
25
26 int32_t y = 0; // Y轴的整数值,默认为0
27
28 int32_t z = 0; // Z轴的整数值,默认为0
29
30 // =========================================================================
31 // -- 构造函数 ---------------------------------------------------------
32 // =========================================================================
33
34 Vector3DInt() = default;
35
36 Vector3DInt(int32_t ix, int32_t iy, int32_t iz)
37 : x(ix),
38 y(iy),
39 z(iz) {} // 参数化构造函数,初始化x、y、z
40
41 // =========================================================================
42 // -- 其他方法 --------------------------------------------------------
43 // =========================================================================
44
45 int64_t SquaredLength() const { // 计算向量的平方长度
46 return x * x + y * y + z * z;
47 }
48
49 double Length() const { // 计算向量的长度
50 return std::sqrt(SquaredLength());
51 }
52
53 // =========================================================================
54 // -- 算术运算符 -------------------------------------------------
55 // =========================================================================
56
57 Vector3DInt &operator+=(const Vector3DInt &rhs) { // 加法赋值运算符
58 x += rhs.x;
59 y += rhs.y;
60 z += rhs.z;
61 return *this;
62 }
63
64 friend Vector3DInt operator+(Vector3DInt lhs, const Vector3DInt &rhs) { // 加法运算符
65 lhs += rhs;
66 return lhs;
67 }
68
69 Vector3DInt &operator-=(const Vector3DInt &rhs) { // 减法赋值运算符
70 x -= rhs.x;
71 y -= rhs.y;
72 z -= rhs.z;
73 return *this;
74 }
75
76 friend Vector3DInt operator-(Vector3DInt lhs, const Vector3DInt &rhs) { // 减法运算符
77 lhs -= rhs;
78 return lhs;
79 }
80
81 Vector3DInt &operator*=(int32_t rhs) { // 乘法赋值运算符
82 x *= rhs;
83 y *= rhs;
84 z *= rhs;
85 return *this;
86 }
87
88 friend Vector3DInt operator*(Vector3DInt lhs, int32_t rhs) { // 乘法运算符
89 lhs *= rhs;
90 return lhs;
91 }
92
93 friend Vector3DInt operator*(int32_t lhs, Vector3DInt rhs) { // 乘法运算符
94 rhs *= lhs;
95 return rhs;
96 }
97
98 Vector3DInt &operator/=(int32_t rhs) { // 除法赋值运算符
99 x /= rhs;
100 y /= rhs;
101 z /= rhs;
102 return *this;
103 }
104
105 friend Vector3DInt operator/(Vector3DInt lhs, int32_t rhs) { // 除法运算符
106 lhs /= rhs;
107 return lhs;
108 }
109
110 friend Vector3DInt operator/(int32_t lhs, Vector3DInt rhs) { // 除法运算符
111 rhs /= lhs;
112 return rhs;
113 }
114
115 // =========================================================================
116 // -- 比较运算符 -------------------------------------------------
117 // =========================================================================
118
119 bool operator==(const Vector3DInt &rhs) const { // 等于运算符
120 return (x == rhs.x) && (y == rhs.y) && (z == rhs.z);
121 }
122
123 bool operator!=(const Vector3DInt &rhs) const { // 不等于运算符
124 return !(*this == rhs);
125 }
126
127 // =========================================================================
128 // -- 转换为UE4类型 ---------------------------------------------
129 // =========================================================================
130
131#ifdef LIBCARLA_INCLUDED_FROM_UE4
132
133 Vector3DInt(const FIntVector &v) = delete; // 禁止从UE4的FIntVector转换
134 Vector3DInt& operator=(const FIntVector &rhs) = delete; // 禁止赋值UE4的FIntVector
135
136 /// 将厘米转换为米
138 return *this / 100;
139 }
140
141 ///将米转换为厘米
143 return *this * 100;
144 }
145
146 FIntVector ToFIntVector() const { // 转换为UE4的FIntVector
147 return FIntVector{x, y, z};
148 }
149
150#endif // LIBCARLA_INCLUDED_FROM_UE4
151
152 // =========================================================================
153 /// 待办事项:以下是从MSGPACK_DEFINE_ARRAY复制粘贴过来的。
154 /// 这是解决msgpack库中一个问题的临时方法。
155 /// MSGPACK_DEFINE_ARRAY宏正在遮蔽我们的z变量。
156 /// https://github.com/msgpack/msgpack-c/issues/709
157 // =========================================================================
158 template <typename Packer>
159 void msgpack_pack(Packer& pk) const // 消息打包函数
160 {
161 clmdep_msgpack::type::make_define_array(x, y, z).msgpack_pack(pk);
162 }
163 void msgpack_unpack(clmdep_msgpack::object const& o) // 消息解包函数
164 {
165 clmdep_msgpack::type::make_define_array(x, y, z).msgpack_unpack(o);
166 }
167 template <typename MSGPACK_OBJECT>
168 void msgpack_object(MSGPACK_OBJECT* o, clmdep_msgpack::zone& sneaky_variable_that_shadows_z) const // 消息对象函数
169 {
170 clmdep_msgpack::type::make_define_array(x, y, z).msgpack_object(o, sneaky_variable_that_shadows_z);
171 }
172 // =========================================================================
173 };
174
175} // namespace geom
176} // namespace carla
int64_t SquaredLength() const
Definition Vector3DInt.h:45
double Length() const
Definition Vector3DInt.h:49
Vector3DInt & operator+=(const Vector3DInt &rhs)
Definition Vector3DInt.h:57
Vector3DInt(const FIntVector &v)=delete
Vector3DInt & operator-=(const Vector3DInt &rhs)
Definition Vector3DInt.h:69
bool operator==(const Vector3DInt &rhs) const
void msgpack_unpack(clmdep_msgpack::object const &o)
Vector3DInt & operator/=(int32_t rhs)
Definition Vector3DInt.h:98
friend Vector3DInt operator/(Vector3DInt lhs, int32_t rhs)
FIntVector ToFIntVector() const
Vector3DInt(int32_t ix, int32_t iy, int32_t iz)
Definition Vector3DInt.h:36
friend Vector3DInt operator+(Vector3DInt lhs, const Vector3DInt &rhs)
Definition Vector3DInt.h:64
friend Vector3DInt operator*(Vector3DInt lhs, int32_t rhs)
Definition Vector3DInt.h:88
void msgpack_object(MSGPACK_OBJECT *o, clmdep_msgpack::zone &sneaky_variable_that_shadows_z) const
Vector3DInt ToMeters() const
将厘米转换为米
friend Vector3DInt operator*(int32_t lhs, Vector3DInt rhs)
Definition Vector3DInt.h:93
Vector3DInt ToCentimeters() const
将米转换为厘米
Vector3DInt & operator*=(int32_t rhs)
Definition Vector3DInt.h:81
bool operator!=(const Vector3DInt &rhs) const
Vector3DInt & operator=(const FIntVector &rhs)=delete
void msgpack_pack(Packer &pk) const
待办事项:以下是从MSGPACK_DEFINE_ARRAY复制粘贴过来的。 这是解决msgpack库中一个问题的临时方法。 MSGPACK_DEFINE_ARRAY宏正在遮蔽我们的z变量。 https:...
friend Vector3DInt operator/(int32_t lhs, Vector3DInt rhs)
friend Vector3DInt operator-(Vector3DInt lhs, const Vector3DInt &rhs)
Definition Vector3DInt.h:76
CARLA模拟器的主命名空间。
Definition Carla.cpp:139