美文网首页
UE4 三种旋转(二)

UE4 三种旋转(二)

作者: wblong | 来源:发表于2021-04-09 22:09 被阅读0次

UE4 三种旋转(二)

UE4 中旋转操作常用的方式:欧拉角、四元数和旋转矩阵。

欧拉角

//右手法则
struct FRotator
{
public:
    /** Rotation around the right axis (around Y axis), Looking up and down (0=Straight Ahead, +Up, -Down) */
    float Pitch; 

    /** Rotation around the up axis (around Z axis), Running in circles 0=East, +North, -South. */
    float Yaw; 

    /** Rotation around the forward axis (around X axis), Tilting your head, 0=Straight, +Clockwise, -CCW. */
    float Roll;
 }
//左手法则
auto cameraRightVector = GetActorRotation().RotateVector(FVector::RightVector);
auto cameraUpVecotor = GetActorRotation().RotateVector(FVector::UpVector);
auto cameraForwardVector=(cameraRightVector ^ cameraUpVecotor);

四元数

struct FQuat 
{
public:

    /** The quaternion's X-component. */
    float X;

    /** The quaternion's Y-component. */
    float Y;

    /** The quaternion's Z-component. */
    float Z;

    /** The quaternion's W-component. */
    float W;
 }

利用四元数进行旋转操作。

FQuat axisRot(FVector::RightVector, FMath::DegreesToRadians(90));
SetActorRotation((GetActorRotation().Quaternion() * axisRot).Rotator());

FQuat axisRot(FVector::UpVector, FMath::DegreesToRadians(90);
SetActorRotation((axisRot * GetActorRotation().Quaternion()).Rotator());

旋转矩阵

class FRotationMatrix
    : public FRotationTranslationMatrix :public FMatrix
{
    FRotationMatrix(const FRotator& Rot)
        : FRotationTranslationMatrix(Rot, FVector::ZeroVector)
            //FRotationTranslationMatrix(const FRotator& Rot, const FVector& Origin)
    { }
 
    M[0][0] = CP * CY;
    M[0][1] = CP * SY;
    M[0][2] = SP;
    M[0][3] = 0.f;

    M[1][0] = SR * SP * CY - CR * SY;
    M[1][1] = SR * SP * SY + CR * CY;
    M[1][2] = - SR * CP;
    M[1][3] = 0.f;

    M[2][0] = -( CR * SP * CY + SR * SY );
    M[2][1] = CY * SR - CR * SP * SY;
    M[2][2] = CR * CP;
    M[2][3] = 0.f;

    M[3][0] = 0;
    M[3][1] = 0;
    M[3][2] = 0;
    M[3][3] = 1.f;
}

旋转矩阵的移动操作。

AddMovementInput(FRotationMatrix(GetActorRotation()).GetScaledAxis(EAxis::X), Value * GetCameraSpeed());
AddMovementInput(FRotationMatrix(GetActorRotation()).GetScaledAxis(EAxis::Y), Value * GetCameraSpeed());
AddMovementInput(FRotationMatrix(GetActorRotation()).GetScaledAxis(EAxis::Z), Value * GetCameraSpeed());

参考

UE4 三种旋转(一)

UE4 三种旋转(二)

相关文章

  • UE4 三种旋转(二)

    UE4 三种旋转(二) UE4 中旋转操作常用的方式:欧拉角、四元数和旋转矩阵。 欧拉角 四元数 利用四元数进行旋...

  • Unity的捕捉

    上面写到UE4,旋转捕捉,unity没有,现在纠正一下,Unity也是有的,把 “Snap Setting” 给忘...

  • iOS横竖屏旋转及其基本适配方法 <转>

    目录 一、最让人纠结的三种枚举 二、两种屏幕旋转的触发方式 三、屏幕旋转控制的优先级 四、开启屏幕旋转的全局权限 ...

  • IOS横竖屏以及适配

    目录一、最让人纠结的三种枚举二、两种屏幕旋转的触发方式三、屏幕旋转控制的优先级四、开启屏幕旋转的全局权限五、开启屏...

  • 屏幕旋转的那些事

    屏幕旋转一般有三种方式: 第一种、系统自带的自动旋转,只需要在Xcode - General设置即可 第二种、 U...

  • UE4 毛发渲染参考文章

    《UE4 头发制作流程》《ue4 4.24测试功能groom头发》《Digital Human UE4 TEST ...

  • iOS坐标系旋转让两个图像完全重合的心得

    例如A图为添加旋转、缩放、平移旋转的容器,B图为自己用CGContextRef 绘制。 需求A视图做三种转换时,利...

  • 旋转有序数组

    旋转有序数组:ll = [15,16,19,20,25,1,3,4,5,7,10,14]使用二分查找,分三种情况处...

  • UE4 actor绕着某个actor旋转

    实现的效果是Sphere 以 Cube为中心点 在水平面 即 xy平面进行旋转

  • PCN

    1、引言 一般情况下有三种策略来解决旋转变换: 数据增强(data augmentation):对于训练旋转不变性...

网友评论

      本文标题:UE4 三种旋转(二)

      本文链接:https://www.haomeiwen.com/subject/tonwkltx.html