mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Separate out _spinSpeedFromGyro function.
This commit is contained in:
parent
8da82cfe01
commit
39f69bd8c1
1 changed files with 12 additions and 17 deletions
|
@ -230,15 +230,11 @@ class GdxFor {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_onSensorValueChanged (sensor) {
|
_onSensorValueChanged (sensor) {
|
||||||
let val = sensor.value;
|
|
||||||
const framesPerSec = 1000 / this._runtime.currentStepTime;
|
|
||||||
|
|
||||||
switch (sensor.number) {
|
switch (sensor.number) {
|
||||||
case GDXFOR_SENSOR.FORCE:
|
case GDXFOR_SENSOR.FORCE:
|
||||||
// Normalize the force, which can be measured between -50 and 50 N,
|
// Normalize the force, which can be measured between -50 and 50 N,
|
||||||
// to be a value between -100 and 100.
|
// to be a value between -100 and 100.
|
||||||
val = MathUtil.clamp(val * 2, -100, 100);
|
this._sensors.force = MathUtil.clamp(sensor.value * 2, -100, 100);
|
||||||
this._sensors.force = val;
|
|
||||||
break;
|
break;
|
||||||
case GDXFOR_SENSOR.ACCELERATION_X:
|
case GDXFOR_SENSOR.ACCELERATION_X:
|
||||||
this._sensors.accelerationX = sensor.value;
|
this._sensors.accelerationX = sensor.value;
|
||||||
|
@ -250,26 +246,25 @@ class GdxFor {
|
||||||
this._sensors.accelerationZ = sensor.value;
|
this._sensors.accelerationZ = sensor.value;
|
||||||
break;
|
break;
|
||||||
case GDXFOR_SENSOR.SPIN_SPEED_X:
|
case GDXFOR_SENSOR.SPIN_SPEED_X:
|
||||||
val = MathUtil.radToDeg(val);
|
this._sensors.spinSpeedX = this._spinSpeedFromGyro(sensor.value);
|
||||||
val = val / framesPerSec; // convert to from degrees per sec to degrees per frame
|
|
||||||
val = val * -1;
|
|
||||||
this._sensors.spinSpeedX = val;
|
|
||||||
break;
|
break;
|
||||||
case GDXFOR_SENSOR.SPIN_SPEED_Y:
|
case GDXFOR_SENSOR.SPIN_SPEED_Y:
|
||||||
val = MathUtil.radToDeg(val);
|
this._sensors.spinSpeedY = this._spinSpeedFromGyro(sensor.value);
|
||||||
val = val / framesPerSec; // convert to from degrees per sec to degrees per frame
|
|
||||||
val = val * -1;
|
|
||||||
this._sensors.spinSpeedY = val;
|
|
||||||
break;
|
break;
|
||||||
case GDXFOR_SENSOR.SPIN_SPEED_Z:
|
case GDXFOR_SENSOR.SPIN_SPEED_Z:
|
||||||
val = MathUtil.radToDeg(val);
|
this._sensors.spinSpeedZ = this._spinSpeedFromGyro(sensor.value);
|
||||||
val = val / framesPerSec; // convert to from degrees per sec to degrees per frame
|
|
||||||
val = val * -1;
|
|
||||||
this._sensors.spinSpeedZ = val;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_spinSpeedFromGyro (val) {
|
||||||
|
const framesPerSec = 1000 / this._runtime.currentStepTime;
|
||||||
|
val = MathUtil.radToDeg(val);
|
||||||
|
val = val / framesPerSec; // convert to from degrees per sec to degrees per frame
|
||||||
|
val = val * -1;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
getForce () {
|
getForce () {
|
||||||
return this._sensors.force;
|
return this._sensors.force;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue