From 11b566156c77121cd42428617e92d084f517de7f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 28 Nov 2022 17:09:52 +0200 Subject: [OKG/HWK2] Camera instruction can now have null values --- .../Homework 2/mannequin.html | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html index ef6327a..da7f70c 100644 --- a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html +++ b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html @@ -179,15 +179,15 @@ function fillBacklog() { for (var time in animationData) { for (var instruction of animationData[time]) { - if (instruction[1].constructor === Array) { + if (typeof instruction[3] == "boolean") { executeBacklog.push({ start : Number(time), end : Number(time) + instruction[0], iscamera : true, - camposold : vecToArr(camera.position), + camposold : null, campos : (instruction[3] || !instruction[1]) ? instruction[1] : arrSum(vecToArr(camera.position), instruction[1]), - camwatold : camLookAt.clone(), + camwatold : null, camwatch : arrToVec(((instruction[3] || !instruction[2]) ? instruction[2] : arrSum(vecToArr(camLookAt), instruction[2]))), isabsol : instruction[3], }); @@ -234,10 +234,12 @@ mo.mannequin.rotation.set(...vecBlend(mo.crot, mo.nrot, blendPer)); } else { - if (mo.campos !== null) { + if (!mo.camposold) mo.camposold = vecToArr(camera.position); + if (!mo.camwatold) mo.camwatold = camLookAt.clone(); + if (mo.campos) { camera.position.set(...arrBlend(mo.camposold, mo.campos, blendPer)); } - if (mo.camwatch !== null) { + if (mo.camwatch) { camLookAt = new THREE.Vector3(...vecBlend(mo.camwatold, mo.camwatch, blendPer)); camera.lookAt(camLookAt); } @@ -319,6 +321,7 @@ } function arrToVec(a) { + if (!a) return a; return { x: a[0], y: a[1], -- cgit v1.3.1-26-gb76a