Game Development Reference
In-Depth Information
JNIEXPORT jint JNICALL Java_quake_jni_Natives_mouseLook
(JNIEnv * env, jclass cls, jint mousex, jint mousey)
{
mx = (int)mousex;
my = (int)mousey;
}
extern int mouse_side, mouse_fwd;
JNIEXPORT jint JNICALL Java_quake_jni_Natives_mouseMove
(JNIEnv * env, jclass cls, jint jx, jint jy)
{
mouse_side = (int)jx;
mouse_fwd = (int)jy;
}
// vid_so.c
int mouse_side = 0;
int mouse_fwd = 0;
int mx, my; // mouse look
void IN_Move (usercmd_t *cmd)
{
old_mouse_x = mx;
old_mouse_y = my;
mx *= 3; //sensitivity
my *= 3; //sensitivity
// Look: yaw/pitch
in_state.viewangles[YAW] -= m_yaw->value * mx;
in_state.viewangles[PITCH] += m_pitch->value * my;
mx = my = 0;
// Move
cmd->sidemove += m_side->value * mouse_side;
cmd->forwardmove -= m_forward->value * mouse_fwd;
}
IN_Move is the Quake II input handler for movement. For forward or side movement, IN_Move
provides the command structure of usercmd_t *cmd , which can be used to control the
character by consuming two delta values in the XY coordinates.
cmd->sidemove += m_side->value * DELTA_X;
cmd->forwardmove -= m_forward->value * DELTA_Y;
DELTA_X and DELTA_Y are the increments in the XY direction provided by Java when the user
drags a finger on screen; m_side and m_forward are two internal constants used to control
the sensitivity of the movement; and cmd->sidemove and cmd->forwardmove are the internal
variables that contain the actual character position on 3D space. Note that to move forward
in the Quake I/II 3D space coordinate system, the increments in the Y axis must be negative.
This is the inverse of dragging a finger up the screen, which provides a positive increment.
Search WWH ::




Custom Search