Skip to main content
New Participant
September 25, 2014

Oculus Rift read sensor

Hello,

i'm not really into C++ and want to get the values of the Oculus accelerometers and send them to a Java application.
I searched around 5 hours and with all help (SDK Manual or Guide, other Forums, ...) I couldn't solve the problem.

So my question is: How do i read the sensordatas and export them to Java?

Greeting,
Knoxa

    6 replies

    Inspiring
    September 25, 2014
    Use the Java bindings for the SDK: https://github.com/jherico/jocular

    There's a full example of an application using LWJGL here: https://github.com/OculusRiftInAction/jocular-examples

    If you're only interested in fetching the sensor data, you can do that too.

    You can also take a look at my book ( http://manning.com/bdavis/ ) which has a chapter devoted to Python and Java development for the Rift.
    Brad Davis - Developer for High Fidelity Co-author of Oculus Rift in Action
    KnoxaAuthor
    New Participant
    October 2, 2014
    Thanks for the fast help!

    Now i looked over the java files and i don't get them.

    When I start the RiftDemo or RiftDemoRedux a application opens, but freezes.
    I don't get how the jocular-examples project is related to the jovr project.

    And which java file is responsible for the sensors, so i can read them?

    Greeting,
    Knoxa
    Inspiring
    October 2, 2014
    "Knoxa" wrote:
    When I start the RiftDemo or RiftDemoRedux a application opens, but freezes.
    I don't get how the jocular-examples project is related to the jovr project.


    The jocular examples project is simply a demo of using the JOVR bindings. If you only care about the sensors, you don't need it.

    "Knoxa" wrote:
    And which java file is responsible for the sensors, so i can read them?


    None of the Java files directly interacts with the hardware. These are C bindings that interact with the Oculus SDK. The SDK in turn communicates with the hardware.

    If you want to read the sensors, you can use something like this code:


    import static com.oculusvr.capi.OvrLibrary.ovrTrackingCaps.*;

    import com.oculusvr.capi.Hmd;
    import com.oculusvr.capi.OvrLibrary;
    import com.oculusvr.capi.TrackingState;

    public class RiftTracker {

    public static void main(String[] args) throws InterruptedException {
    Hmd.initialize();
    Hmd hmd = Hmd.create(0);
    if (null == hmd) {
    throw new IllegalStateException("Could not open HMD");
    }
    if (0 == hmd.configureTracking(ovrTrackingCap_Orientation | ovrTrackingCap_Position, 0)) {
    throw new IllegalStateException("Could not configure tracking");
    }

    for (int i = 0; i < 10; ++i) {
    TrackingState state = OvrLibrary.INSTANCE.ovrHmd_GetTrackingState(hmd, 0);
    System.out.println(state.HeadPose.Pose.Position.x);
    System.out.println(state.RawSensorData.Accelerometer.x);
    Thread.sleep(1000);
    }
    hmd.destroy();
    hmd = null;
    Hmd.shutdown();
    }
    };
    Brad Davis - Developer for High Fidelity Co-author of Oculus Rift in Action
    KnoxaAuthor
    New Participant
    October 2, 2014
    Thanks again!

    I just forgot to install the Oculus SDK and now everything is clear.
    Again thank you very much!

    Greeting,
    Knoxa
    Inspiring
    October 3, 2014
    Perhaps you mean you didn't install the Oculus runtime? The Java code has it's own DLL built into the jar file, so it doesn't need the SDK itself.
    Brad Davis - Developer for High Fidelity Co-author of Oculus Rift in Action
    April 10, 2020

    Knoxa said:

    Hello,


    i'm not really into C++ and want to get the values of the Oculus accelerometers and send them to a Java application.

    I searched around 5 hours and with all help (SDK Manual or Guide, other Forums, ...) I couldn't solve the problem.


    So my question is: How do i read the sensordatas and export them to Java?


    Greeting,

    Knoxa


    Hey, how is going..
    i have now the same problem as you back then.
    I hope you read this and guide me with my problem some how to fitch the sensor data from Oculus Rift S