【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 ]
    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM