Giter Site home page Giter Site logo

rustquest's Introduction

Rustquest

This is a minimal example project for the Oculus Quest, written completely in Rust. It renders a simple colored cube to the screen that moves around when your head pose changes.

Note that this project use neither Android Studio nor Gradle. Instead, the projects contains a build script that uses the platform and build tools in the Android SDK directly.

The project itself is organised into two parts. The android directory contains all the Java code, and is little more than a thin wrapper that forwards callbacks from the operating system to the native layer. The native directory contains all the native code, and is organised as a Cargo crate.

The Cargo crate contains several subcrates named *-sys. These contain all the Rust bindings for the relevant C libraries. Almost all these bindings were autogenerated using the Rust bindgen tool. The only exception are the utility functions in the VR API. These are static inline functions, preventing bindgen from generating bindings for them. As a workaround, I've ported these functions to Rust by hand.

The code itself contains a lot of boilerplate, but is not terribly complicated. The main source of complexity is the fact that the application runs in a separate dedicated thread: all the callbacks from the Java code need to be somehow forwarded to that thread. Luckily, Rust has some very nice primitives for multithreading, so the resulting code shouldn't be that hard to read.

Prerequisites

The following prerequisites are required in order to build the project:

  • Install OpenJDK 8

    • On Ubuntu, you can use the following command: sudo apt install openjdk-8-jdk-headless
    • NOTE: Make sure you install version 8 of the JDK, and not just the latest version. When I tried it, the SDK manager in the Android SDK tools did not work with any version of the JDK other than 8.
    • NOTE: Make sure you install the JDK, and not just the JRE, or you'll end up missing several tools that you'll need in the following steps.
  • Download and extract the Android SDK tools

    • You can download the Android SDK tools here: https://developer.android.com/studio
    • Extract the SDK tools somewhere. You can extract them anywhere you want, but the directory that seems to be the most often used, and the one I ended up using, is ~/Android/SDK/
  • Use the SDK manager to install:

    • Android platform 26
    • Build tools 28.0.3
    • NDK bundle
    • NOTE: Assuming you installed the SDK tools in ~/Android/SDK/, you can find the SDK manager in ~/Android/SDK/tools/bin/.
    • NOTE: These version numbers are based on what the samples in the Oculus Mobile SDK seem to be using.
  • Download and extract the Oculus Mobile SDK

  • Make sure the following environment variables are set:

    • export ANDROID_HOME=$HOME/Android/Sdk
    • export ANDROID_NDK_HOME=$HOME/Android/Sdk/ndk-bundle
    • export OVR_HOME=$HOME/ovr_sdk_mobile
    • export PATH=$ANDROID_HOME/platform-tools:$PATH
    • NOTE: If you installed either the Android SDK tools or the Oculus Mobile SDK in a different location than the one I suggested, you need to change the paths here accordingly.

Usage

I've created several shell scripts that allow you to build, install, start, and stop the application on the Quest. All of these scripts assume that the platform tools are in your $PATH, so before you start, doubly make sure that you've set your environment variables correctly.

IMPORTANT NOTE: Before we can build the application, we need to update the file native/.cargo/config. This is a configuration file that tells Cargo where it can find the compiler toolchain for cross-compiling to Android. Unfortunately, Cargo does not allow you to use either relative paths or environment variables here, so I've had to hardcode these paths. I would like to come up with a more elegant solution here eventually, but for now this the way things are.

  • To build the application, run: ./build.sh

NOTE: The subsequent steps require that the Quest is set in developer mode, and connected to your machine over USB.

  • To install the application, run: ./install.sh

  • To start the application, run: ./start.sh

  • To stop the application, run: ./stop.sh

rustquest's People

Contributors

ejpbruel2 avatar

Stargazers

Richard Kelley avatar  avatar Nick "MakeAvoy" McAvoy avatar GuruPoo avatar Andrey avatar Tim Arterbury avatar  avatar Global Young avatar misha kevlishvili avatar Tatsuhiko Suzuki avatar astrolemonade avatar ᴍᴀᴍᴀᴅᴏᴜ ʙᴀʙᴀᴇɪ avatar Moncef AOUDIA avatar Andy Thomson avatar Weykon avatar  avatar  avatar joshuacaffey avatar William Gooch avatar Gabriele Carrettoni avatar Timothy Schmidt avatar Farhad Hakimov avatar Kugushev Aleksandr avatar Ishan Bhargava avatar Tristan de Cacqueray avatar Dan Minshew avatar Leonard Pauli avatar Doug Moscrop avatar Dylan Johnston avatar Brian Cain avatar Rasmus Brönnegård avatar  avatar  avatar Pavlo Lozovskiy avatar Jan Van Sweevelt avatar Philip Kristoffersen avatar David Komer avatar Ryan Butler avatar Nathan Bleigh avatar Dmitry Kury avatar Seiji Emery avatar Scott Anderson avatar Martin Habovštiak avatar GAURAV avatar Tristam MacDonald avatar Kilian Steenman avatar Pedro Diaz avatar

Watchers

James Cloos avatar GuruPoo avatar Tristam MacDonald avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.