Now with new hope some will be proud
This is no hoax, no one pushed out
Receive a reprieve and be a pioneer
Break new ground of a new frontier
New ideas will surely get by
No deed, or dividend. Some may ask "Why?"
You'll find the solution, the answers in the sky
A hundred times every day I remind myself that my
inner and outer life are based on the labors of
other men, living and dead, and that I must exert
myself in order to give in the same measure as I
have received and am still receiving...
The worthwhile problems are the ones you can really solve or help solve,
the ones you can really contribute something to. ...
No problem is too small or too trivial if we can really do something about it.
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.
In everything, do to others what you would want them to do to you.
What we are is the sum of 1000 lives
What we know is almost nothing at all
But we are what we are until the day we die
Together we will find the strength to go on
-Rise against (intentionally missquoted and
taken out of context)
We need to be the change we wish to see in the world.
Seven social sins:
politics without principles,
wealth without work,
pleasure without conscience,
knowledge without character,
commerce without morality,
science without humanity,
and worship without sacrifice.
If I have seen further it is only by standing on the shoulders of giants.
It is not enough to have a good mind.
The main thing is to use it well.
A loud "Fuck yeah!"
-From my heart (with James Hetfield's voice)
Would you like to support the development? Please feel free to make a donation.
-- Kristofer Björnson
Contact me at: firstname.lastname@example.org
Virtual reality - Lesson 4
We now know how to setup an orientation handler so that we can look in different directions in the scene by simply turning the phone around. The steps taken in this lesson will be very similar to those in that last one. By adding a location handler we will after this lesson also be able to move around in the scene.
For the complete files produced in this lesson, click here.
For the complete application produced in this lesson, click here.
Before we proceede with this lesson it should be mentioned that when using the GPS for location handling, as is done in this lesson, there is a certain limit to the precission and update speed that can be obtained. We have to accept that the GPS can be unavailable for some time and that it needs some initial time before a steady signal is recieved after up start. These limitations will have to be taken into consideration when deciding what types of applications one wants to create. Games that relies on GPS positioning are probably the first thing that comes to mind as being problematic to create. And indeed, a 3D real world shooter is probably far from possible to create with the current technology. But still an augmented reality chess game, intended to be played on a large field with chess pieces large as cars would probably be possible. And it could certainly be a mighty experience to play such a game. The key points to consider is that the applications not can rely on a very quick position update, and that it certainly not can rely on a precission less than a meter. Experience has to guide in deciding what applications to create.
Now, lets continue with this lesson.
Just like the camera orientation was handled by an implementation of VROrientationHandler, the cameras location is handled with an implementation of VRLocationHandler. In a similar way, it is also possible to implement a custom location handler by implementing the VRLocationHandler interface, but we will here use the prepacked GPSLocationHandler.
The GPSLocationHandler can operate in three different modes. Either in a local mode, where the origo is fixed to a nearby position by the application, or in one of two global modes, where the origo is fixed to the earth. The global modes can for example be useful in an augmented reality application, where the actual GPS coordinate matters. For viewing a model, or possibly for use in a virtual reality game, the local mode is however more suitable because the scene can be built around the origo, and the origo of the coordinate system be set to the point on earth where the phone is located at the upstart. The application we build in this lesson will be a kind of model view application and we therefore choose to use the local mode.
The first thing to do is to import the GPSLocationHandler with
Then add a GPSLocationHandler reference in the VRFirst class with
private GPSLocationHandler gpsLocationHandler;
Now create the GPSLocationHandler in the local mode and add it to the VirtualRealityView by adding the following lines to the onCreate-method
new GPSLocationHandler(this, GPSLocationHandler.MODE_LOCAL_ORIGO);
Because the GPSLocationHandler registers to recieve gps signals at creation, it has to be destroyed at the destruction of the application. This procedure is similarly as for the destruction of the LocalOrientationHandler. Simply add the following line to the onDestroy-method
Setting the origo
Because we use a local origo in this application, we have to have a way of setting it. Here we do this in the simplest way imaginable, we add a button to our layout which will reset the origo to the phones current position.
To do this, open the layout file main.xml and add the following right before the VirtualRealityView tag.
Now go back to theVRFirst.java file and import the Button, OnClickListener and View classes with
Allowing the application to access the GPS
The final thing we have to do is to edit the manifest file so that the application is allowed to access the GPS. To do this, open AndroidManifest.xml and add the following lines before the final tag </manifest> .
Get out and try it
The application is now ready to be compiled, and it is time to get outdoor to try it. Because the GPS signal is to weak indoor it is very unlikely that it will work unless you get out under the open sky. Initially the application will behave just similarly to that compiled in lesson 3. However, once the GPS starts to recieve signals, all the blocks will disapear from the screen. When this happens it is time to click the "F"-button to fix the origo at your current location, and the blocks should once again show up around you and you can start walking around them (you might have to refix the origo a couple of times before the origo gets fixed quite stable at your location, this is because the positioning is quite unreliable in the begining). Notice however that the blocks will jump quite irregularly, and that it not at all is as smooth as one ideally would like. With bigger blocks located at a farther distance, the irregular jumping will not be at all as disturbing, and this is the kind of considerations that has to be taken account of when starting to design real applications.
A note on the realtion between the real world scales and virtual reality coordinate system scales is also approperiate here. When using the GPSLocationHandler, each unit in the virtual reality coordinates corresponds to one meter in reality. If you therefore place an object at (50, 0, 0), you will have to walk 50 meter to the east to get there. (Note that it here is assumes that you also use the LocalOrientationHandler to determine directions).