Example project for integration Rajawali and Cardboard SDK.
Sample photo is from http://eje-c.com/vr_promotion/.
There are 3 modules in this project.
- rajawali is a copy of Rajawali (see below).
- rajawalicardboard is a glue module which integrates Cardboard SDK and Rajawali. This module provides two classes
RajawaliCardboardViewandRajawaliCardboardRenderer. Your renderer should extendRajawaliCardboardRendererand you should putRajawaliCardboardViewto render your scene. - app is an example app. This simply shows 360 panorama photo.
- Download in ZIP or clone this repository.
- Create new project with Android Studio. Cardboard SDK requires SDK Level 16 so you should select API 16 or higher.
- Select File->Import Module...
- Browse to
rajawalicardboarddirectory and click Finish button.rajawalidirectory is also required. But it is automatically imported whenrajawalicardboardis imported. - Add module dependency in
appmodule. Open%Project ROOT%/app/build.gradleand addcompile project(':rajawalicardboard')independenciesblock. - Edit
AndroidManifest.xmlto launchMainActivityin landscape mode. Open%Project ROOT%/app/src/main/AndroidManifest.xmland addandroid:screenOrientation="landscape"attribute to<activity>. - Modify your
MainActivitylike this.
public class MainActivity extends CardboardActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RajawaliCardboardView view = new RajawaliCardboardView(this);
setContentView(view);
setCardboardView(view);
RajawaliCardboardRenderer renderer = new MyRenderer(this); // your renderer
view.setRenderer(renderer); // required for CardboardView
view.setSurfaceRenderer(renderer); // required for RajawaliSurfaceView
}
private static class MyRenderer extends RajawaliCardboardRenderer {
public MyRenderer(Context context) {
super(context);
}
@Override
protected void initScene() {
// create your scene
}
}
}Your renderer should extend RajawaliCardboardRenderer and create your scene in initScene(). Nothing is special. Just create an normal scene like you did in RajawaliRenderer.
Camera is automatically rotated with gyro sensor. You should not set camera's orientation manually.
This project has own copy of Rajawali because I have to edit one line of codes. Edited line is #1011 line of org.rajawali3d.scene.RajawaliScene.
...
} else {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
GLES20.glClearColor(mRed, mGreen, mBlue, mAlpha);
}
...to
...
} else {
// GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
GLES20.glClearColor(mRed, mGreen, mBlue, mAlpha);
}
...I do not guarantee that my copy of rajawali is up to date. Rajawali will support VR soon. This project is considered for temporary use.
