Game Development Reference
The Screen and the World
Most games, especially those on a computer with mouse control, require
calculations that transform the mouse position on the screen in 2D to
game environment coordinates in 3D. This is necessary when you need to
program for the player clicking on and interacting with objects in the 3D
world. They are not actually clicking on the game world; they are, in fact,
clicking on an imaginary transparent flat plane through which the game
is being viewed.
The screen coordinates are usually set most commonly with (0,0) in either
the upper or lower left corner or right in the center. The mouse position is
either counted in pixels or screen size proportions. For example, if the screen
resolution was 640 pixels wide and 480 pixels high with (0,0) being in the lower
left corner, the mouse coordinates when exactly in the center of the screen
would be (320,240). When screen coordinates are proportional, values range
from 0 to 1 in both the x and y directions no matter the resolution. For example,
if (0,0) were in the top left corner, (1,1) would be in the lower right. The mouse
position when the pointer is in the center of the screen would be (0.5,0.5).
If the different formats for the 2D screen space weren't complicated enough,
the 3D game world coordinates will be affected by rotation, perspective, or
orthographic views and scaling. The nature of the problem is illustrated in
Figure 4.6 .
Fig 4.6 The difference between 2D
screen coordinates and the