DeprojectScreenPositionToWorld and ProjectWorldLocationToScreen seem to not match.
FVector2D ScreenLoc;
bool Pressed;
GetInputTouchState(ETouchIndex::Touch1, ScreenLoc.X, ScreenLoc.Y, Pressed);
FVector WorldLoc, WorldDir;
UE_LOG(LogScript, Warning, TEXT("ScreenLoc Dep %f %f"), ScreenLoc.X, ScreenLoc.Y);
DeprojectScreenPositionToWorld(ScreenLoc.X, ScreenLoc.Y, WorldLoc, WorldDir);
ProjectWorldLocationToScreen(WorldLoc, ScreenLoc);
UE_LOG(LogScript, Warning, TEXT("ScreenLoc Proj %f %f"), ScreenLoc.X, ScreenLoc.Y);
FVector2D ViewportSize;
GEngine->GameViewport->GetViewportSize(ViewportSize);
UE_LOG(LogScript, Warning, TEXT("ViewportSize %f %f"), ViewportSize.X, ViewportSize.Y);
FVector TraceEnd = WorldLoc + WorldDir * 10240;
FHitResult HitInfo;
FCollisionQueryParams QParams;
FCollisionObjectQueryParams OParams;
GetWorld()->LineTraceSingle(HitInfo, WorldLoc, TraceEnd, QParams, OParams);
DrawDebugSphere(GetWorld(), HitInfo.ImpactPoint, 10, 10, FColor::Red, false, 1);
DeprojectScreenPositionToWorld works fine, I get the DebugSphere exactly where I touched.
But the screen coordinates that I get from ProjectWorldLocationToScreen(WorldLoc, ScreenLoc);
don’t match.
I get this in the log, when I pressed near the bottom, right edge:
LogScript:Warning: ScreenLoc Dep 1136.159180 425.000000
LogScript:Warning: ScreenLoc Proj 806.860779 301.869476
LogScript:Warning: ViewportSize 1139.000000 428.000000
I’m using version 4.4.0.