Game Development Reference
In-Depth Information
if (inf < 0)
inf = 0;
if (inf > 255)
inf = 255;
palette[i] = inf;
}
// assign new values
memcpy (pal, palette, sizeof(palette));
}
Handling Pitch and Yaw
In a first-person shooter game like Quake, pitch and yaw are commonly used to aim your
weapon. In the PC world, this is usually done using the mouse to control the direction of a
crosshair. On a touch device, on the other hand, you don't have such luxury but you can
decide which sections of the screen control what. For example, in 3D space, if sweeping on
the left half of the screen, you can move your character forwards or sideways. If sweeping
on the right half, you can aim. It's all up to you. Listing 6-12 shows how to control aiming by
altering the yaw and pitch of the built-in client view angles data structure ( cl.viewangles ).
Listing 6-12. Aim Control with Yaw and Pitch
void IN_LookMove (usercmd_t *cmd)
{
if (!mouse_avail)
return;
if (m_filter.value)
{
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
mouse_x *= sensitivity.value;
mouse_y *= sensitivity.value;
// set YAW
cl.viewangles[YAW] -= m_yaw.value * mouse_x;
V_StopPitchDrift ();
// PITCH
cl.viewangles[PITCH] += m_pitch.value * mouse_y;
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
mouse_x = mouse_y = 0;
}
 
Search WWH ::




Custom Search