Search in sources :

Example 1 with Callback

use of com.sun.jna.Callback in project jmonkeyengine by jMonkeyEngine.

the class OSVRInput method init.

@Override
public boolean init() {
    logger.config("Initialize OSVR input.");
    buttonHandler = new Callback() {

        @SuppressWarnings("unused")
        public void invoke(Pointer userdata, Pointer timeval, OSVR_ButtonReport report) {
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < BUTTON_COUNT; j++) {
                    if (buttons[i][j] == null)
                        continue;
                    if (userdata.toString().equals(buttons[i][j].getPointer().toString())) {
                        buttonState[i][j] = report.state;
                        return;
                    }
                }
            }
        }
    };
    analogHandler = new Callback() {

        @SuppressWarnings("unused")
        public void invoke(Pointer userdata, Pointer timeval, OSVR_AnalogReport report) {
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < ANALOG_COUNT; j++) {
                    for (int k = 0; k < CHANNEL_COUNT; k++) {
                        if (analogs[i][j][k] == null)
                            continue;
                        if (userdata.toString().equals(analogs[i][j][k].getPointer().toString())) {
                            analogState[i][j][k] = (float) report.state;
                            return;
                        }
                    }
                }
            }
        }
    };
    buttons = new OSVR_ClientInterface[2][BUTTON_COUNT];
    analogs = new OSVR_ClientInterface[2][ANALOG_COUNT][CHANNEL_COUNT];
    buttonState = new float[2][BUTTON_COUNT];
    analogState = new float[2][ANALOG_COUNT][CHANNEL_COUNT];
    hands = new OSVR_ClientInterface[2];
    hands[0] = getInterface(leftHand);
    hands[1] = getInterface(rightHand);
    handState = new OSVR_Pose3[2];
    handState[0] = new OSVR_Pose3();
    handState[1] = new OSVR_Pose3();
    for (int h = 0; h < 2; h++) {
        for (int i = 0; i < BUTTON_COUNT - 2; i++) {
            buttons[h][i] = getInterface(getButtonString(h == 0, (byte) Integer.toString(i).toCharArray()[0]));
            OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[h][i], buttonHandler, buttons[h][i].getPointer());
        }
    }
    buttons[0][BUTTON_COUNT - 2] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'b', 'u', 'm', 'p', 'e', 'r', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[0][BUTTON_COUNT - 2], buttonHandler, buttons[0][BUTTON_COUNT - 2].getPointer());
    buttons[1][BUTTON_COUNT - 2] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'b', 'u', 'm', 'p', 'e', 'r', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[1][BUTTON_COUNT - 2], buttonHandler, buttons[1][BUTTON_COUNT - 2].getPointer());
    buttons[0][BUTTON_COUNT - 1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'b', 'u', 't', 't', 'o', 'n', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[0][BUTTON_COUNT - 1], buttonHandler, buttons[0][BUTTON_COUNT - 1].getPointer());
    buttons[1][BUTTON_COUNT - 1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'b', 'u', 't', 't', 'o', 'n', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[1][BUTTON_COUNT - 1], buttonHandler, buttons[1][BUTTON_COUNT - 1].getPointer());
    analogs[0][0][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 't', 'r', 'i', 'g', 'g', 'e', 'r', (byte) 0 });
    analogs[1][0][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 't', 'r', 'i', 'g', 'g', 'e', 'r', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][0][0], analogHandler, analogs[0][0][0].getPointer());
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][0][0], analogHandler, analogs[1][0][0].getPointer());
    analogs[0][1][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'x', (byte) 0 });
    analogs[0][1][1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'y', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][1][0], analogHandler, analogs[0][1][0].getPointer());
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][1][1], analogHandler, analogs[0][1][1].getPointer());
    analogs[1][1][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'x', (byte) 0 });
    analogs[1][1][1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'y', (byte) 0 });
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][1][0], analogHandler, analogs[1][1][0].getPointer());
    OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][1][1], analogHandler, analogs[1][1][1].getPointer());
    return true;
}
Also used : Callback(com.sun.jna.Callback) OSVR_ButtonReport(com.jme3.system.osvr.osvrclientreporttypes.OSVR_ButtonReport) OSVR_Pose3(com.jme3.system.osvr.osvrclientreporttypes.OSVR_Pose3) Pointer(com.sun.jna.Pointer) OSVR_AnalogReport(com.jme3.system.osvr.osvrclientreporttypes.OSVR_AnalogReport)

Aggregations

OSVR_AnalogReport (com.jme3.system.osvr.osvrclientreporttypes.OSVR_AnalogReport)1 OSVR_ButtonReport (com.jme3.system.osvr.osvrclientreporttypes.OSVR_ButtonReport)1 OSVR_Pose3 (com.jme3.system.osvr.osvrclientreporttypes.OSVR_Pose3)1 Callback (com.sun.jna.Callback)1 Pointer (com.sun.jna.Pointer)1