CARLA
 
载入中...
搜索中...
未找到
rpc/Color.h
浏览该文件的文档.
1// Copyright (c) 2017 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 <cstdint>
12
13#ifdef LIBCARLA_INCLUDED_FROM_UE4
15#include "Math/Color.h"
17#endif // LIBCARLA_INCLUDED_FROM_UE4
18
19namespace carla {
20namespace rpc {
21// 定义一个 Color 类用于表示颜色
22 class Color {
23 public:
24
25 uint8_t r = 0u;// 红色通道的值,0~255之间的整数
26 uint8_t g = 0u; // 绿色通道的值
27 uint8_t b = 0u; // 蓝色通道的值
28
29 Color() = default;// 默认构造函数,初始化为黑色(r=0, g=0, b=0)
30 Color(const Color &) = default;// 拷贝构造函数
31
32 Color(uint8_t r, uint8_t g, uint8_t b)
33 : r(r), g(g), b(b) {} // 构造函数,接受 r, g, b 三个颜色分量值来初始化 Color 对象
34
35 Color &operator=(const Color &) = default;
36
37#ifdef LIBCARLA_INCLUDED_FROM_UE4
38
39 Color(const FColor &color)
40 : Color(color.R, color.G, color.B) {}
41
42 Color(const FLinearColor &color)
43 : Color(color.R * 255.0f, color.G * 255.0f, color.B * 255.0f) {}
44
45 operator FColor() const {
46 return FColor{r, g, b};
47 }
48
49 operator FLinearColor() const {
50 return FLinearColor{
51 static_cast<float>(r)/255.0f, // 将整数 RGB 分量转换为浮动值(0.0~1.0)
52 static_cast<float>(g)/255.0f,
53 static_cast<float>(b)/255.0f,
54 1.0f // 透明度设为 1.0(不透明)
55 };
56 }
57
58#endif // LIBCARLA_INCLUDED_FROM_UE4 // 使用 MsgPack 序列化库定义颜色类的序列化规则
59
60 MSGPACK_DEFINE_ARRAY(r, g, b);// 定义序列化数组,确保 r, g, b 被正确序列化和反序列化
61 };
62
63} // namespace rpc
64} // namespace carla
Color(const FColor &color)
Definition rpc/Color.h:39
Color(const FLinearColor &color)
Definition rpc/Color.h:42
Color(const Color &)=default
MSGPACK_DEFINE_ARRAY(r, g, b)
Color & operator=(const Color &)=default
Color(uint8_t r, uint8_t g, uint8_t b)
Definition rpc/Color.h:32
CARLA模拟器的主命名空间。
Definition Carla.cpp:139