private void processMagnetometerEvent(SensorEvent event) { Matrix magneticInWorld = worldBase.to( new Matrix(1, 3, new double[] {event.values[0], event.values[1], event.values[2]})); mMagnetometerVector.setValues( magneticInWorld.getValue(0, 0), magneticInWorld.getValue(1, 0), magneticInWorld.getValue(2, 0)); }
private void processAccelerometerEvent(SensorEvent event) { for (int i = 0; i < 3; i++) { mAccMovingAverage[i].push(event.timestamp, event.values[i]); } long timestamp = event.timestamp; if (mLastAccTimeStamp == 0) { mLastAccTimeStamp = timestamp; // throw away the first event if // timestamp not set return; } boolean realign = realignCondition(); long now = System.nanoTime(); if (realign && now - lastRealignTimestamp > NANO) { lastRealignTimestamp = now; mTouched = false; // worldBase.realign(new Matrix(1, 3, new double[] {} ), 3); Vector3d axisZ = worldBase.getAxis(2); // z axis Vector3d acc = new Vector3d( mAccMovingAverage[0].getAverage(), mAccMovingAverage[1].getAverage(), mAccMovingAverage[2].getAverage()); Vector3d rotationVector = axisZ.normalize().crossProduct(acc.normalize()); double[] rotationMatrix = Transform.getRotationMatrixSORA(rotationVector.getValues()); worldBase.transform(new Matrix(3, 3, rotationMatrix)); mAccModel.reset(); } // double deltaT = (double) (timestamp - mLastAccTimeStamp) / NANO; // Log.d(TAG, "values = (" + values[0] + ", " + values[1] + ", " + // values[2] + "), deltaT = " + deltaT); if (timestamp != 0) { Matrix accelerationInWorld = worldBase.to( new Matrix(1, 3, new double[] {event.values[0], event.values[1], event.values[2]})); mAccModel.processAccelerometerEvent( timestamp, (float) accelerationInWorld.getValue(0, 0), (float) accelerationInWorld.getValue(1, 0), (float) accelerationInWorld.getValue(2, 0)); mAccelerationVector.setValues( accelerationInWorld.getValue(0, 0), accelerationInWorld.getValue(1, 0), accelerationInWorld.getValue(2, 0)); } mLastAccTimeStamp = timestamp; }