【UE4】GAMES101 图形学作业0:矩阵初识

作业描述

给定一个点P=(2,1), 将该点绕原点先逆时针旋转45◦,再平移(1,2), 计算出变换后点的坐标(要求用齐次坐标进行计算)。

UE4 知识点

  • 主要矩阵

    • FMatrix
      • FBasisVectorMatrix
      • FLookFromMatrix
      • FOrthoMatrix
      • FReversedZOrthoMatrix
      • FPerspectiveMatrix
      • FReversedZPerspectiveMatrix
      • FScaleMatrix
      • FTranslationMatrix
      • FRotationTranslationMatrix
      • FRotationMatrix
      • FInverseRotationMatrix
      • PMatrix
    • FMatrix2x2
  • FMatrix 矩阵说明

    以行向量作为计算习惯,所以计算的时候矩阵注意取转置

    image

代码实现

  • 版本 4.26.2

  • 原文地址

  • 蓝图

    image

  • C++

    void AActor_Pa0::BeginPlay()
    {
    	Super::BeginPlay();
    
    	// 给定一个点P=(2,1), 将该点绕原点先逆时针旋转45◦,再平移(1,2), 计算出变换后点的坐标(要求用齐次坐标进行计算)。
    	float fcos = UKismetMathLibrary::DegCos(45);
    	float fsin = UKismetMathLibrary::DegSin(45);
    	FPlane row1 = FPlane(fcos, -fsin, 1, 0);
    	FPlane row2 = FPlane(fsin, fcos, 2, 0);
    	FPlane row3 = FPlane(0, -0, 1, 0);
    	FPlane row4 = FPlane(0, -0, 0, 0);
    	FMatrix matrix = FMatrix(row1, row2, row3, row4);
    	FVector4 originPos = FVector4(2, 1, 1, 0);
    
    	matrix = matrix.GetTransposed(); //行向量乘以矩阵,所以矩阵取转置
    	FVector4 res = matrix.TransformFVector4(originPos);
    	
    	UE_LOG(LogTemp, Warning, TEXT("%s"), *matrix.ToString());
    	UE_LOG(LogTemp, Warning, TEXT("[ %f, %f, %f ]"), res.X, res.Y, res.Z);
    }
    
    output:
    LogTemp: Warning: [0.707107 0.707107 0 0] [-0.707107 0.707107 0 0] [1 2 1 0] [0 0 0 0] 
    LogTemp: Warning: [ 1.707107, 4.121320, 1.000000 ]
    
posted @ 2021-10-20 14:25  砥才人  阅读(1148)  评论(0编辑  收藏  举报