Android Application Development practices

Source: Internet
Author: User
Tags in degrees

The following article describes what Android Application Development is. Before Introducing Android Application Development, let's first understand what Android Application Development is, android is often rumored to be Google phone or GPhone before it is made public.

To implement our Augmented Reality Engine, acceleration sensor data is also needed. However, Android Application Development has simplified the data collection for us. In the previous article about augmented reality technology, our sample program can request the location of the mobile phone and call the registerListener in the location manager object to retrieve the compass data.

We can also use the same technology to request the acceleration sensor data. The code we use to request the acceleration sensor data is as follows:

 
 
  1. sensorMan = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);  
  2. sensorMan.registerListener(listener,  
  3.    sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),  
  4.    SensorManager.SENSOR_DELAY_FASTEST); 

We call the getSystemService method of the context object (ctx in the above Code. The following is the complete code for the direction listener and the acceleration sensor listener.

 
 
  1. private SensorEventListener listener = new SensorEventListener(){  
  2.    public static volatile float direction = (float) 0;  
  3.    public static volatile float inclination;  
  4.    public static volatile float rollingZ = (float)0;  
  5.  
  6.    public static volatile float kFilteringFactor = (float)0.05;  
  7.    public static float aboveOrBelow = (float)0;  
  8.  
  9.    public void onAccuracyChanged(Sensor arg0, int arg1){}  
  10.  
  11.    public void onSensorChanged(SensorEvent evt)  
  12.    {  
  13.       float vals[] = evt.values;  
  14.         
  15.       if(evt.sensor.getType() == Sensor.TYPE_ORIENTATION)  
  16.       {  
  17.          float rawDirection = vals[0];  
  18.  
  19.          direction =(float) ((rawDirection * kFilteringFactor) +   
  20.             (direction * (1.0 - kFilteringFactor)));  
  21.  
  22.           inclination =   
  23.             (float) ((vals[2] * kFilteringFactor) +   
  24.             (inclination * (1.0 - kFilteringFactor)));  
  25.  
  26.                   
  27.           if(aboveOrBelow > 0)  
  28.              inclinationinclination = inclination * -1;  
  29.             
  30.          if(evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER)  
  31.          {  
  32.             aboveOrBelow =  
  33.                (float) ((vals[2] * kFilteringFactor) +   
  34.                (aboveOrBelow * (1.0 - kFilteringFactor)));  
  35.          }  
  36.       }  
  37.    }  
  38. }; 

The code here is a little bit more. Let's take a look at it. First, set all values for the listener. This means that you can query the compass orientation and mobile phone inclination from the listener at any time. These values vary with the update type of your request.

Then, we will receive the sensor information. At this time, we need to determine two main types of information:
1. Mobile phone pointing
2. Tilt Angle of the screen relative to the horizontal plane

The first information is called the azimuth angle, and the second information is called the inclination angle. To determine these values, the first task is to filter out the camera's compass motion. This is called a rolling filter ). The variable direction is used to point to the top of the phone, not the camera itself, so we need to make some corrections.

The Second Mathematical computing task is to use the flip filter to process the slope to obtain a measurement value in degrees, where the horizontal measurement value is 90, the value of the up or down half is 45, and the value of the vertical up or down is 0. Note: When the number is 45, we cannot determine whether the phone is tilted up or down. At this time, the acceleration sensor will be used.

It can determine the positive and negative angle, positive value indicates from the horizontal line up, copy indicates from the horizontal line down. In short, everything we need can be obtained from the accelerometer. So far, we have introduced all the tools required to build your own Augmented Reality Technology engine. You still need a little mathematical knowledge, some Android Application Development, and a lot of energy.

If you are far more interested in building augmented reality applications than creating the Augmented Reality Engine itself, you can focus on an open source Augmented Reality Technology engine that I am currently developing for Android. To get more progress, follow twitter.com/androidarkiton Twitter. Although I like to try to put all the mathematical and drawing Code together and fold the three types of information onto the camera.

However, these are beyond the scope of this article. However, in addition to the previous article, this article has made a comprehensive introduction to Android's compass, camera preview, accelerometer and GPS subsystem. Now you have all the components required to create large-scale augmented reality technology applications.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.