Game Development Reference
In-Depth Information
Listing 7-3. Key Handlers for Quake II Java Wrappers
// in jni_quake.c
JNIEXPORT jint JNICALL Java_quake_jni_Natives_keyPress
(JNIEnv * env, jclass cls, jint key)
{
Key_Event((int)key, 1);
return key;
}
JNIEXPORT jint JNICALL Java_quake_jni_Natives_keyRelease
(JNIEnv * env, jclass cls, jint key)
{
Key_Event((int)key, 0);
return key;
}
Listing 7-3 shows the parameter key, which must be an ASCII code being fed to the Quake
II key handler. I want to stress this because failing to translate the key properly will make all
kinds of weird things happen and cause you a lot of headaches.
Key_Event((int)key, 1);
The first argument of Key_Event is the ASCII code and the second is a Boolean variable
where 1 means key pressed and 0 means key released.
Moving in 3D Space
When moving a Quake II character in 3D space, you have four choices: moving forward,
moving sideways, and the ability to look around by controlling the yaw (or angular movement
in the X coordinate) or pitch (angular movement in the Y coordinate). To do so, there are two
native methods in Natives.java :
mouseMove(int deltaX, int deltaY)
mouseLook(int deltaX, int deltaY)
mouseMove controls forward or sideways movement by feeding XY increments (or deltas) to
the Quake II engine. mouseLook does the same thing with yaw and pitch increments. The C
companions for mouseMove and mouseLook are identical to Quake I in Chapter 6; however,
Quake II requires a movement handler that must be implemented. This handler is called
IN_Move and it is shown in Listing 7-4.
Listing 7-4. Moving in 3D Space
// jni_quake.c
// forwards/sideways deltas
extern int mouse_side, mouse_fwd;
// Yaw/pitch deltas
extern int mx, my;
 
Search WWH ::




Custom Search