c++ - 前进时改变 FOV(视野)
问题描述
我有情况。我想在前进的同时顺利地改变 FOV。在父类的相机设置中,我设置了默认值:
FollowCamera->FieldOfView = 90.0f;
然后在 MoveForward 函数中我这样设置
void AStarMotoVehicle::MoveForward(float Axis)
{
if ((Controller != NULL) && (Axis != 0.0f) && (bDead != true))
{
//Angle of direction of camera on Yaw
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Axis);
FollowCamera->FieldOfView = 140.0f;
}
实际上它可以工作,所以当我向前移动时,FOV 更改为 140,但它的工作原理非常粗略,并且会立即发生。我想从90到140顺利完成。你能帮我吗?
解决方案
FInterpTo 会为你做这个: https ://docs.unrealengine.com/en-US/API/Runtime/Core/Math/FMath/FInterpTo/index.html
每次调用“MoveForward”时,fov 将增加直到 140。要减慢/加快过渡,请减少/增加 InterpSpeed 值
使用您的代码:
void AStarMotoVehicle::MoveForward(float Axis)
{
if ((Controller != NULL) && (Axis != 0.0f) && (bDead != true))
{
//Angle of direction of camera on Yaw
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Axis);
// could check if World is valid
UWorld *World = GetWorld();
const float CurrentFOV = FollowCamera->FieldOfView;
const float InterpSpeed = 2.0f
FollowCamera->FieldOfView = FMath::FInterpTo(CurrentFOV,
140.0f,
World->GetTimeSeconds(),
InterpSpeed);
}
推荐阅读
- python - 如何通过响应者获取 remote_addr?
- keras - Keras如何对层的输出进行切片然后将其添加到模型中
- r - R:通过 REST 调用的 Azure 表实体查询失败
- ios - SwiftUI 自定义 View 的 ViewBuilder 不会在子类 ObservedObject 更新时重新渲染/更新
- css - 在样式化组件中使用 CSS 选择器
- email - 如何使用标头识别电子邮件是否为已读回执响应
- javascript - 如何在不调用 imageChangedEvent 事件的情况下在 ngx-image-cropper 上加载图像?
- python - 如何将 3d 模型转换为点数组
- python - numpy中不同形状的数组之间的乘法
- python - 嗨,我如何使用 Flask(python) 将 sqlite 数据库中的所有元素加在一起以获得数字的总和