Determine target on a surface using camera pitch and yaw

tabs

Veteran
Supporter
Been mucking around with Minecraft mods recently, and I'm creating an API for ComputerCraft for use with the OpenCCSensors mod. The point of it is to allow for a Kinect-like interface between the player and a virtual computer that is attached to a virtual monitor.

Here's an image in the likely case you're unfamiliar with this mod. The stuff with all the writing on is an in game monitor attached to a computer.

A key thing I'd like to achieve is being able to look at a specfic point on the screen from anywhere within range of the sensor and have the program accurately report that point. I have this working. Kind of.

What I do is use basic trigonometry and the player's yaw to calculate the X location of the target, and the player's pitch to calculate the Y location (both taking into account the relative positions of the monitor and player). This works great... until you get near the corners.

Imagine standing your player in front of a big monitor and looking at the center of the top edge. Now follow the edge to the corner and you'll notice you aren't moving the mouse purely horizontally, you have to move it down a bit to account for perspective or the 3D'ness of it. This lowers the pitch and therefore lowers my target.

I have no idea how to accurately compensate for this. :oops: I don't want to put a fudge factor in as that won't work for all monitor sizes and probably not if the player is standing outside of the X,Y bounds of the monitor.

I've had a look around obviously, but don't know the terms I need to be using.
 
Last edited by a moderator:
Back
Top