Advertisement
Guest User

PerComponentFOV using FSceneView similar to UT3

a guest
Oct 31st, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.21 KB | None | 0 0
  1. FMatrix UDoWSkeletalMeshComponent::GetRenderMatrix() const
  2. {
  3.     /* UT3's implementation for reference
  4.  
  5.     const FMatrix LocalToView = LocalToWorld * View->ViewMatrix;
  6.     const FMatrix ViewToWarpedView = FPerspectiveMatrix(FOV * PI / 360.0f, View->SizeX, View->SizeY, View->NearClippingDistance) * View->ProjectionMatrix.Inverse();
  7.  
  8.     OutLocalToWorld = LocalToView * ViewToWarpedView * View->ViewMatrix.Inverse();
  9.     OutWorldToLocal = OutLocalToWorld.Inverse();
  10.  
  11.     */
  12.  
  13.     // Get references
  14.     ADoWWeapon* Weapon = Cast<ADoWWeapon>(GetOuter());
  15.  
  16.     if (false)//Weapon)
  17.     {
  18.         ADoWCharacter * Character = Cast<ADoWCharacter>(Weapon->GetOwner());
  19.  
  20.         if (Character)
  21.         {
  22.             // The FOV we actually want to apply to the mesh
  23.             float FOV = 70.0f;
  24.             const FVector2D ViewportSize = FVector2D(GEngine->GameViewport->Viewport->GetSizeXY());
  25.  
  26.             ADoWPlayerController *PC = Cast<ADoWPlayerController>(Character->GetController());
  27.             if (PC)
  28.             {
  29.                 ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(PC->Player);
  30.  
  31.                 if (LocalPlayer != NULL && LocalPlayer->ViewportClient != NULL && LocalPlayer->ViewportClient->Viewport != NULL)
  32.                 {
  33.                     FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
  34.                         LocalPlayer->ViewportClient->Viewport,
  35.                         PC->GetWorld()->Scene,
  36.                         LocalPlayer->ViewportClient->EngineShowFlags).SetRealtimeUpdate(true));
  37.  
  38.                     FVector ViewLocation;
  39.                     FRotator ViewRotation;
  40.                     FSceneView* View = LocalPlayer->CalcSceneView(&ViewFamily, ViewLocation, ViewRotation, LocalPlayer->ViewportClient->Viewport);
  41.  
  42.                     //SceneView->ViewMatrices.ProjMatrix.SetIdentity();
  43.  
  44.                     const FMatrix LocalToView = ComponentToWorld.ToMatrixWithScale() * View->ViewMatrices.ViewMatrix;
  45.                     const FMatrix ViewToWarpedView = FPerspectiveMatrix(FOV * PI / 360.0f, ViewportSize.X, ViewportSize.Y, View->NearClippingDistance) * View->ViewMatrices.ProjMatrix.Inverse();
  46.  
  47.                     FMatrix OutLocalToWorld = LocalToView * ViewToWarpedView * View->ViewMatrices.ViewMatrix.Inverse();
  48.                     FMatrix OutWorldToLocal = OutLocalToWorld.Inverse();
  49.                     return OutWorldToLocal;
  50.                 }
  51.  
  52.             }
  53.  
  54.             /*
  55.             // Get current FOV
  56.             float currFovFull = (Cast<APlayerController>(Character->Controller))->PlayerCameraManager->GetFOVAngle();
  57.  
  58.             // Calc radial FOV to pass into FPerspectiveMatrix
  59.             float engineFovHalf = currFovFull * PI / 360.0f;// PI / (180.0f / (currFovFull * 0.5f));
  60.             float requiredFovHalf = FOV * PI / 360.0f; //PI / (180.0f / (requiredFovFull * 0.5f));
  61.  
  62.             // Get perspective matrix that will be applied after we send our data and invert it - inversion will allow us to pre-emptively remove the camera FOV
  63.             FPerspectiveMatrix enginePerspective = FPerspectiveMatrix(engineFovHalf, ViewportSize.X, ViewportSize.Y, 1.0f);
  64.             FMatrix invEnginePerspective = enginePerspective.Inverse();
  65.  
  66.             // Set up perspective matrix we want to apply
  67.             FPerspectiveMatrix requiredPerspective = FPerspectiveMatrix(requiredFovHalf, ViewportSize.X, ViewportSize.Y, 1.0f);
  68.  
  69.             // Get world transform for this comp and apply inverse and required transforms to it
  70.             FMatrix adjTransform = invEnginePerspective * requiredPerspective * ComponentToWorld.ToMatrixWithScale();
  71.  
  72.             return adjTransform;
  73.             */
  74.         }
  75.     }
  76.  
  77.     return Super::GetRenderMatrix();
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement