I'm using Unreal Engine 4. Currently I ray trace to a surface in game and I'm trying to find the location of the point relative to the surface1 instead of the world.
I have the world position of the origin of the surface and the world position of the impact point. I also have the X,Y,Z bounds of the object What I would like to find out is how to get X',Y' position of the hitpoint relative to the upper left corner. I've tried rotating the hitpoint around the origin to calculate the hitpoint based on refernce Roll, Pitch, and Yaw like so:
FVector RotatePointAroundPivot(FVector hitpoint, FVector pivot, FRotator angles) {
FVector dir = hitpoint - pivot;
FQuat quat(angles);
dir = quat*dir;
hitpoint = dir + pivot;
return hitpoint;
}
But it changes based on the rotation of the plane no matter what I do.
I also tried a very limited technique like so which just assumes it's in one of the correct orientations:
if (actorRotation.Yaw >= 0) {
xpos = (actorBounds.Y - clickPosition.Y) / (actorBounds.Y * 2) * compscale.X * 1000;
ypos = (actorBounds.Z + clickPosition.Z) / (actorBounds.Z * 2) * compscale.Y * 1000;
}
else {
xpos = (actorBounds.Y + clickPosition.Y) / (actorBounds.Y * 2) * compscale.X * 1000;
ypos = (actorBounds.Z + clickPosition.Z) / (actorBounds.Z * 2) * compscale.Y * 1000;
}
But it's flawed. All I want is to be able to use the surface like a screen.
Any help would be appreciated.