Google Cardboard Android
Google Cardboard is a device which experience virtual reality in a simple, fun, and inexpensive way. Cardboard main aim to provide virtual reality (VR) tools to allow everyone to enjoy VR in a simple, fun, and natural way.
Cardboard SDK tool enable android and unity application to quickly start creating virtual reality (VR) apps or adapt your existing application for virtual reality (VR).
The cardboard SDK tools provide a simple platform for android and unity so you can focus on building your new immersive experience
Cardboard SDK for Android :- Build apps that display 3D scenes with binocular rendering, track and react to head movements, and interact with apps through magnet input.
Cardboard SDK for Unity :- Easily adapt an existing Unity 3D app for virtual reality or build your own VR experience from scratch.
How It Works with Cardboard SDK for Android :-
The Cardboard SDK toolkit enable android developer familiar with OpenGL to quickly start creating VR applications. SDK toolkit provide many task includes : Lens distortion correction, Head tracking, 3D calibration, Side-by-side rendering, Stereo geometry configuration, User input event handling xperience.The Cardboard SDK requires manifest tags :- Firstly we give permission to cardboard
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.VIBRATE" />android.permission.NFC permission is required by the Cardboard SDK to access Cardboard's NFC tag.
android.permission.VIBRATE permission is required by our demo app to make the phone vibrate to inform the user that something has happened.
We give a permission according to our requirement.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE. These permissions are required by the Cardboard SDK to pair the user's phone to their VR viewer.
The minimum requirement to start cardboard application min SDK Version 16 ( this line indicates that the device must be running API Level 16 (Jellybean) or higher) and target API target SDK Version 19.
Implement CardboardView.StereoRenderer - Then we implement the CardboardView.StereoRenderer. CardboardView.StereoRenderer Interface for renderers that delegate all stereoscopic rendering details to the view. Implementors should simply render a view as they would normally do using the provided transformation parameters. All stereoscopic rendering and distortion correction details are abstracted from the renderer and managed internally by the view.
android.permission.READ_EXTERNAL_STORAGE and android.permission.WRITE_EXTERNAL_STORAGE. These permissions are required by the Cardboard SDK to pair the user's phone to their VR viewer.
The minimum requirement to start cardboard application min SDK Version 16 ( this line indicates that the device must be running API Level 16 (Jellybean) or higher) and target API target SDK Version 19.
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
The activity's required screen orientation is "landscape." This is the orientation you must set for VR apps. The view used by the Cardboard SDK, CardBoard, only renders on fullscreen and landscape (landscape, reverseLandscape, sensorLandscape) modes.
android:screenOrientation="landscape"
The setting android:configChanges="orientation|keyboardHidden" is also recommended, but not mandatory.For exampleThe activity's required screen orientation is "landscape." This is the orientation you must set for VR apps. The view used by the Cardboard SDK, CardBoard, only renders on fullscreen and landscape (landscape, reverseLandscape, sensorLandscape) modes.
android:screenOrientation="landscape"
<uses-feature
android:glEsVersion="0x00030000"
android:required="true"
/>
The intent-filter and specifically com.google.intent.category.CARDBOARD state that this activity is compatible with Cardboard-like viewers. This category is used by the Cardboard App to list compatible apps installed on the user's phone.
Extend CardboardActivity - First we extend the main class through CardboardActivity. The starting point for coding a cardboard application is CardboardActivity. CardboardActivity is the base activity that provides easy integration with Cardboard devices. It exposes events to interact with Cardboards and handles many of the details commonly required when creating an activity for VR rendering.
CardboardActivity uses sticky immersive mode, in which the system UI is hidden, and the content takes up the whole screen. This is a requirement for a VR app, since CardboardView will only render when the activity is in fullscreen mode.The intent-filter and specifically com.google.intent.category.CARDBOARD state that this activity is compatible with Cardboard-like viewers. This category is used by the Cardboard App to list compatible apps installed on the user's phone.
Implement CardboardView.StereoRenderer - Then we implement the CardboardView.StereoRenderer. CardboardView.StereoRenderer Interface for renderers that delegate all stereoscopic rendering details to the view. Implementors should simply render a view as they would normally do using the provided transformation parameters. All stereoscopic rendering and distortion correction details are abstracted from the renderer and managed internally by the view.
public extends
CardboardActivity implementsCardboardView.StereoRenderer {
}
Define a CardboardView with Xml File - All user interface elements in an Android app are built using views. The Cardboard SDK for Android provides its own view,CardboardView , which is a convenience extension of GLSurfaceView that can be used for VR rendering. CardboardView renders content in stereo. You can defines a CardboardView to in its activity layout xml file in the following way:
Then in the main activity class it initializes the CardboardView in the onCreate() method:
Define a CardboardView with Xml File - All user interface elements in an Android app are built using views. The Cardboard SDK for Android provides its own view,CardboardView , which is a convenience extension of GLSurfaceView that can be used for VR rendering. CardboardView renders content in stereo. You can defines a CardboardView to in its activity layout xml file in the following way:
<com.google.vrtoolkit.cardboard.CardboardView
android:id="@+id/cardboard_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"/>
public class Main extends
CardboardActivity implements CardboardView.StereoRenderer {
@Override
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CardboardView cardboardView
= (CardboardView)findViewById(R.id.cardboard_view);
cardboardView.setRenderer(this);
setCardboardView(cardboardView);
}
Render the view - Once you get the CardboardView you associate it with a renderer, and then you associate the CardboardView with the activity. CardboardView.StereoRenderer includes these key methods
onNewFrame() - called every time that app renders.
onDrawEye() - called for each eye with different eye parameters.
Implementing these is similar to what you would normally do for an OpenGL application.
Implement onNewFrame - Use the onNewFrame() method to to encode rendering logic before the individual eyes are rendered. Any per-frame operations not specific to a single view should happen here. This is a good place to update your model. In this snippet, the variable mHeadView contains the position of the head.
}
Render the view - Once you get the CardboardView you associate it with a renderer, and then you associate the CardboardView with the activity. CardboardView.StereoRenderer includes these key methods
onNewFrame() - called every time that app renders.
onDrawEye() - called for each eye with different eye parameters.
Implementing these is similar to what you would normally do for an OpenGL application.
Implement onNewFrame - Use the onNewFrame() method to to encode rendering logic before the individual eyes are rendered. Any per-frame operations not specific to a single view should happen here. This is a good place to update your model. In this snippet, the variable mHeadView contains the position of the head.
/**
* Prepares OpenGL ES before we draw a frame.
* Prepares OpenGL ES before we draw a frame.
*@param headTransform The head transformation in the new frame.
*/
public void onNewFrame(HeadTransform
headTransform) {
...
headTransform.getHeadView(mHeadView,
0);
...
}Implement onDrawEye - Implement onDrawEye() to perform per-eye configuration. This is the meat of the rendering code, and very similar to building a regular OpenGL ES2 application. The following snippet shows how to get the view transformation matrix, and also the perspective transformation matrix. You need to make sure that you render with low latency. The Eye object contains the transformation and projection matrices for the eye. This is the sequence of events.
/**
* Draws a frame for an eye.
*
* @param eye
The eye to render. Includes all required transformations.
*/
@Override
public void
onDrawEye(Eye eye) {
.......
}
}
/**
* Increment the score, hide the object, and
give feedback if the user pulls the magnet while
* looking at the anythings
*/
*/
@Override
public void
onCardboardTrigger() {
...............
}
have you made any sample projects you could share? I am new to google cardboard and need a small jumpstart on this
ReplyDeleteYou can get the sample projects at https://github.com/androidcardboard. For any queries, please feel free to revert.
ReplyDeletehow to create application for toursim using virtual reality
DeleteCheck out https://www.yobi3d.com to look for 3D models for developing Cardboard Apps. It has a VR mode to see the search results in 3D with Cardboard.
ReplyDeleteGood Enough
ReplyDeleteThis is a nice article and information about 3D and virtual Reality.
ReplyDeleteyou can also buy this from ostron http://ostron.in/shop-google-cardboard
Hey Rahul, This is devesh. I'm new to virtual reality and I want to jump start on this. But i am stucked in at a point where i have to make selection in VR Space using gaze control, where user can select an object by pointing through gaze input, any example will help..
ReplyDelete