I am looking for the best way (or note that this is the best way) to shift the pixel coordinate to the corresponding beam direction from an arbitrary position / direction of the camera.
My current method is as follows. I define "camera" as a position vector, a lookat vector, and a vector up, named as such. (Note that the lookat vector is a single vector in the direction the camera is facing, not where (position-lookat) is the direction, just like the standard in XNA Matrix.CreateLookAt). These three vectors can uniquely determine the position of the camera. Here is the real code (well, actually, not a real, simplified abstracted version) (Language - HLSL)
float xPixelCoordShifted = (xPixelCoord / screenWidth * 2 - 1) * aspectRatio; float yPixelCoordShifted = yPixelCoord / screenHeight * 2 - 1; float3 right = cross(lookat, up); float3 actualUp = cross(right, lookat); float3 rightShift = mul(right, xPixelCoordShifted); float3 upShift = mul(actualUp, yPixelCoordShifted); return normalize(lookat + rightShift + upShift);
(return value is the direction of the beam)
So here is what I ask: this is the best way to do this, possibly using matrices, etc. The problem with this method is that if you have a too wide viewing angle, the edges of the screen will get a "radially stretched" appearance.
source share