From 322afc39668ecd3d1a45dfc9e575187828759b77 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 22 Nov 2022 10:37:14 +0200 Subject: [OKG/HWK2] Added rotation capabilities to animationData --- .../Homework 2/mannequin.html | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html index 3099725..8cfeb01 100644 --- a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html +++ b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html @@ -201,6 +201,8 @@ B : fixPostureY(instr[3]), cpos : instr[1].position.clone(), npos : (instr.length === 4 || !instr[4]) ? null : vecSum(instr[1].position, instr[4]), + crot : instr[1].rotation.clone(), + nrot : (instr.length < 6 || !instr[5]) ? null : vecMultScal(instr[5], Math.PI / 2), }); } } @@ -215,6 +217,8 @@ mo.mannequin.posture = Mannequin.blend(mo.A, mo.B, blendPer); if (mo.npos) mo.mannequin.position.set(...vecBlend(mo.cpos, mo.npos, blendPer)); + if (mo.nrot) + mo.mannequin.rotation.set(...vecBlend(mo.crot, mo.nrot, blendPer)); } else { if (mo.campos !== null) { @@ -270,6 +274,14 @@ return [vec.x + arr[0], vec.y + arr[1], vec.z + arr[2]]; } + function vecMultScal(vec, scal) { + return { + x: vec.x * scal, + y: vec.y * scal, + z: vec.z * scal, + }; + } + function vecSum(a, b) { return { x: a.x + b.x, @@ -312,6 +324,14 @@ return null; } + function arrToRotVec(a) { + return { + x: a[0] * Math.PI / 2, + y: a[1] * Math.PI / 2, + z: a[2] * Math.PI / 2, + }; + } + /* * За функции, генериращи обекти */ @@ -661,14 +681,14 @@ ** Анимационни действия **/ - const DEFAULT_POSTURE = {"version":6,"data":[3.8,[0,-90,0],[0,0,-2],[0,0,5],[6,0,0],[0],[-6,-6,-0.6],[-6,0,0],[0],[6,6,-0.6],[7,-0.6,-5],[15],[-15,0,0],[10,10],[-7,0.6,-5],[15],[15,0,0],[10,10]]}; - var animationData = { 0: [ [ 5, jotaro, null, {"version":6,"data":[3.8,[0,-90,0],[-1.3,0,-2],[0,0,5],[6,0,0],[0],[-6,-6,-0.6],[-6,0,0],[0],[6,6,-0.6],[7,-0.6,-5],[15],[-15,0,0],[10,10],[-86.8,50.3,65.1],[15],[15,0,0],[10,10]]}, + {x:50, y:0, z:0}, + {x:2, y:0, z:0}, ], [ 3, [50, 0, 0], [0, -10, 0], false -- cgit v1.3.1-23-gd82d