Created
March 7, 2019 07:48
-
-
Save pofulu/2942212cd4b271b9543c2e84571d176e to your computer and use it in GitHub Desktop.
Script for Spark AR, make SceneObject dragable with TouchGestures.
This file contains 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
// const Scene = require('Scene'); | |
// new Dragable(Scene.root.find('plane0')); | |
function Dragable(object) { | |
const CameraInfo = require('CameraInfo'); | |
const TouchGestures = require('TouchGestures'); | |
const width = CameraInfo.previewSize.width; | |
const height = CameraInfo.previewSize.height; | |
let widthMax = width.div(height).mul(25); | |
let widthMin = widthMax.mul(-1); | |
TouchGestures.onPan(object).subscribe(event => { | |
object.transform.x = RemapSingal(event.location.x, Reactive.val(0), width, widthMin, widthMax); | |
object.transform.y = RemapSingal(event.location.y, Reactive.val(0), height, Reactive.val(25), Reactive.val(-25)); | |
}); | |
TouchGestures.onPinch(object).subscribe(event => { | |
const sx = object.transform.scaleX.pinLastValue(); | |
object.transform.scaleX = Reactive.mul(sx, event.scale); | |
const sy = object.transform.scaleY.pinLastValue(); | |
object.transform.scaleY = Reactive.mul(sy, event.scale); | |
}); | |
TouchGestures.onRotate(object).subscribe(event => { | |
object.transform.rotationZ = Reactive.add(object.transform.rotationZ.pinLastValue(), Reactive.mul(-1, event.rotation)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment