Code Monkey home page Code Monkey logo

jme-cardboard's Introduction

jme-cardboard

Google Cardboard integration for jMonkeyEngine 3.1. Tested with cardboard.jar 0.5.8

Take any jMonkeyEngine 3 application and run it in mobile VR.

How do I use this thing!?

This has only been developed for jMonkeyEngine 3.1 (trunk).

Before using it, you need to add Android support to your project through the SDK:

http://wiki.jmonkeyengine.org/doku.php/jme3:android?s[]=android

You also need to follow the instructions for how to develop for Google Cardboard:

https://developers.google.com/cardboard/android/download

Then, the project specific things: New way using CardboardHarnessFragment:

  1. Add jme-cardboard.jar to your project.
  2. Turn on Android deployment for your project (Properties/Application/Android)
  3. Follow these instructions to run jme in a fragment: http://www.softwarepioneering.com/2015/07/running-jmonkeyengine-3-on-android.html But instead of extending AndroidHarnessFragment, extend CardboardHarnessFragment instead. MainActivity should extend CardboardActivity

For an example, look at test/CardboardStarTravel

If you need to set your own CardboardDeviceParams you can do so by a setter in CardboardContext. It has to be done before createView() is called. You can access it via CardboardHarnessFragment:

((CardboardContext) getJmeApplication().getContext()).setCardboardDeviceParams(params);

If you wish to build the sources yourself, it needs access to an android.jar file.

Troubleshooting: It seems to be important that the starting orientation is "forward" according to the cardboard. If you find that the screen is black when starting, try looking in the opposite direction, or rotate the spatial.

jme-cardboard's People

Contributors

neph1 avatar scienceofficer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jme-cardboard's Issues

Missing viewport in cardboard.jar 0.5.4

Using 0.5.4 of Google Cardboard seems to cut out one of the viewports.
It's briefly visible before disappearing.
If created as a "pre view", the right viewport is lost. If instead created as a "post view", the left viewport disappears.
Workaround: Use 0.5.3

Wrong viewport and camera configuration

On my device (Samsung Galaxy S5), the viewport is distorted (flattened) and the head tracking is moving the camera in the inverted Y axis (pitch), so moving the head up moves the camera down, and moving the head down moves the camera up.

I managed to fix the update method of CardboardState.java to get rid of these issues.

@Override
    public void update(float tpf) {
        super.update(tpf);
        if(context.getLeftEye() == null){
            return;
        }
        TempVars tempVars = TempVars.get();

        if(!viewPortSet){
            //Left eye
            Viewport v = context.getLeftEye().getViewport();

            camLeft.setViewPort((float)v.x/ context.getSettings().getWidth(), (float)(v.x + v.width) / context.getSettings().getWidth(), (float)v.y/ context.getSettings().getHeight(), (float)v.height / context.getSettings().getHeight());
            camLeft.setFrustumPerspective(context.getLeftEye().getFov().getTop() + context.getLeftEye().getFov().getBottom(), (float)v.width / v.height, camLeft.getFrustumNear(), camLeft.getFrustumFar());
            camLeft.setProjectionMatrix(new Matrix4f( context.getLeftEye().getPerspective(camLeft.getFrustumNear(), camLeft.getFrustumFar())));

            // Right eye
            v = context.getRightEye().getViewport();

            camRight.setViewPort((float)v.x/ context.getSettings().getWidth(), (float)(v.x + v.width) / context.getSettings().getWidth(), (float)v.y/ context.getSettings().getHeight(), (float)v.height / context.getSettings().getHeight());
            camRight.setFrustumPerspective(context.getRightEye().getFov().getTop() + context.getRightEye().getFov().getBottom(), (float)v.width / v.height, camRight.getFrustumNear(), camRight.getFrustumFar());
            camRight.setProjectionMatrix(new Matrix4f( context.getRightEye().getPerspective(camRight.getFrustumNear(), camRight.getFrustumFar())));

            viewPortSet = true;
        }

        // left eye
        tempVars.quat1.set(context.getOrientation());

        tempVars.quat1.toAngles(tempAngles);
        tempAngles[0] = -tempAngles[0];
        tempAngles[2] = -tempAngles[2];
        tempVars.quat1.fromAngles(tempAngles);

        if(observer != null){
            tempVars.quat1.multLocal(observer.getLocalRotation());
        }

        tempVars.tempMat4.set(context.getLeftEye().getEyeView());
        tempVars.tempMat4.toTranslationVector(tempVars.vect1);
        camLeft.setFrame(tempVars.vect1, tempVars.quat1);

        // right eye
        tempVars.tempMat4.set(context.getRightEye().getEyeView());
        tempVars.tempMat4.toTranslationVector(tempVars.vect1);
        camRight.setFrame(tempVars.vect1, tempVars.quat1);

        tempVars.release();
    }

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.