UE5怎么用UE_LOG打印Rotator 的Pitch、Yaw、Roll
时间: 2023-07-10 16:11:18 浏览: 51
你可以使用UE_LOG的格式符号来打印Rotator的Pitch、Yaw、Roll。具体的代码实现如下:
```cpp
FRotator Rotation = FRotator(45.f, 0.f, 90.f);
UE_LOG(LogTemp, Warning, TEXT("Pitch: %f, Yaw: %f, Roll: %f"), Rotation.Pitch, Rotation.Yaw, Rotation.Roll);
```
在上面的示例中,我们创建了一个FRotator对象,并使用UE_LOG打印出了其Pitch、Yaw和Roll值。通过在UE_LOG的字符串参数中使用格式符号,我们可以将这些值以指定格式输出到控制台或日志文件中。
相关问题
mediapipe中计算出来的Pitch Yaw Roll转换ue5角度代码 c++
以下是将Mediapipe计算出的Pitch、Yaw和Roll转换为UE5角度的C++代码:
```c++
// 计算Mediapipe计算得出的Pitch、Yaw和Roll的弧度值
float pitch_radians = pitch_degrees * (float)PI / 180.0f;
float yaw_radians = yaw_degrees * (float)PI / 180.0f;
float roll_radians = roll_degrees * (float)PI / 180.0f;
// 将弧度值转换为UE5角度值
FRotator ue_rotator = FRotator(FMath::RadiansToDegrees(pitch_radians),
FMath::RadiansToDegrees(yaw_radians),
FMath::RadiansToDegrees(roll_radians));
```
其中,`pitch_degrees`、`yaw_degrees`和`roll_degrees`分别是Mediapipe计算出的Pitch、Yaw和Roll的角度值,`PI`是圆周率的值(可以使用`PI`宏定义),`FRotator`是UE4中表示旋转角度的结构体,其中的三个参数分别表示Pitch、Yaw和Roll的角度值。最终,`ue_rotator`变量中存储的就是转换后的UE5角度值。
mediapipe 坐标转换为UE5中的世界、坐标
首先,需要明确 Mediapipe 和 UE5 中的坐标系。
Mediapipe 使用的是左手坐标系,原点在图像的左上角,x 轴向右,y 轴向下,z 轴指向屏幕外方向。
UE5 中默认使用的是左手坐标系,原点在世界坐标系中心,x 轴向右,y 轴向前,z 轴向上。
因此,需要对 Mediapipe 中的坐标进行转换,使其适应 UE5 中的坐标系。
具体步骤如下:
1. 将 Mediapipe 中的坐标系原点转换为图像中心。可以通过以下代码实现:
```
image_width, image_height = image.shape[:2]
center_x, center_y = image_width // 2, image_height // 2
```
2. 将 Mediapipe 中的坐标系缩放到 [0, 1] 范围内。可以通过以下代码实现:
```
x /= image_width
y /= image_height
```
3. 将 Mediapipe 中的坐标系转换为 UE5 中的坐标系。可以通过以下代码实现:
```
ue_x = 2 * (x - 0.5)
ue_y = -(2 * (y - 0.5))
ue_z = depth * -1
```
其中,depth 为距离相机的深度,需要根据实际情况进行调整。
4. 将 UE5 中的坐标系转换为世界坐标系。可以通过以下代码实现:
```
world_location = unreal.Vector(ue_x, ue_y, ue_z)
world_rotation = unreal.Rotator(0, 0, 0)
world_scale = unreal.Vector(1, 1, 1)
world_transform = unreal.Transform(world_location, world_rotation, world_scale)
world_location = unreal.MathLibrary.transform_location(actor_transform, world_transform)
```
其中,actor_transform 为相机的 transform,需要根据实际情况进行传入。
这样,就完成了 Mediapipe 坐标到 UE5 中的世界坐标的转换。