fix for roll/pitch in simulator.

fix for https://github.com/Microsoft/pxt/issues/893
This commit is contained in:
Peli de Halleux 2016-12-08 12:14:34 -08:00
parent d791738d84
commit 3d0523a298

View File

@ -23,15 +23,15 @@ namespace pxsim.input {
} }
export function rotation(kind: number): number { export function rotation(kind: number): number {
let b = board().accelerometerState; const b = board().accelerometerState;
let acc = b.accelerometer; const acc = b.accelerometer;
acc.activate(); acc.activate();
let x = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); const x = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
let y = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); const y = acc.getY(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
let z = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); const z = acc.getZ(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
let roll = Math.atan2(y, z); const roll = Math.atan2(y, z);
let pitch = Math.atan(-x / (y * Math.sin(roll) + z * Math.cos(roll))); const pitch = Math.atan(-x / (y * Math.sin(roll) + z * Math.cos(roll)));
let r = 0; let r = 0;
switch (kind) { switch (kind) {