私は主な活動をしています
public class MainActivity extends Activity {
private static SensorManager sensorService;
private GLSurfaceView view;
private Sensor sensor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
GLSurfaceView view = new GLSurfaceView(this);
view.setRenderer(new SceneView());
setContentView(view);
sensorService = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensor = sensorService.getDefaultSensor(Sensor.TYPE_ORIENTATION);
if (sensor != null) {
sensorService.registerListener(mySensorEventListener, sensor,
SensorManager.SENSOR_DELAY_NORMAL);
Log.i("Compass MainActivity", "Registerered for ORIENTATION Sensor");
} else {
Log.e("Compass MainActivity", "Registerered for ORIENTATION Sensor");
Toast.makeText(this, "ORIENTATION Sensor not found",
Toast.LENGTH_LONG).show();
finish();
}
}
private SensorEventListener mySensorEventListener = new SensorEventListener() {
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
public void onSensorChanged(SensorEvent event) {
// angle between the magnetic north directio
// 0=North, 90=East, 180=South, 270=West
float azimuth = event.values[0];
view.updateData(azimuth);
}
};
@Override
protected void onDestroy() {
super.onDestroy();
if (sensor != null) {
sensorService.unregisterListener(mySensorEventListener);
}
}
}
と
シーン
public class SceneView implements GLSurfaceView.Renderer {
private float position = 0;
private Square mSquare;
public SceneView() {
mSquare = new Square();
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -6);
mSquare.draw(gl);
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void updateData(float position) {
}
}
これを解決する方法でnullであるため、呼び出すupdateData
とエラーが発生しますか?view
SensorEventListener mySensorEventListener
http://www.vogella.com/articles/AndroidSensor/article.html著者の使用extends View
と彼のコードは完全に機能し、別のコンストラクター手順で使用するとimplements GLSurfaceView.Renderer
すべてが壊れます