title: Pass Compass values
body: <p>I would like to use my compass' values to make a 3D compass. When I'm writing out the values in a textView, it work properly. But when I'm trying to pass the values to an external variable, adn the write out these external variable's value in a TextView, they always show ZERO VALUES. So is there anyway to use the sensor's values in a GLSurfaceView?</p>
  
  <p>This code works:</p>
  
  <pre><code>  @Override
       public void onSensorChanged(SensorEvent event) {
            switch(event.sensor.getType()){
                  case Sensor.TYPE_ACCELEROMETER:
                      for(int i =0; i &lt; 3; i++){
                          valuesAccelerometer[i] = event.values[i];
                      }
                      break;
                  case Sensor.TYPE_MAGNETIC_FIELD:
                      for(int i =0; i &lt; 3; i++){
                          valuesMagneticField[i] = event.values[i];
                      }
                      break;
              }
  
              boolean success = SensorManager.getRotationMatrix(matrixR, matrixI, valuesAccelerometer, valuesMagneticField);
              if(success){
                  SensorManager.getOrientation(matrixR, matrixValues);
                  double azimuth = Math.toDegrees(matrixValues[0]);
                  double pitch = Math.toDegrees(matrixValues[1]);
                  double roll = Math.toDegrees(matrixValues[2]);
  
                  readingAzimuth.setText("Azimuth: " + String.valueOf(azimuth));
                  readingPitch.setText("Pitch: " + String.valueOf(pitch));
                  readingRoll.setText("Roll: " + String.valueOf(roll));
              }
          }
  </code></pre>
  
  <p>But this code doesn't:</p>
  
  <pre><code> public double azimuth;
   public double pitch 
   public double roll
  
   @Override
   public void onSensorChanged(SensorEvent event) {
            switch(event.sensor.getType()){
                  case Sensor.TYPE_ACCELEROMETER:
                      for(int i =0; i &lt; 3; i++){
                          valuesAccelerometer[i] = event.values[i];
                      }
                      break;
                  case Sensor.TYPE_MAGNETIC_FIELD:
                      for(int i =0; i &lt; 3; i++){
                          valuesMagneticField[i] = event.values[i];
                      }
                      break;
              }
  
              boolean success = SensorManager.getRotationMatrix(matrixR, matrixI, valuesAccelerometer, valuesMagneticField);
              if(success){
                  SensorManager.getOrientation(matrixR, matrixValues);
                  azimuth = Math.toDegrees(matrixValues[0]);
                  pitch = Math.toDegrees(matrixValues[1]);
                  roll = Math.toDegrees(matrixValues[2]);
              }
          }
  </code></pre>