implementing input.rotation
This commit is contained in:
parent
1c403e4ddb
commit
9f0f63a79e
@ -306,6 +306,25 @@ namespace pxsim.input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function rotation(kind : number) : number {
|
||||||
|
let b = board();
|
||||||
|
let acc = b.accelerometer;
|
||||||
|
acc.activate();
|
||||||
|
let x = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||||
|
let y = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||||
|
let z = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
|
||||||
|
|
||||||
|
let roll = Math.atan2(y,z);
|
||||||
|
let pitch = Math.atan(-x / (y*Math.sin(roll) + z*Math.cos(roll)));
|
||||||
|
|
||||||
|
let r = 0;
|
||||||
|
switch(kind) {
|
||||||
|
case 0: r = pitch; break;
|
||||||
|
case 1: r = roll; break;
|
||||||
|
}
|
||||||
|
return Math.floor(r / Math.PI * 180);
|
||||||
|
}
|
||||||
|
|
||||||
export function setAccelerometerRange(range: number) {
|
export function setAccelerometerRange(range: number) {
|
||||||
let b = board();
|
let b = board();
|
||||||
b.accelerometer.setSampleRange(range);
|
b.accelerometer.setSampleRange(range);
|
||||||
|
Loading…
Reference in New Issue
Block a user