I have only two rules which I regard as principles of conduct.
The first is: Have no rules.
The second is: Be independent of the opinion of others.
-Albert Einstein
In everything, do to others what you would want them to do to you.
-Jesus
We need to be the change we wish to see in the world.
-Mahatma Gandhi
If I have seen further it is only by standing on the shoulders of giants.
-Isaac Newton
It is not enough to have a good mind.
The main thing is to use it well.
-Descartes
In this first lesson you will learn how to setup your project in order to use the virtual reality library, this is something you will have to do for each new application you create. And while the final executable in this lesson will present nothing but a black window, it lays the ground for all future lessons, which makes reading it well worth it.
It is assumed that you are familiar with openGL, especially openGL for android. If you are new to openGL or openGL for android, I recommend that you first take a look at
Nehe Android Ports at INsanityDesign.
It is throughout these lessons also assumed that development takes place in an Eclipse development environment. This is however not essential to much more than the content of this lesson, and most of the lessons that follows should be possible to follow without any modifications. If you develop in a differenet environment than Eclipse, this first lesson might however be a little more tricky, and you have to work out some of the steps by yourself. With just a little knowledge of your development environment, you should however have no problem of taking the information in this lesson and apply it in your own environment.
For the complete application produced in this lesson, click
here. (Not very interesting, just a black screen. See lesson 2 for the first screen output, and 3 and forward for real virtual reality.)
Creating a project and adding the virtualreality.jar file
Start by creating a new project (File -> New -> Project, choose Andriod Project and Click next). Call the project VRFirst, choose "Android 1.5" as build target, and enter the following values into the property fields:
Application name: VRFirst
Pacakage name: com.dafer45.virtualreality
Create Activity: VRFirst
Min SDK: 3
Finally click Finish.
The project is now created, and the next thing to do is to add the virtual reality library to it. To do this, right click the VRFirst folder in the Package window and create a new folder (New -> Folder). Enter libs as folder name and click Finish. Then copy
VirtualReality_v0d1.jar into the libs folder. Next right click the VRFirst folder and select properties. From the left menu, choose "Java Build Path", click the "Libraries" tab, and then "Add JARs". Open "VRFirst/libs" and select the VirtualReality_v0d1.jar file and click OK twice.
Creating the layout file
Now open "/res/layout/main.xml" and replace the content with the following:
This defines a layout that consists of a single virtualRealityView which fills the whole screen and has the id "virtualRealityView". The last line android:keepScreenOn="true" ensures that the screen will not shut of after a few seconds of usage, which would be quite anoying here.
The manifest file
We are expected to turn the phone around alot when using it together with a virtual reality view. It does therefore not make sense to have the phone jumping between landscape and portrait mode. In addition, by default the android application is destroyed and recreated each time it passes between landscape and portrait mode. A behaviour we not want in this case. To solve this we add the following two line to the Activity-tag in the AndroidManifest.xml file:
android:screenOrientation="landscape"
android:configChanges="orientation"
To do this, open AndroidManifest.xml and click the AndroidManifest.xml tab below the window and make sure that the content is the following
The Activity
Finally open the file "src/com.dafer45.virtualreality/VRFirst.java" and make sure the content is the following
package com.dafer45.virtualreality;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class VRFirst extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window win = getWindow();
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
}
The line
setContentView(R.layout.main)
is what sets our virtual reality layout to actually be displayed by the activity, and the three lines
Window win = getWindow();
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
that preceeds it makes the title and statusbar disappear.
That's it
These steps completes our setup of the project. This is the most boring part, but is something that has to be done for each new project, and you will soon find yourself doing it very quickly. Once it's done we are ready to continue with the actual development, which will be a lot of fun!
Continue with lesson 2