Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
tesappcompat7;
import org.json.JSONException;
import org.json.JSONObject;
import
import
import
import
import
import
import
import
import
import
import
import
android.os.Bundle;
android.app.Activity;
android.view.Menu;
android.widget.Toast;
android.app.Activity;
android.content.Context;
android.hardware.Sensor;
android.hardware.SensorEvent;
android.hardware.SensorEventListener;
android.hardware.SensorManager;
android.os.Bundle;
android.widget.TextView;
mSensorManager.unregisterListener(this, mSensor);
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
private static final double NS2S = 1.0f / 1000000000.0f;
private final float[] deltaRotationVector = new float[4];
private double timestamp;
public void onSensorChanged(SensorEvent event) {
String pesan = "0: " + event.values[0] + "\n" +
"1: " + event.values[1] + "\n" +
"2: " + event.values[2] + "\n";
text.setText(pesan);
//text.invalidate();
if (timestamp != 0) {
final double dT = (event.timestamp - timestamp) * NS2S;
// Axis of the rotation sample, not normalized yet.
double axisX = event.values[0];
double axisY = event.values[1];
double axisZ = event.values[2];
// Calculate the angular speed of the sample
double omegaMagnitude = Math.sqrt(axisX*axisX + axisY*axisY
+ axisZ*axisZ);
// Normalize the rotation vector if it's big enough to get t
he axis
// (that is, EPSILON should represent your maximum allowable
margin of error)
if (omegaMagnitude > 0.000000001f) {
axisX /= omegaMagnitude;
axisY /= omegaMagnitude;
axisZ /= omegaMagnitude;
}
// Integrate around this axis with the angular speed by the
timestep
// in order to get a delta rotation from this sample over th
e timestep
// We will convert this axis-angle representation of the del
ta rotation
// into a quaternion before turning it into the rotation mat
rix.
double thetaOverTwo = omegaMagnitude * dT / 2.0f;
double sinThetaOverTwo = Math.sin(thetaOverTwo);
double cosThetaOverTwo = Math.cos(thetaOverTwo);
deltaRotationVector[0] = (float) (sinThetaOverTwo * axisX);
deltaRotationVector[1] = (float) (sinThetaOverTwo * axisY);
deltaRotationVector[2] = (float) (sinThetaOverTwo * axisZ);
deltaRotationVector[3] = (float) cosThetaOverTwo;
}
timestamp = event.timestamp;
float[] deltaRotationMatrix = new float[9];
SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRo
tationVector);
}
@Override