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
RajawaliCardboardView
andRajawaliCardboardRenderer
. Your renderer should extendRajawaliCardboardRenderer
and you should putRajawaliCardboardView
to 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
rajawalicardboard
directory and click Finish button.rajawali
directory is also required. But it is automatically imported whenrajawalicardboard
is imported. - Add module dependency in
app
module. Open%Project ROOT%/app/build.gradle
and addcompile project(':rajawalicardboard')
independencies
block. - Edit
AndroidManifest.xml
to launchMainActivity
in landscape mode. Open%Project ROOT%/app/src/main/AndroidManifest.xml
and addandroid:screenOrientation="landscape"
attribute to<activity>
. - Modify your
MainActivity
like 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.