Game Development Reference
In-Depth Information
2.3 Defining 2D and 3D Space
Whether it is in 2D or 3D space the principles of vectors are applied in
the same way. As we explored with vectors, the difference between a 2D
coordinate and a 3D coordinate is just another value. In 3D game engines,
such as Unity, 2D games are created by ignoring one of the axes. In the rocket
ship application shown later in this chapter, all game objects are positioned
in the same plane, having a y position value initially set to 0. All movements
thereafter only move and rotate the objects in x and y . This is the same
principle as moving objects around on a flat tabletop. In the rocket ship game,
the camera is positioned directly above the game objects and perspective is
removed to give the illusion of a truly 2D world.
The camera in a game is a critical component as it presents the action to
the player. It is literally the lens through which the game world is perceived.
Understanding how the camera moves and how to set what it looks
at is essential knowledge.
2.3.1 Cameras
The camera in a game defines the visible area on the screen. In addition to
defining the height and width of the view, the camera also sets the depth
of what can be seen. The entire space visible by a camera is called the view
volume . If an object is not inside the view volume, it is not drawn on the screen.
The shape of the view volume can be set to orthographic or perspective. Both
views are constructed from an eye position (representing the viewers' location),
a near clipping plane, the screen, and a far clipping plane.
An orthographic camera projects all points of 3D objects between the clipping
planes in parallel onto a screen plane, as shown in Figure 2.5 . The screen plane
is the view the player ends up seeing. The viewing volume of an orthographic
camera is the shape of a rectangular prism.
A perspective camera projects all points of 3D objects between the clipping
planes back to the eye, as shown in Figure 2.6 . The near clipping plane
becomes the screen. The viewing volume of a perspective camera is called the
frustum as it takes on the volume of a pyramid with the top cut off. The eye is
located at the apex of the pyramid.
The result of using a perspective and orthographic camera on the same scene
in Unity is illustrated in Figure 2.7 . A perspective camera is used in Figure 2.7a .
The way in which perspective projections best show depth is evident from
the line of buildings getting smaller as they disappear into the distance. This
is not the case for the orthographic camera shown in Figure 2.7b . Depth can
only be determined by which objects are drawn in front. The buildings appear
to be flattened with no size difference between buildings in the distance.
Figures 2.7c and 2.7d illustrate the way in how the camera view volume is
displayed in Unity's Editor Scene. If an object is not inside the view volume
in the Scene, it will not appear on the screen in the Game.
Search Nedrilad ::

Custom Search