added rotational axis too
This commit is contained in:
parent
9cdf5d7156
commit
99e22aa0b4
|
@ -67,13 +67,22 @@ public class Controller {
|
||||||
|
|
||||||
/** X position, range -1000 to 1000 */
|
/** X position, range -1000 to 1000 */
|
||||||
public static int x = 0;
|
public static int x = 0;
|
||||||
|
|
||||||
|
/** X rotational position, range -1000 to 1000 */
|
||||||
|
public static int rx = 0;
|
||||||
|
|
||||||
/** Y position, range -1000 to 1000 */
|
/** Y position, range -1000 to 1000 */
|
||||||
public static int y = 0;
|
public static int y = 0;
|
||||||
|
|
||||||
|
/** Y rotational position, range -1000 to 1000 */
|
||||||
|
public static int ry = 0;
|
||||||
|
|
||||||
/** Z position, range -1000 to 1000 */
|
/** Z position, range -1000 to 1000 */
|
||||||
public static int z = 0;
|
public static int z = 0;
|
||||||
|
|
||||||
|
/** Z rotational position, range -1000 to 1000 */
|
||||||
|
public static int rz = 0;
|
||||||
|
|
||||||
/** Position of Point of View from -1 to 27000 (360 degrees) */
|
/** Position of Point of View from -1 to 27000 (360 degrees) */
|
||||||
public static int pov;
|
public static int pov;
|
||||||
|
|
||||||
|
@ -98,8 +107,11 @@ public class Controller {
|
||||||
/* Controller capabilities */
|
/* Controller capabilities */
|
||||||
public static int buttonCount = -1;
|
public static int buttonCount = -1;
|
||||||
public static boolean hasXAxis = false;
|
public static boolean hasXAxis = false;
|
||||||
|
public static boolean hasRXAxis = false;
|
||||||
public static boolean hasYAxis = false;
|
public static boolean hasYAxis = false;
|
||||||
public static boolean hasZAxis = false;
|
public static boolean hasRYAxis = false;
|
||||||
|
public static boolean hasZAxis = false;
|
||||||
|
public static boolean hasRZAxis = false;
|
||||||
public static boolean hasPOV = false;
|
public static boolean hasPOV = false;
|
||||||
public static boolean hasSlider = false;
|
public static boolean hasSlider = false;
|
||||||
|
|
||||||
|
|
|
@ -95,18 +95,33 @@ public class ControllerTest extends Panel {
|
||||||
if(Controller.hasXAxis) {
|
if(Controller.hasXAxis) {
|
||||||
g.drawString("x : " + Controller.x, x, y);
|
g.drawString("x : " + Controller.x, x, y);
|
||||||
y += 20;
|
y += 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Controller.hasRXAxis) {
|
||||||
|
g.drawString("rx : " + Controller.rx, x, y);
|
||||||
|
y += 20;
|
||||||
|
}
|
||||||
|
|
||||||
if(Controller.hasYAxis) {
|
if(Controller.hasYAxis) {
|
||||||
g.drawString("y : " + Controller.y, x, y);
|
g.drawString("y : " + Controller.y, x, y);
|
||||||
y += 20;
|
y += 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Controller.hasRYAxis) {
|
||||||
|
g.drawString("ry : " + Controller.ry, x, y);
|
||||||
|
y += 20;
|
||||||
|
}
|
||||||
|
|
||||||
if (Controller.hasZAxis) {
|
if (Controller.hasZAxis) {
|
||||||
g.drawString("z : " + Controller.z, x, y);
|
g.drawString("z : " + Controller.z, x, y);
|
||||||
y += 20;
|
y += 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Controller.hasRZAxis) {
|
||||||
|
g.drawString("rz : " + Controller.rz, x, y);
|
||||||
|
y += 20;
|
||||||
|
}
|
||||||
|
|
||||||
if (Controller.hasPOV) {
|
if (Controller.hasPOV) {
|
||||||
g.drawString("pov: " + Controller.pov, x, y);
|
g.drawString("pov: " + Controller.pov, x, y);
|
||||||
y += 20;
|
y += 20;
|
||||||
|
|
|
@ -56,8 +56,11 @@ DIJOYSTATE2 js; // State of Controller
|
||||||
|
|
||||||
int buttoncount = 0; // Temporary buttoncount
|
int buttoncount = 0; // Temporary buttoncount
|
||||||
bool hasx; // Temporary xaxis check
|
bool hasx; // Temporary xaxis check
|
||||||
|
bool hasrx; // Temporary rotational xaxis check
|
||||||
bool hasy; // Temporary yaxis check
|
bool hasy; // Temporary yaxis check
|
||||||
|
bool hasry; // Temporary rotational yaxis check
|
||||||
bool hasz; // Temporary zaxis check
|
bool hasz; // Temporary zaxis check
|
||||||
|
bool hasrz; // Temporary rotational zaxis check
|
||||||
bool haspov; // Temporary pov check
|
bool haspov; // Temporary pov check
|
||||||
bool hasslider; // Temporary slider check
|
bool hasslider; // Temporary slider check
|
||||||
|
|
||||||
|
@ -69,14 +72,20 @@ bool create_success; // bool used to determine successfull creati
|
||||||
jclass clsController;
|
jclass clsController;
|
||||||
jfieldID fidButtonCount;
|
jfieldID fidButtonCount;
|
||||||
jfieldID fidHasXAxis;
|
jfieldID fidHasXAxis;
|
||||||
|
jfieldID fidHasRXAxis;
|
||||||
jfieldID fidHasYAxis;
|
jfieldID fidHasYAxis;
|
||||||
|
jfieldID fidHasRYAxis;
|
||||||
jfieldID fidHasZAxis;
|
jfieldID fidHasZAxis;
|
||||||
|
jfieldID fidHasRZAxis;
|
||||||
jfieldID fidHasPOV;
|
jfieldID fidHasPOV;
|
||||||
jfieldID fidHasSlider;
|
jfieldID fidHasSlider;
|
||||||
jfieldID fidButtons;
|
jfieldID fidButtons;
|
||||||
jfieldID fidX;
|
jfieldID fidX;
|
||||||
|
jfieldID fidRX;
|
||||||
jfieldID fidY;
|
jfieldID fidY;
|
||||||
|
jfieldID fidRY;
|
||||||
jfieldID fidZ;
|
jfieldID fidZ;
|
||||||
|
jfieldID fidRZ;
|
||||||
jfieldID fidPOV;
|
jfieldID fidPOV;
|
||||||
jfieldID fidSlider;
|
jfieldID fidSlider;
|
||||||
|
|
||||||
|
@ -271,6 +280,12 @@ BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LP
|
||||||
haspov = true;
|
haspov = true;
|
||||||
} else if (lpddoi->guidType == GUID_Slider){
|
} else if (lpddoi->guidType == GUID_Slider){
|
||||||
hasslider = true;
|
hasslider = true;
|
||||||
|
} else if (lpddoi->guidType == GUID_RxAxis) {
|
||||||
|
hasrx = true;
|
||||||
|
} else if (lpddoi->guidType == GUID_RyAxis) {
|
||||||
|
hasry = true;
|
||||||
|
} else if (lpddoi->guidType == GUID_RzAxis) {
|
||||||
|
hasrz = true;
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
} else {
|
} else {
|
||||||
printf("Unhandled object found: %s\n", lpddoi->tszName);
|
printf("Unhandled object found: %s\n", lpddoi->tszName);
|
||||||
|
@ -316,18 +331,19 @@ void SetupController() {
|
||||||
create_success = false;
|
create_success = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set X-axis range to (-1000 ... +1000)
|
// set range to (-1000 ... +1000)
|
||||||
// This lets us test against 0 to see which way the stick is pointed.
|
// This lets us test against 0 to see which way the stick is pointed.
|
||||||
DIPROPRANGE diprg;
|
DIPROPRANGE diprg;
|
||||||
diprg.diph.dwSize = sizeof(diprg);
|
diprg.diph.dwSize = sizeof(diprg);
|
||||||
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
|
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
|
||||||
diprg.diph.dwObj = DIJOFS_X;
|
|
||||||
diprg.diph.dwHow = DIPH_BYOFFSET;
|
diprg.diph.dwHow = DIPH_BYOFFSET;
|
||||||
diprg.lMin = AXISMIN;
|
diprg.lMin = AXISMIN;
|
||||||
diprg.lMax = AXISMAX;
|
diprg.lMax = AXISMAX;
|
||||||
|
|
||||||
|
// set X-axis
|
||||||
if(hasx) {
|
if(hasx) {
|
||||||
|
diprg.diph.dwObj = DIJOFS_X;
|
||||||
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
printf("SetProperty(DIJOFS_X) failed\n");
|
printf("SetProperty(DIJOFS_X) failed\n");
|
||||||
|
@ -337,9 +353,20 @@ void SetupController() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// set RX-axis
|
||||||
// And again for Y-axis range
|
if(hasrx) {
|
||||||
//
|
diprg.diph.dwObj = DIJOFS_RX;
|
||||||
|
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||||
|
#if _DEBUG
|
||||||
|
printf("SetProperty(DIJOFS_RX) failed\n");
|
||||||
|
#endif
|
||||||
|
create_success = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// set Y-axis
|
||||||
if(hasy) {
|
if(hasy) {
|
||||||
diprg.diph.dwObj = DIJOFS_Y;
|
diprg.diph.dwObj = DIJOFS_Y;
|
||||||
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||||
|
@ -351,9 +378,19 @@ void SetupController() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// set RY-axis
|
||||||
// And again for Z-axis range
|
if(hasry) {
|
||||||
//
|
diprg.diph.dwObj = DIJOFS_RY;
|
||||||
|
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||||
|
#if _DEBUG
|
||||||
|
printf("SetProperty(DIJOFS_RY) failed\n");
|
||||||
|
#endif
|
||||||
|
create_success = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set Z-axis
|
||||||
if(hasz) {
|
if(hasz) {
|
||||||
diprg.diph.dwObj = DIJOFS_Z;
|
diprg.diph.dwObj = DIJOFS_Z;
|
||||||
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||||
|
@ -365,6 +402,19 @@ void SetupController() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// set RZ-axis
|
||||||
|
if(hasrz) {
|
||||||
|
diprg.diph.dwObj = DIJOFS_RZ;
|
||||||
|
if(lpDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
|
||||||
|
#if _DEBUG
|
||||||
|
printf("SetProperty(DIJOFS_RZ) failed\n");
|
||||||
|
#endif
|
||||||
|
create_success = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Lastly slider
|
// Lastly slider
|
||||||
// using z axis since we're running dx 5
|
// using z axis since we're running dx 5
|
||||||
|
@ -414,17 +464,30 @@ void UpdateFields() {
|
||||||
|
|
||||||
//axis's
|
//axis's
|
||||||
if(hasx) {
|
if(hasx) {
|
||||||
environment->SetStaticIntField(clsController, fidX, js.lX);
|
environment->SetStaticIntField(clsController, fidX, js.lX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasy) {
|
if(hasy) {
|
||||||
environment->SetStaticIntField(clsController, fidY, js.lY);
|
environment->SetStaticIntField(clsController, fidY, js.lY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasz) {
|
if(hasz) {
|
||||||
environment->SetStaticIntField(clsController, fidZ, js.lZ);
|
environment->SetStaticIntField(clsController, fidZ, js.lZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//rotational axis
|
||||||
|
if(hasrx) {
|
||||||
|
environment->SetStaticIntField(clsController, fidRX, js.lRx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hasry) {
|
||||||
|
environment->SetStaticIntField(clsController, fidRY, js.lRy);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hasrz) {
|
||||||
|
environment->SetStaticIntField(clsController, fidRZ, js.lRz);
|
||||||
|
}
|
||||||
|
|
||||||
//buttons
|
//buttons
|
||||||
jbooleanArray buttonsArray = (jbooleanArray) environment->GetStaticObjectField(clsController, fidButtons);
|
jbooleanArray buttonsArray = (jbooleanArray) environment->GetStaticObjectField(clsController, fidButtons);
|
||||||
BYTE * buttons = (BYTE *) environment->GetPrimitiveArrayCritical(buttonsArray, NULL);
|
BYTE * buttons = (BYTE *) environment->GetPrimitiveArrayCritical(buttonsArray, NULL);
|
||||||
|
@ -454,6 +517,11 @@ void SetCapabilities() {
|
||||||
environment->SetStaticIntField(clsController, fidHasYAxis, hasy);
|
environment->SetStaticIntField(clsController, fidHasYAxis, hasy);
|
||||||
environment->SetStaticIntField(clsController, fidHasZAxis, hasz);
|
environment->SetStaticIntField(clsController, fidHasZAxis, hasz);
|
||||||
|
|
||||||
|
//set rotational axis
|
||||||
|
environment->SetStaticIntField(clsController, fidHasRXAxis, hasrx);
|
||||||
|
environment->SetStaticIntField(clsController, fidHasRYAxis, hasry);
|
||||||
|
environment->SetStaticIntField(clsController, fidHasRZAxis, hasrz);
|
||||||
|
|
||||||
//set pov
|
//set pov
|
||||||
environment->SetStaticIntField(clsController, fidHasPOV, haspov);
|
environment->SetStaticIntField(clsController, fidHasPOV, haspov);
|
||||||
|
|
||||||
|
@ -467,14 +535,20 @@ void SetCapabilities() {
|
||||||
void CacheFields() {
|
void CacheFields() {
|
||||||
fidButtonCount = environment->GetStaticFieldID(clsController, "buttonCount", "I");
|
fidButtonCount = environment->GetStaticFieldID(clsController, "buttonCount", "I");
|
||||||
fidHasXAxis = environment->GetStaticFieldID(clsController, "hasXAxis", "Z");
|
fidHasXAxis = environment->GetStaticFieldID(clsController, "hasXAxis", "Z");
|
||||||
|
fidHasRXAxis = environment->GetStaticFieldID(clsController, "hasRXAxis", "Z");
|
||||||
fidHasYAxis = environment->GetStaticFieldID(clsController, "hasYAxis", "Z");
|
fidHasYAxis = environment->GetStaticFieldID(clsController, "hasYAxis", "Z");
|
||||||
|
fidHasRYAxis = environment->GetStaticFieldID(clsController, "hasRYAxis", "Z");
|
||||||
fidHasZAxis = environment->GetStaticFieldID(clsController, "hasZAxis", "Z");
|
fidHasZAxis = environment->GetStaticFieldID(clsController, "hasZAxis", "Z");
|
||||||
|
fidHasRZAxis = environment->GetStaticFieldID(clsController, "hasRZAxis", "Z");
|
||||||
fidHasPOV = environment->GetStaticFieldID(clsController, "hasPOV", "Z");
|
fidHasPOV = environment->GetStaticFieldID(clsController, "hasPOV", "Z");
|
||||||
fidHasSlider = environment->GetStaticFieldID(clsController, "hasSlider", "Z");
|
fidHasSlider = environment->GetStaticFieldID(clsController, "hasSlider", "Z");
|
||||||
fidButtons = environment->GetStaticFieldID(clsController, "buttons", "[Z");
|
fidButtons = environment->GetStaticFieldID(clsController, "buttons", "[Z");
|
||||||
fidX = environment->GetStaticFieldID(clsController, "x", "I");
|
fidX = environment->GetStaticFieldID(clsController, "x", "I");
|
||||||
|
fidRX = environment->GetStaticFieldID(clsController, "rx", "I");
|
||||||
fidY = environment->GetStaticFieldID(clsController, "y", "I");
|
fidY = environment->GetStaticFieldID(clsController, "y", "I");
|
||||||
|
fidRY = environment->GetStaticFieldID(clsController, "ry", "I");
|
||||||
fidZ = environment->GetStaticFieldID(clsController, "z", "I");
|
fidZ = environment->GetStaticFieldID(clsController, "z", "I");
|
||||||
|
fidRZ = environment->GetStaticFieldID(clsController, "rz", "I");
|
||||||
fidPOV = environment->GetStaticFieldID(clsController, "pov", "I");
|
fidPOV = environment->GetStaticFieldID(clsController, "pov", "I");
|
||||||
fidSlider = environment->GetStaticFieldID(clsController, "slider", "I");
|
fidSlider = environment->GetStaticFieldID(clsController, "slider", "I");
|
||||||
}
|
}
|
Loading…
Reference in New Issue