Game Development Reference
In-Depth Information
Tip
Yaw
(also known as heading) is the angular movement of the eye in the X axis.
Pitch
is the
angular movement of the eye in the Y axis.
Note that yaw and pitch are controlled by the
mouse_x
and
mouse_y
variables. These are
delta increments in the XY axis sent through JNI by the
QuakeView
Java class. The center
of the screen represents the origin (0,0). Down or left increments are negative, up or right
increments are positive. The function
V_StopPitchDrift
stops the drift of the pitch angle
back to the origin whenever the movement stops (by lifting the finger). This is typical
behavior of Quake in the desktop (if you aim with the mouse, as soon as you move it outside
the game view, your aim will drift back to the origin).
Handling Forward and Side Movement
Forward and side movements are handled in a way similar to pitch and yaw. Quake uses
built-in data structures:
cmd->sidemove
to control side movements and
cmd->forwardmove
for
forward movement (see Listing 6-13). These variables need to be increased or decreased
by some increment. In this case, the increments are controlled by the variables
mouse_side
and
mouse_fwd
. These two variables will be updated by JNI whenever you drag a finger on
the screen. The companion JNI implementations are described in the previous section,
“Handling Touch.”
Note that both forward and side movements are multiplied by two Quake default values,
m_side
and
m_forward
. These are used to control the range of movement; also keep in mind
that
mouse_side
and
mouse_fwd
are delta values in the XY direction where the origin (0,0) is
defined at the point where the finger goes down. The delta values are then calculated by
subtracting the XY coordinates of the pointer and then sent through JNI for consumption.
Listing 6-13. Handling Forward and Side Movement
// these will be updated by JNI
int mouse_side;
int mouse_fwd;
void IN_FwdSideMove (usercmd_t *cmd)
{
cmd->sidemove += m_side.value * mouse_side;
cmd->forwardmove -= m_forward.value * mouse_fwd;
}
void IN_Move (usercmd_t *cmd)
{
IN_FwdSideMove (cmd);
IN_LookMove (cmd)
}