csharp_pain/Solar system/sss3d-source/sss3d/utils/joystick/Joystick.cpp

94 lines
1.9 KiB
C++
Raw Normal View History

2014-06-26 15:13:46 +00:00
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <windows.h>
#include <limits.h>
#include <jni.h>
#include "JoyStick.h"
/* Header for class Joystick */
#define MAX_VALUE (int)(USHRT_MAX / 2)
/*
* Class: Joystick
* Method: getButton
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_Joystick_getButtons(
JNIEnv *env,
jobject obj,
jint id)
{
JOYINFO info;
if (joyGetPos(id + JOYSTICKID1, &info) != JOYERR_NOERROR)
return 0;
int button = 0;
if (info.wButtons & JOY_BUTTON1)
button |= Joystick_BUTTON1;
if (info.wButtons & JOY_BUTTON2)
button |= Joystick_BUTTON2;
if (info.wButtons & JOY_BUTTON3)
button |= Joystick_BUTTON3;
if (info.wButtons & JOY_BUTTON4)
button |= Joystick_BUTTON4;
return button;
}
/*
* Class: Joystick
* Method: getNumDevs
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_Joystick_getNumDevs(
JNIEnv *env,
jobject obj)
{
return joyGetNumDevs();
}
/*
* Class: Joystick
* Method: getXPos
* Signature: (I)I
*/
JNIEXPORT jfloat JNICALL Java_Joystick_getXPos(
JNIEnv *env,
jobject obj,
jint id)
{
JOYINFO info;
if (joyGetPos(id + JOYSTICKID1, &info) != JOYERR_NOERROR)
return 0.0f;
return (float)((int)info.wXpos - MAX_VALUE) / (float)MAX_VALUE;
}
/*
* Class: Joystick
* Method: getYPos
* Signature: (I)I
*/
JNIEXPORT jfloat JNICALL Java_Joystick_getYPos(
JNIEnv *env,
jobject obj,
jint id)
{
JOYINFO info;
if (joyGetPos(id + JOYSTICKID1, &info) != JOYERR_NOERROR)
return 0.0f;
return (float)((int)info.wYpos - MAX_VALUE) / (float)MAX_VALUE;
}
/*
* Class: Joystick
* Method: getZPos
* Signature: (I)I
*/
JNIEXPORT jfloat JNICALL Java_Joystick_getZPos(
JNIEnv *env,
jobject obj,
jint id)
{
JOYINFO info;
if (joyGetPos(id + JOYSTICKID1, &info) != JOYERR_NOERROR)
return 0.0f;
return (float)((int)info.wZpos - MAX_VALUE) / (float)MAX_VALUE;
}