diff options
| Commit | 59184db96d33777c4acd07f99d720a3133d4490e (patch) | |
|---|---|---|
| Author | 2022-11-22 10:53:39 +0200 | |
| Committer | 2022-11-22 10:53:39 +0200 | |
| Files | 5a55ad9d753c7767143fbb56811c419bfb0bade0 | |
| uni-projects-59184db96d33777c4acd07f99d720a3133d4490e.tar uni-projects-59184db96d33777c4acd07f99d720a3133d4490e.tar.gz uni-projects-59184db96d33777c4acd07f99d720a3133d4490e.zip | ||
| Parent | 322afc39668ecd3d1a45dfc9e575187828759b77 (diff) | |
[OKG/HWK2] Improved property approximation functionality
1 files changed, 23 insertions, 10 deletions
| -rw-r--r-- | Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html | 33 |
diff --git a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html index 8cfeb01..c903818 100644 --- a/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html +++ b/Year 2/Computer Graphics Fundamentals/Homework 2/mannequin.html @@ -174,9 +174,9 @@ {
t = Math.floor(t) / 100;
- var prop = approxProp(animationData, t);
- if (prop)
- for (var instr of prop) {
+ var propInd = approxProp(animationData, t);
+ if (propInd) {
+ for (var instr of animationData[propInd]) {
if (instr[1].constructor === Array) {
executeHooks.push({
start : t,
@@ -186,7 +186,7 @@ camposold : vecToArr(camera.position),
campos : (instr[3] || !instr[1]) ? instr[1] : arrSum(vecToArr(camera.position), instr[1]),
camwatold : camLookAt.clone(),
- camwatch : new THREE.Vector3(...((instr[3] || !instr[2]) ? instr[2] : arrSum(vecToArr(camLookAt), instr[2]))),
+ camwatch : arrToVec(((instr[3] || !instr[2]) ? instr[2] : arrSum(vecToArr(camLookAt), instr[2]))),
isabsol : instr[3],
});
}
@@ -200,12 +200,14 @@ A : (instr[2]) ? instr[2] : fixPostureY(instr[1].posture),
B : fixPostureY(instr[3]),
cpos : instr[1].position.clone(),
- npos : (instr.length === 4 || !instr[4]) ? null : vecSum(instr[1].position, instr[4]),
+ npos : (instr.length < 5 || !instr[4]) ? null : vecSum(instr[1].position, arrToVec(instr[4])),
crot : instr[1].rotation.clone(),
- nrot : (instr.length < 6 || !instr[5]) ? null : vecMultScal(instr[5], Math.PI / 2),
+ nrot : (instr.length < 6 || !instr[5]) ? null : vecMultScal(arrToVec(instr[5]), Math.PI / 2),
});
}
}
+ delete animationData[propInd];
+ }
const executeLength = executeHooks.length;
for (var i = 0; i < executeLength; i++) {
@@ -310,6 +312,14 @@ return [a.x, a.y, a.z];
}
+ function arrToVec(a) {
+ return {
+ x: a[0],
+ y: a[1],
+ z: a[2],
+ };
+ }
+
function fixPostureY(p) {
p.data[0] = 0;
return p;
@@ -317,10 +327,13 @@ function approxProp(object, property) {
if (object.hasOwnProperty(property))
- return object[property];
+ return property;
var toCheck = property.toFixed(1);
if (object.hasOwnProperty(toCheck))
- return object[toCheck];
+ return toCheck;
+ toCheck = property.toFixed(0);
+ if (object.hasOwnProperty(toCheck))
+ return toCheck;
return null;
}
@@ -687,8 +700,8 @@ 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},
+ [50, 0, 0],
+ [2, 0, 0],
],
[
3, [50, 0, 0], [0, -10, 0], false
|
