Created
January 4, 2019 15:50
-
-
Save benursu/9e037ebc7ddab445b76c983ead62b6dd to your computer and use it in GitHub Desktop.
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
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
// Laser Focused | |
// Ben Ursu | Afrosquared | |
// Spark AR Studio | |
// Instagram | https://www.instagram.com/a/r/?effect_id=206763150244323 | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
//require | |
const Scene = require('Scene'); | |
const Animation = require('Animation'); | |
const R = require('Reactive'); | |
const D = require('Diagnostics'); | |
const Time = require('Time'); | |
const Materials = require('Materials'); | |
const Textures = require('Textures'); | |
const Patches = require('Patches'); | |
const FT = require('FaceTracking'); | |
const Instruction = require('Instruction'); | |
// const TouchGestures = require('TouchGestures'); | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
//scene | |
var canvas = Scene.root.find('canvas'); | |
// var canvasInstructions = Scene.root.find('canvasInstructions'); | |
var zero = Scene.root.find('zero'); | |
var facetracker0 = Scene.root.find('facetracker0'); | |
var facetracker1 = Scene.root.find('facetracker1'); | |
var planeLaserMiddle0 = Scene.root.find('planeLaserMiddle0'); | |
var planeLaserMiddle1 = Scene.root.find('planeLaserMiddle1'); | |
var planeLaser0Left = Scene.root.find('planeLaser0Left'); | |
var planeLaser0Right = Scene.root.find('planeLaser0Right'); | |
var planeLaser1Left = Scene.root.find('planeLaser1Left'); | |
var planeLaser1Right = Scene.root.find('planeLaser1Right'); | |
var laserContainer0Left = Scene.root.find('laserContainer0Left'); | |
var laserContainer0LeftLine = laserContainer0Left.child('line'); | |
var laserContainer0LeftLaser = laserContainer0LeftLine.child('laser'); | |
var laserContainer0LeftEmitterShortEnd = laserContainer0Left.child('emitterShortEnd'); | |
var laserContainer0Right = Scene.root.find('laserContainer0Right'); | |
var laserContainer0RightLine = laserContainer0Right.child('line'); | |
var laserContainer0RightLaser = laserContainer0RightLine.child('laser'); | |
var laserContainer0RightEmitterShortEnd = laserContainer0Right.child('emitterShortEnd'); | |
var laserContainer1Left = Scene.root.find('laserContainer1Left'); | |
var laserContainer1LeftLine = laserContainer1Left.child('line'); | |
var laserContainer1LeftLaser = laserContainer1LeftLine.child('laser'); | |
var laserContainer1LeftEmitterShortEnd = laserContainer1Left.child('emitterShortEnd'); | |
var laserContainer1Right = Scene.root.find('laserContainer1Right'); | |
var laserContainer1RightLine = laserContainer1Right.child('line'); | |
var laserContainer1RightLaser = laserContainer1RightLine.child('laser'); | |
var laserContainer1RightEmitterShortEnd = laserContainer1Right.child('emitterShortEnd'); | |
var laserExplosion0IntroMaterial = Materials.get('laserExplosion0Intro'); | |
var laserExplosion1IntroMaterial = Materials.get('laserExplosion1Intro'); | |
// var instructions = canvasInstructions.child('instructions'); | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
//init | |
var rotation180 = Math.PI; | |
var rotation360 = Math.PI * 2; | |
var vectorForward = R.vector(1, 0, 0); | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
////////////////////////////////////////////////////////////////////////// | |
//lasers | |
var laserContainerLaserRotateDuration = 6000; | |
var planeLaserMiddleDuration = 800; | |
var planeLaserMiddleZStart = 98.97576; | |
var planeLaserMiddleZEnd = 31.60554; | |
var planeLaserMiddleZRatio = 6; | |
var planeLaserMiddle0XDriver; | |
var planeLaserMiddle0YDriver; | |
var planeLaserMiddle0ZDriver; | |
var planeLaserMiddle1XDriver; | |
var planeLaserMiddle1YDriver; | |
var planeLaserMiddle1ZDriver; | |
var planeLaserMiddleTimeout; | |
var laserExplosionIntroMaterialStart = 0.14; | |
var laserExplosion0IntroMaterialDriver; | |
var laserExplosion1IntroMaterialDriver; | |
////////////////////////////////////////////////////////////////////////// | |
//face | |
var face0IsTracking = false; | |
var face1IsTracking = false; | |
var subscription = FT.count.monitor({fireOnInitialValue: true}).subscribeWithSnapshot({ 'FT.face(0).isTracked': FT.face(0).isTracked, 'FT.face(1).isTracked': FT.face(1).isTracked }, function(e, snapshots) { | |
var face0IsTrackingPrevious = face0IsTracking; | |
var face1IsTrackingPrevious = face1IsTracking; | |
if(planeLaserMiddleTimeout){ | |
Time.clearTimeout(planeLaserMiddleTimeout); | |
} | |
if(snapshots['FT.face(0).isTracked']){ | |
planeLaser0Left.transform.x = FT.face(0).cameraTransform.applyTo(FT.face(0).leftEye.center).x; | |
planeLaser0Left.transform.y = FT.face(0).cameraTransform.applyTo(FT.face(0).leftEye.center).y; | |
planeLaser0Left.transform.z = FT.face(0).cameraTransform.applyTo(FT.face(0).leftEye.center).z.add(53); | |
planeLaser0Right.transform.x = FT.face(0).cameraTransform.applyTo(FT.face(0).rightEye.center).x; | |
planeLaser0Right.transform.y = FT.face(0).cameraTransform.applyTo(FT.face(0).rightEye.center).y; | |
planeLaser0Right.transform.z = FT.face(0).cameraTransform.applyTo(FT.face(0).rightEye.center).z.add(53); | |
laserContainer0Left.hidden = false; | |
laserContainer0Right.hidden = false; | |
if(!face0IsTracking){ | |
planeLaserMiddle0.hidden = false; | |
planeLaserMiddle0.transform.x = (planeLaser1Right.transform.x.add((planeLaser0Left.transform.x.sub(planeLaser1Right.transform.x)).div(2))).div(planeLaserMiddleZRatio); | |
planeLaserMiddle0.transform.y = (planeLaser1Right.transform.y.add((planeLaser0Left.transform.y.sub(planeLaser1Right.transform.y)).div(2))).div(planeLaserMiddleZRatio); | |
planeLaserMiddle0Stop(); | |
planeLaserMiddle0ZDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration}); | |
var sampler = Animation.samplers.easeInOutQuad(planeLaserMiddleZEnd, planeLaserMiddleZStart); | |
planeLaserMiddle0.transform.z = Animation.animate(planeLaserMiddle0ZDriver, sampler); | |
planeLaserMiddle0ZDriver.start(); | |
laserExplosion0IntroMaterialDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration}); | |
var sampler = Animation.samplers.easeInOutQuad(0, laserExplosionIntroMaterialStart); | |
laserExplosion0IntroMaterial.opacity = Animation.animate(laserExplosion0IntroMaterialDriver, sampler); | |
laserExplosion0IntroMaterialDriver.start(); | |
} | |
face0IsTracking = true; | |
}else{ | |
planeLaserMiddle0.hidden = true; | |
planeLaserMiddle0.transform.x = 0; | |
planeLaserMiddle0.transform.y = 0; | |
laserContainer0Left.hidden = true; | |
laserContainer0Right.hidden = true; | |
face0IsTracking = false; | |
} | |
if(snapshots['FT.face(1).isTracked']){ | |
planeLaser1Left.transform.x = FT.face(1).cameraTransform.applyTo(FT.face(1).leftEye.center).x; | |
planeLaser1Left.transform.y = FT.face(1).cameraTransform.applyTo(FT.face(1).leftEye.center).y; | |
planeLaser1Left.transform.z = FT.face(1).cameraTransform.applyTo(FT.face(1).leftEye.center).z.add(53); | |
planeLaser1Right.transform.x = FT.face(1).cameraTransform.applyTo(FT.face(1).rightEye.center).x; | |
planeLaser1Right.transform.y = FT.face(1).cameraTransform.applyTo(FT.face(1).rightEye.center).y; | |
planeLaser1Right.transform.z = FT.face(1).cameraTransform.applyTo(FT.face(1).rightEye.center).z.add(53); | |
laserContainer1Left.hidden = false; | |
laserContainer1Right.hidden = false; | |
if(!face1IsTracking){ | |
planeLaserMiddle1.hidden = false; | |
planeLaserMiddle1.transform.x = (planeLaser1Right.transform.x.add((planeLaser0Left.transform.x.sub(planeLaser1Right.transform.x)).div(2))).div(planeLaserMiddleZRatio); | |
planeLaserMiddle1.transform.y = (planeLaser1Right.transform.y.add((planeLaser0Left.transform.y.sub(planeLaser1Right.transform.y)).div(2))).div(planeLaserMiddleZRatio); | |
planeLaserMiddle1Stop(); | |
planeLaserMiddle1ZDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration}); | |
var sampler = Animation.samplers.easeInOutQuad(planeLaserMiddleZEnd, planeLaserMiddleZStart); | |
planeLaserMiddle1.transform.z = Animation.animate(planeLaserMiddle1ZDriver, sampler); | |
planeLaserMiddle1ZDriver.start(); | |
laserExplosion1IntroMaterialDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration}); | |
var sampler = Animation.samplers.easeInOutQuad(0, laserExplosionIntroMaterialStart); | |
laserExplosion1IntroMaterial.opacity = Animation.animate(laserExplosion1IntroMaterialDriver, sampler); | |
laserExplosion1IntroMaterialDriver.start(); | |
} | |
face1IsTracking = true; | |
}else{ | |
planeLaserMiddle1.hidden = true; | |
planeLaserMiddle1.transform.x = 0; | |
planeLaserMiddle1.transform.y = 0; | |
laserContainer1Left.hidden = true; | |
laserContainer1Right.hidden = true; | |
face1IsTracking = false; | |
} | |
if(e.newValue == 1 && e.oldValue == 2){ | |
if(laserExplosion0IntroMaterialDriver != null){ | |
laserExplosion0IntroMaterialDriver.stop(); | |
} | |
if(laserExplosion1IntroMaterialDriver != null){ | |
laserExplosion1IntroMaterialDriver.stop(); | |
} | |
if(face0IsTracking){ | |
planeLaserMiddle0.hidden = false; | |
planeLaserMiddle0Stop(); | |
planeLaserMiddle0ZDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration}); | |
var sampler = Animation.samplers.easeInOutQuad(planeLaserMiddleZEnd, planeLaserMiddleZStart); | |
planeLaserMiddle0.transform.z = Animation.animate(planeLaserMiddle0ZDriver, sampler); | |
planeLaserMiddle0ZDriver.start(); | |
laserExplosion0IntroMaterialDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration }); | |
var sampler = Animation.samplers.easeInOutQuad(laserExplosionIntroMaterialStart / 3, 0); | |
laserExplosion0IntroMaterial.opacity = Animation.animate(laserExplosion0IntroMaterialDriver, sampler); | |
laserExplosion0IntroMaterialDriver.start(); | |
} | |
if(face1IsTracking){ | |
planeLaserMiddle1.hidden = false; | |
planeLaserMiddle1Stop(); | |
planeLaserMiddle1ZDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration}); | |
var sampler = Animation.samplers.easeInOutQuad(planeLaserMiddleZEnd, planeLaserMiddleZStart); | |
planeLaserMiddle1.transform.z = Animation.animate(planeLaserMiddle1ZDriver, sampler); | |
planeLaserMiddle1ZDriver.start(); | |
laserExplosion1IntroMaterialDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration }); | |
var sampler = Animation.samplers.easeInOutQuad(laserExplosionIntroMaterialStart / 3, 0); | |
laserExplosion1IntroMaterial.opacity = Animation.animate(laserExplosion1IntroMaterialDriver, sampler); | |
laserExplosion1IntroMaterialDriver.start(); | |
} | |
} | |
if(face0IsTracking && face1IsTracking){ | |
// instructions.hidden = true; | |
planeLaserMiddleTimeout = Time.setTimeoutWithSnapshot({ 'planeLaser0Left.transform.x': planeLaser0Left.transform.x, 'planeLaser0Left.transform.y': planeLaser0Left.transform.y, 'planeLaser0Left.transform.z': planeLaser0Left.transform.z, 'planeLaser1Right.transform.x': planeLaser1Right.transform.x, 'planeLaser1Right.transform.y': planeLaser1Right.transform.y, 'planeLaser1Right.transform.z': planeLaser1Right.transform.z }, function(delay, snapshots){ | |
planeLaserMiddle0Stop(); | |
planeLaserMiddle1Stop(); | |
planeLaserMiddle0.hidden = false; | |
planeLaserMiddle0ZDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration}); | |
var sampler = Animation.samplers.easeInOutQuad(planeLaserMiddleZStart, planeLaserMiddleZEnd); | |
planeLaserMiddle0.transform.z = Animation.animate(planeLaserMiddle0ZDriver, sampler); | |
planeLaserMiddle0ZDriver.start(); | |
planeLaserMiddle1.hidden = true; | |
planeLaserMiddle1ZDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration}); | |
var sampler = Animation.samplers.easeInOutQuad(planeLaserMiddleZStart, planeLaserMiddleZEnd); | |
planeLaserMiddle1.transform.z = Animation.animate(planeLaserMiddle1ZDriver, sampler); | |
planeLaserMiddle1ZDriver.start(); | |
laserExplosion0IntroMaterialDriver = Animation.timeDriver({durationMilliseconds: planeLaserMiddleDuration + 100}); | |
var sampler = Animation.samplers.easeInOutQuad(laserExplosionIntroMaterialStart, 0); | |
laserExplosion0IntroMaterial.opacity = Animation.animate(laserExplosion0IntroMaterialDriver, sampler); | |
laserExplosion0IntroMaterialDriver.start(); | |
}, planeLaserMiddleDuration + 10); | |
} | |
}); | |
function planeLaserMiddle0Stop(){ | |
if(planeLaserMiddle0XDriver != null){ | |
planeLaserMiddle0XDriver.stop(); | |
} | |
if(planeLaserMiddle0YDriver != null){ | |
planeLaserMiddle0YDriver.stop(); | |
} | |
if(planeLaserMiddle0ZDriver != null){ | |
planeLaserMiddle0ZDriver.stop(); | |
} | |
if(laserExplosion0IntroMaterialDriver != null){ | |
laserExplosion0IntroMaterialDriver.stop(); | |
} | |
} | |
function planeLaserMiddle1Stop(){ | |
if(planeLaserMiddle1XDriver != null){ | |
planeLaserMiddle1XDriver.stop(); | |
} | |
if(planeLaserMiddle1YDriver != null){ | |
planeLaserMiddle1YDriver.stop(); | |
} | |
if(planeLaserMiddle1ZDriver != null){ | |
planeLaserMiddle1ZDriver.stop(); | |
} | |
if(laserExplosion1IntroMaterialDriver != null){ | |
laserExplosion1IntroMaterialDriver.stop(); | |
} | |
} | |
var planeLaser0Left_target = planeLaserMiddle0; | |
var planeLaser0Right_target = planeLaserMiddle0; | |
var planeLaser1Left_target = planeLaserMiddle1; | |
var planeLaser1Right_target = planeLaserMiddle1; | |
////////////////////////////////////////////////////////////////////////// | |
//left0 lookAt | |
laserContainer0Left.transform.position = planeLaser0Left.transform.position; | |
var distance0Left = planeLaser0Left.transform.position.distance(planeLaser0Left_target.transform.position); | |
laserContainer0LeftLaser.transform.scaleX = distance0Left.mul(1); | |
laserContainer0LeftEmitterShortEnd.transform.x = distance0Left; | |
var planeLaser0Left_forwardVector = planeLaser0Left_target.transform.position.sub(planeLaser0Left.transform.position); | |
Patches.setVectorValue('planeLaser0LeftForwardVector', planeLaser0Left_forwardVector); | |
var planeLaser0LeftForwardVectorNormalized = Patches.getVectorValue('planeLaser0LeftForwardVectorNormalized'); | |
var planeLaser0Left_rotationAxis = planeLaser0LeftForwardVectorNormalized.cross(vectorForward); | |
var planeLaser0Left_dot = planeLaser0LeftForwardVectorNormalized.dot(vectorForward).add(1); | |
var planeLaser0Left_w0 = planeLaser0Left_dot.mul(-1); | |
var planeLaser0Left_x0 = planeLaser0Left_rotationAxis.x; | |
var planeLaser0Left_y0 = planeLaser0Left_rotationAxis.y; | |
var planeLaser0Left_z0 = planeLaser0Left_rotationAxis.z; | |
var planeLaser0LeftQuatL = R.sqrt((planeLaser0Left_x0.mul(planeLaser0Left_x0)).add(planeLaser0Left_y0.mul(planeLaser0Left_y0)).add(planeLaser0Left_z0.mul(planeLaser0Left_z0)).add(planeLaser0Left_w0.mul(planeLaser0Left_w0))); | |
var planeLaser0LeftQuatLL = R.val(1).div(planeLaser0LeftQuatL); | |
var planeLaser0Left_w = planeLaser0Left_w0.mul(planeLaser0LeftQuatLL); | |
var planeLaser0Left_x = planeLaser0Left_x0.mul(planeLaser0LeftQuatLL); | |
var planeLaser0Left_y = planeLaser0Left_y0.mul(planeLaser0LeftQuatLL); | |
var planeLaser0Left_z = planeLaser0Left_z0.mul(planeLaser0LeftQuatLL); | |
//quaternion to euler using zyx | |
var planeLaser0Left_r11 = R.val(2).mul((planeLaser0Left_x.mul(planeLaser0Left_y).add(planeLaser0Left_w.mul(planeLaser0Left_z)))); | |
var planeLaser0Left_r12 = (planeLaser0Left_w.mul(planeLaser0Left_w)).add(planeLaser0Left_x.mul(planeLaser0Left_x)).sub(planeLaser0Left_y.mul(planeLaser0Left_y)).sub(planeLaser0Left_z.mul(planeLaser0Left_z)); | |
var planeLaser0Left_r21 = R.val(-2).mul((planeLaser0Left_x.mul(planeLaser0Left_z)).sub(planeLaser0Left_w.mul(planeLaser0Left_y))); | |
var planeLaser0Left_r31 = R.val(2).mul((planeLaser0Left_y.mul(planeLaser0Left_z)).add(planeLaser0Left_w.mul(planeLaser0Left_x))); | |
var planeLaser0Left_r32 = (planeLaser0Left_w.mul(planeLaser0Left_w)).sub(planeLaser0Left_x.mul(planeLaser0Left_x)).sub(planeLaser0Left_y.mul(planeLaser0Left_y)).add(planeLaser0Left_z.mul(planeLaser0Left_z)); | |
var planeLaser0Left_heading = R.atan2(planeLaser0Left_r31, planeLaser0Left_r32); | |
laserContainer0Left.transform.rotationX = planeLaser0Left_heading; | |
Patches.setScalarValue('planeLaser0LeftAttitude', planeLaser0Left_r21); | |
var planeLaser0Left_asin_attitude = Patches.getScalarValue('planeLaser0LeftAsinAttitude'); | |
laserContainer0Left.transform.rotationY = planeLaser0Left_asin_attitude; | |
var planeLaser0Left_bank = R.atan2(planeLaser0Left_r11, planeLaser0Left_r12); | |
laserContainer0Left.transform.rotationZ = planeLaser0Left_bank; | |
////////////////////////////////////////////////////////////////////////// | |
//right0 lookAt | |
laserContainer0Right.transform.position = planeLaser0Right.transform.position; | |
var distance0Right = planeLaser0Right.transform.position.distance(planeLaser0Right_target.transform.position); | |
laserContainer0RightLaser.transform.scaleX = distance0Right.mul(1); | |
laserContainer0RightEmitterShortEnd.transform.x = distance0Right; | |
var planeLaser0Right_forwardVector = planeLaser0Right_target.transform.position.sub(planeLaser0Right.transform.position); | |
Patches.setVectorValue('planeLaser0RightForwardVector', planeLaser0Right_forwardVector); | |
var planeLaser0RightForwardVectorNormalized = Patches.getVectorValue('planeLaser0RightForwardVectorNormalized'); | |
var planeLaser0Right_rotationAxis = planeLaser0RightForwardVectorNormalized.cross(vectorForward); | |
var planeLaser0Right_dot = planeLaser0RightForwardVectorNormalized.dot(vectorForward).add(1); | |
var planeLaser0Right_w0 = planeLaser0Right_dot.mul(-1); | |
var planeLaser0Right_x0 = planeLaser0Right_rotationAxis.x; | |
var planeLaser0Right_y0 = planeLaser0Right_rotationAxis.y; | |
var planeLaser0Right_z0 = planeLaser0Right_rotationAxis.z; | |
var planeLaser0RightQuatL = R.sqrt((planeLaser0Right_x0.mul(planeLaser0Right_x0)).add(planeLaser0Right_y0.mul(planeLaser0Right_y0)).add(planeLaser0Right_z0.mul(planeLaser0Right_z0)).add(planeLaser0Right_w0.mul(planeLaser0Right_w0))); | |
var planeLaser0RightQuatLL = R.val(1).div(planeLaser0RightQuatL); | |
var planeLaser0Right_w = planeLaser0Right_w0.mul(planeLaser0RightQuatLL); | |
var planeLaser0Right_x = planeLaser0Right_x0.mul(planeLaser0RightQuatLL); | |
var planeLaser0Right_y = planeLaser0Right_y0.mul(planeLaser0RightQuatLL); | |
var planeLaser0Right_z = planeLaser0Right_z0.mul(planeLaser0RightQuatLL); | |
//quaternion to euler using zyx | |
var planeLaser0Right_r11 = R.val(2).mul((planeLaser0Right_x.mul(planeLaser0Right_y).add(planeLaser0Right_w.mul(planeLaser0Right_z)))); | |
var planeLaser0Right_r12 = (planeLaser0Right_w.mul(planeLaser0Right_w)).add(planeLaser0Right_x.mul(planeLaser0Right_x)).sub(planeLaser0Right_y.mul(planeLaser0Right_y)).sub(planeLaser0Right_z.mul(planeLaser0Right_z)); | |
var planeLaser0Right_r21 = R.val(-2).mul((planeLaser0Right_x.mul(planeLaser0Right_z)).sub(planeLaser0Right_w.mul(planeLaser0Right_y))); | |
var planeLaser0Right_r31 = R.val(2).mul((planeLaser0Right_y.mul(planeLaser0Right_z)).add(planeLaser0Right_w.mul(planeLaser0Right_x))); | |
var planeLaser0Right_r32 = (planeLaser0Right_w.mul(planeLaser0Right_w)).sub(planeLaser0Right_x.mul(planeLaser0Right_x)).sub(planeLaser0Right_y.mul(planeLaser0Right_y)).add(planeLaser0Right_z.mul(planeLaser0Right_z)); | |
var planeLaser0Right_heading = R.atan2(planeLaser0Right_r31, planeLaser0Right_r32); | |
laserContainer0Right.transform.rotationX = planeLaser0Right_heading; | |
Patches.setScalarValue('planeLaser0RightAttitude', planeLaser0Right_r21); | |
var planeLaser0Right_asin_attitude = Patches.getScalarValue('planeLaser0RightAsinAttitude'); | |
laserContainer0Right.transform.rotationY = planeLaser0Right_asin_attitude; | |
var planeLaser0Right_bank = R.atan2(planeLaser0Right_r11, planeLaser0Right_r12); | |
laserContainer0Right.transform.rotationZ = planeLaser0Right_bank; | |
////////////////////////////////////////////////////////////////////////// | |
//left1 lookAt | |
laserContainer1Left.transform.position = planeLaser1Left.transform.position; | |
var distance1Left = planeLaser1Left.transform.position.distance(planeLaser1Left_target.transform.position); | |
laserContainer1LeftLaser.transform.scaleX = distance1Left.mul(1); | |
laserContainer1LeftEmitterShortEnd.transform.x = distance1Left; | |
var planeLaser1Left_forwardVector = planeLaser1Left_target.transform.position.sub(planeLaser1Left.transform.position); | |
Patches.setVectorValue('planeLaser1LeftForwardVector', planeLaser1Left_forwardVector); | |
var planeLaser1LeftForwardVectorNormalized = Patches.getVectorValue('planeLaser1LeftForwardVectorNormalized'); | |
var planeLaser1Left_rotationAxis = planeLaser1LeftForwardVectorNormalized.cross(vectorForward); | |
var planeLaser1Left_dot = planeLaser1LeftForwardVectorNormalized.dot(vectorForward).add(1); | |
var planeLaser1Left_w0 = planeLaser1Left_dot.mul(-1); | |
var planeLaser1Left_x0 = planeLaser1Left_rotationAxis.x; | |
var planeLaser1Left_y0 = planeLaser1Left_rotationAxis.y; | |
var planeLaser1Left_z0 = planeLaser1Left_rotationAxis.z; | |
var planeLaser1LeftQuatL = R.sqrt((planeLaser1Left_x0.mul(planeLaser1Left_x0)).add(planeLaser1Left_y0.mul(planeLaser1Left_y0)).add(planeLaser1Left_z0.mul(planeLaser1Left_z0)).add(planeLaser1Left_w0.mul(planeLaser1Left_w0))); | |
var planeLaser1LeftQuatLL = R.val(1).div(planeLaser1LeftQuatL); | |
var planeLaser1Left_w = planeLaser1Left_w0.mul(planeLaser1LeftQuatLL); | |
var planeLaser1Left_x = planeLaser1Left_x0.mul(planeLaser1LeftQuatLL); | |
var planeLaser1Left_y = planeLaser1Left_y0.mul(planeLaser1LeftQuatLL); | |
var planeLaser1Left_z = planeLaser1Left_z0.mul(planeLaser1LeftQuatLL); | |
//quaternion to euler using zyx | |
var planeLaser1Left_r11 = R.val(2).mul((planeLaser1Left_x.mul(planeLaser1Left_y).add(planeLaser1Left_w.mul(planeLaser1Left_z)))); | |
var planeLaser1Left_r12 = (planeLaser1Left_w.mul(planeLaser1Left_w)).add(planeLaser1Left_x.mul(planeLaser1Left_x)).sub(planeLaser1Left_y.mul(planeLaser1Left_y)).sub(planeLaser1Left_z.mul(planeLaser1Left_z)); | |
var planeLaser1Left_r21 = R.val(-2).mul((planeLaser1Left_x.mul(planeLaser1Left_z)).sub(planeLaser1Left_w.mul(planeLaser1Left_y))); | |
var planeLaser1Left_r31 = R.val(2).mul((planeLaser1Left_y.mul(planeLaser1Left_z)).add(planeLaser1Left_w.mul(planeLaser1Left_x))); | |
var planeLaser1Left_r32 = (planeLaser1Left_w.mul(planeLaser1Left_w)).sub(planeLaser1Left_x.mul(planeLaser1Left_x)).sub(planeLaser1Left_y.mul(planeLaser1Left_y)).add(planeLaser1Left_z.mul(planeLaser1Left_z)); | |
var planeLaser1Left_heading = R.atan2(planeLaser1Left_r31, planeLaser1Left_r32); | |
laserContainer1Left.transform.rotationX = planeLaser1Left_heading; | |
Patches.setScalarValue('planeLaser1LeftAttitude', planeLaser1Left_r21); | |
var planeLaser1Left_asin_attitude = Patches.getScalarValue('planeLaser1LeftAsinAttitude'); | |
laserContainer1Left.transform.rotationY = planeLaser1Left_asin_attitude; | |
var planeLaser1Left_bank = R.atan2(planeLaser1Left_r11, planeLaser1Left_r12); | |
laserContainer1Left.transform.rotationZ = planeLaser1Left_bank; | |
////////////////////////////////////////////////////////////////////////// | |
//right1 | |
laserContainer1Right.transform.position = planeLaser1Right.transform.position; | |
var distance1Right = planeLaser1Right.transform.position.distance(planeLaser1Right_target.transform.position); | |
laserContainer1RightLaser.transform.scaleX = distance1Right.mul(1); | |
laserContainer1RightEmitterShortEnd.transform.x = distance1Right; | |
var planeLaser1Right_forwardVector = planeLaser1Right_target.transform.position.sub(planeLaser1Right.transform.position); | |
Patches.setVectorValue('planeLaser1RightForwardVector', planeLaser1Right_forwardVector); | |
var planeLaser1RightForwardVectorNormalized = Patches.getVectorValue('planeLaser1RightForwardVectorNormalized'); | |
var planeLaser1Right_rotationAxis = planeLaser1RightForwardVectorNormalized.cross(vectorForward); | |
var planeLaser1Right_dot = planeLaser1RightForwardVectorNormalized.dot(vectorForward).add(1); | |
var planeLaser1Right_w0 = planeLaser1Right_dot.mul(-1); | |
var planeLaser1Right_x0 = planeLaser1Right_rotationAxis.x; | |
var planeLaser1Right_y0 = planeLaser1Right_rotationAxis.y; | |
var planeLaser1Right_z0 = planeLaser1Right_rotationAxis.z; | |
var planeLaser1RightQuatL = R.sqrt((planeLaser1Right_x0.mul(planeLaser1Right_x0)).add(planeLaser1Right_y0.mul(planeLaser1Right_y0)).add(planeLaser1Right_z0.mul(planeLaser1Right_z0)).add(planeLaser1Right_w0.mul(planeLaser1Right_w0))); | |
var planeLaser1RightQuatLL = R.val(1).div(planeLaser1RightQuatL); | |
var planeLaser1Right_w = planeLaser1Right_w0.mul(planeLaser1RightQuatLL); | |
var planeLaser1Right_x = planeLaser1Right_x0.mul(planeLaser1RightQuatLL); | |
var planeLaser1Right_y = planeLaser1Right_y0.mul(planeLaser1RightQuatLL); | |
var planeLaser1Right_z = planeLaser1Right_z0.mul(planeLaser1RightQuatLL); | |
//quaternion to euler using zyx | |
var planeLaser1Right_r11 = R.val(2).mul((planeLaser1Right_x.mul(planeLaser1Right_y).add(planeLaser1Right_w.mul(planeLaser1Right_z)))); | |
var planeLaser1Right_r12 = (planeLaser1Right_w.mul(planeLaser1Right_w)).add(planeLaser1Right_x.mul(planeLaser1Right_x)).sub(planeLaser1Right_y.mul(planeLaser1Right_y)).sub(planeLaser1Right_z.mul(planeLaser1Right_z)); | |
var planeLaser1Right_r21 = R.val(-2).mul((planeLaser1Right_x.mul(planeLaser1Right_z)).sub(planeLaser1Right_w.mul(planeLaser1Right_y))); | |
var planeLaser1Right_r31 = R.val(2).mul((planeLaser1Right_y.mul(planeLaser1Right_z)).add(planeLaser1Right_w.mul(planeLaser1Right_x))); | |
var planeLaser1Right_r32 = (planeLaser1Right_w.mul(planeLaser1Right_w)).sub(planeLaser1Right_x.mul(planeLaser1Right_x)).sub(planeLaser1Right_y.mul(planeLaser1Right_y)).add(planeLaser1Right_z.mul(planeLaser1Right_z)); | |
var planeLaser1Right_heading = R.atan2(planeLaser1Right_r31, planeLaser1Right_r32); | |
laserContainer1Right.transform.rotationX = planeLaser1Right_heading; | |
Patches.setScalarValue('planeLaser1RightAttitude', planeLaser1Right_r21); | |
var planeLaser1Right_asin_attitude = Patches.getScalarValue('planeLaser1RightAsinAttitude'); | |
laserContainer1Right.transform.rotationY = planeLaser1Right_asin_attitude; | |
var planeLaser1Right_bank = R.atan2(planeLaser1Right_r11, planeLaser1Right_r12); | |
laserContainer1Right.transform.rotationZ = planeLaser1Right_bank; | |
////////////////////////////////////////////////////////////////////////// | |
//laser rotations | |
var driver = Animation.timeDriver({durationMilliseconds: laserContainerLaserRotateDuration, loopCount: Infinity}); | |
var sampler = Animation.samplers.linear(0, rotation360); | |
laserContainer0LeftLaser.transform.rotationX = Animation.animate(driver, sampler); | |
driver.start(); | |
var driver = Animation.timeDriver({durationMilliseconds: laserContainerLaserRotateDuration, loopCount: Infinity}); | |
var sampler = Animation.samplers.linear(0, rotation360); | |
laserContainer0RightLaser.transform.rotationX = Animation.animate(driver, sampler); | |
driver.start(); | |
var driver = Animation.timeDriver({durationMilliseconds: laserContainerLaserRotateDuration, loopCount: Infinity}); | |
var sampler = Animation.samplers.linear(0, rotation360); | |
laserContainer1LeftLaser.transform.rotationX = Animation.animate(driver, sampler); | |
driver.start(); | |
var driver = Animation.timeDriver({durationMilliseconds: laserContainerLaserRotateDuration, loopCount: Infinity}); | |
var sampler = Animation.samplers.linear(0, rotation360); | |
laserContainer1RightLaser.transform.rotationX = Animation.animate(driver, sampler); | |
driver.start(); | |
////////////////////////////////////////////////////////////////////////// | |
// instructions | |
var faceOneFound = false; | |
var faceTwoFound = false; | |
Patches.setBooleanValue('instructionEnabled', true); | |
Patches.setStringValue('instructionToken', 'find_face'); | |
var faceFinderCountSub = FT.count.monitor({fireOnInitialValue: true}).subscribe(function(e) { | |
if(e.newValue == 1){ | |
if(!faceTwoFound){ | |
Patches.setStringValue('instructionToken', 'try_with_friends'); | |
} | |
faceOneFound = true; | |
}else if(e.newValue == 2){ | |
if(!faceTwoFound){ | |
Patches.setBooleanValue('instructionEnabled', false); | |
} | |
faceOneFound = true; | |
faceTwoFound = true; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment