From b5fb80190d93faebb4e713d99e370038213d9567 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Mon, 28 Jan 2019 17:06:14 -0500 Subject: [PATCH] Factor out and scale spin speed --- src/extensions/scratch3_gdx_for/index.js | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/extensions/scratch3_gdx_for/index.js b/src/extensions/scratch3_gdx_for/index.js index 7b1201c79..614d1fabe 100644 --- a/src/extensions/scratch3_gdx_for/index.js +++ b/src/extensions/scratch3_gdx_for/index.js @@ -318,24 +318,26 @@ class GdxFor { } getSpinSpeedX () { - if (this._canReadSensors()) { - return this._device.getSensor(5).value * (180 / Math.PI); - } - return 0; + return this._getSpinSpeed(5); } getSpinSpeedY () { - if (this._canReadSensors()) { - return this._device.getSensor(6).value * (180 / Math.PI); - } - return 0; + return this._getSpinSpeed(6); } getSpinSpeedZ () { - if (this._canReadSensors()) { - return this._device.getSensor(7).value * (180 / Math.PI); - } - return 0; + return this._getSpinSpeed(7); + } + + _getSpinSpeed (sensorNum) { + if (!this._canReadSensors()) return 0; + let val = this._device.getSensor(sensorNum).value; + val = MathUtil.radToDeg(val); + const framesPerSec = 1000 / this._runtime.currentStepTime; + val = val / framesPerSec; // convert to from degrees per sec to degrees per frame + val = Math.round(val); + val = val * -1; + return val; } }