Laya重力感应
陀螺仪Gyroscope
Laya
.Gyroscope
.instance
.on(Laya
.Event
.CHANGE, this, onDeviceorientation
);
function onDeviceorientation (absolute
, rotationInfo
){
var alpha
= rotationInfo
.alpha
;
var beta
= rotationInfo
.beta
;
var gamma
= rotationInfo
.gamma
;
}
beta = beta > 20 ? 20 : beta < -20 ? -20 : beta;
gamma = gamma > 20 ? 20 : gamma < -20 ? -20 : gamma;
this.bg.bg.x = 0 + -beta / 20 * 10;
this.bg.bg.y = 0 + gamma / 20 * 10;
this.bg.f1.x = 0 + beta / 20 * 10;
// this.bg.m1.x = beta / 20 * 3;
this.bg.f1.y = 750 + -gamma / 20 * 10;
东(X)在地面上,垂直于北轴,向东为正。北(Y)在地面上,向正北为正(指向北极)。上(Z)垂直于地面,向上为正。
对于一个移动设备,例如电话或平板,设备坐标系的定义于屏幕的标准方向相关。 如果在设备旋转或展开滑动键盘时屏幕方向发生变化,这不会影响关于设备的坐标系的方向。
x在屏幕或键盘平面上,屏幕或键盘的右侧为正。y在屏幕或键盘屏幕上,屏幕或键盘的上方为正。z垂直于屏幕或键盘屏幕,离开屏幕或键盘为正。
加速计
Laya
.Accelerator
.instance
.on(Laya
.Event
.CHANGE, this, monitorAccelerator
);
function monitorAccelerator(acceleration
,accelerationIncludingGravity
,rotationRate
,interval
){
var vx
= accelerationIncludingGravity
.x
;
var vy
= accelerationIncludingGravity
.y
;
var a
= Laya
.Accelerator
.getTransformedAcceleration(acceleration
);
console
.log("加速度", acceleration
);
console
.log("设备的加速度", vx
, vx
);
console
.log("自转速率", ~~a
.x
, ~~a
.y
, ~~a
.z
);
console
.log("时间间隔", interval
);
}