Last active
July 22, 2018 11:06
-
-
Save keicoon/8b75d592d031d57ceb0382990c47f2a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* ASCII text | |
"use strict"; | |
function NormalizeVector(v) { | |
const l = 1 / (v.x * v.x + v.y + v.y); | |
v.x *= l; v.y *= l; | |
return v; | |
} | |
function GetAngleBetweenVectors(pre, cur) { | |
const ceta = Math.acos(pre.x * cur.x + pre.y * cur.y); | |
return Math.min(ceta, Math.PI - ceta); // NOTE: Positive number | |
} | |
module.export = class TwoFinger { | |
TwoFinger() { | |
this.preVec2D = { x: 0, y: 0 }; | |
this.callbacks = new Array(); | |
} | |
RegisterEvent(callback) { | |
this.callbacks.push(callback); | |
} | |
UnregisterEvent(callback) { | |
this.callbacks.remove(callback); | |
} | |
Update(x1, y1, x2, y2) { | |
const curVec2D = NormalizeVector({ x: x2 - x1, y: y2 - y1 }); // NOTE: Noralized vector | |
const ceta = GetAngleBetweenVectors(this.preVec2D, curVec2D); | |
// TODO: update model rotaion | |
// const EPSILON = 0.0314; | |
// if (ceta > EPSILON) { | |
// this.callbacks.forEach(callback => callback(ceta)); | |
// } | |
this.preVec2D = curVec2D; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment