Raycasting A 2D Point in the World

Hi Guys,

so I am basically trying to make a plugin for Unreal Engine for the pupil labs HTC Vive device in VR. This device does eyetracking and has as inputs the following

Inputs:

2 floats representing the current position of the eye in the square (x,y)

(0, 0) representing the down left corner

(1, 1) representing the up right corner

I basically get data such as (0.5 , 0.5) which represent the center or (0.33, 0.65) some position in the field of view.

Output

The projection of the input in the world.

What I tryed to do

UPupilPlayerController->GetPlayerViewPoint(CameraLocation, CameraRotator);
const FVector StartTrace = CameraLocation;
	

const FVector ForwardVector = CameraRotator.Vector();  
    FVector	*PlanePoint = new FVector(x, y, 1);
FVector *EndPlanePointTrace = new FVector();  ///REAL ■■■■■■■■■■■■ 

*EndPlanePointTrace = ((ForwardVector *220.f) + *PlanePoint);

 (GetWorld()->LineTraceSingleByChannel(*HitResult, StartTrace, *EndPlanePointTrace, ECC_Visibility, *TraceParams)

Also there is the implementation for this already in Unity which looks something like this line 64

I am basically trying to mimic sceneCamera.ViewportPointToRay (viewportPoint);

The current status of my project is free on git.

Hey Sys,

first thank you for your work.
Did it work plausible for you and stable ?

Cheers
Arthur

Try this

UPlayerController* PlayerController = ...
PlayerController->DeprojectScreenPositionToWorld(ScreenX, ScreenY, OutWorldLocation, OutWorldDirection);

More info on: >DeprojectScreenPositionToWorld<

OutWorldLocation and OutWorldDirection is your ray that you can shoot from the scene. You can check if it hits a plane with this API

FPlane PlaneToHit = FPlane(FVector(0, 0, 0), FVector(-1, 0, 0));
FVector WorldHitPosition = FMath::RayPlaneIntersection(OutWorldLocation, OutWorldDirection, PlaneToHit);