after12am / eisenscript

A programming language designed for generating awesome structures.
https://after12am.github.io/eisenscript-docs/
MIT License
46 stars 5 forks source link

Scaling affects rotation ? #53

Closed kronpano closed 4 years ago

kronpano commented 7 years ago

Using the following script:

tower rule tower md 44 { {s 2 5 3 }box {y 5 rx 10 rz 10 s 0.95 } tower } Produces the following image: browsereven

Now the only change is to change the scaling in the recursive function call:

tower rule tower md 44 { {s 2 5 3 }box {y 5 rx 10 rz 10 s 0.95 1 1 } tower } which then produces the following image: browseruneven

There are quite a few wobbles when it comes to the rotation and there seem to be points where the box is actually growing - not shrinking - even though the rule is same or smaller.

It leads to an irregular image when all it should do is shrink in the direction of one axis.

This behaviour will be different from the original Structure Synth because there the shearing happened when rotation and scaling was used in the same rule .

kronpano commented 7 years ago

OK, it really is the case - scaling affects the rotation BUT only the non-uniform scaling. So rule containing "{ry 10 s 1.5}box" that is OK but if you have rotation and non uniform scaling like "{ ry 10 s 1.5 1 1} box" that actually affects the rotation.

As example I use the simple script of

9 * {ry 22.5 y -1 s 1.4} 1 * {ry -22.5}box

This gives you a nice tower of stacked boxes. In the image you can also see the angle value - I put a debug statement into the code when the element is actually added to the scene which shows the x, y and z angles:

var rot2 = new THREE.Euler().setFromRotationMatrix (object.matrix,"YZX") console.log(rot2._x * 180 / Math.PI,rot2._y * 180 / Math.PI,rot2._z * 180 / Math.PI ) switch (object.type) { case 'background': clearColor(object.color); break; case 'primitive': lesson10.MyAddPrimitive(object); break; } These angles are extracted from the Matrix4 - the quaternions - which I still don't fully understand.

OK - first uniform scaling: script: 9 * {ry 22.5 y -1 s 1.4} 1 * {ry -22.5}box (angle chosen to make it easy to see image in the degub you can see angles are close enough to 0,45,90,135 and 180 and now non uniform scaling:

script: 9 * {ry 22.5 y -1 s 1.4 1 1 } 1 * {ry -22.5}box image

it also gets worse if one scaling goes up and one down: script: 9 * {ry 22.5 y -1 s 1.4 1 0.8 } 1 * {ry -22.5}box image After nine rotations of 22.5 it barely reaches 90 degrees not the 180 you would expect.

Looking at the code it is all connected to the Matrix4 (and matrix,js) in interpreter.js where the values are stored and renderer.js addPrimitive where the object matrix is applied.

I am not sure about matrix.js and the functions in there. Need to investigate further but I am not familiar with the Matrix4 side of things.

kronpano commented 7 years ago

Looking at three.js it might be connected to https://github.com/mrdoob/three.js/issues/3185 ??? But - as said before - I don;t fully understand the Matrix4.

after12am commented 7 years ago

Sorry. I came home now. I have to work much more hard for schedule delay in this week. Maybe.. next few weeks.

kronpano commented 7 years ago

No worries - we all know that sadly work - real paid work is more important. Will probably play a bit more and possibly raise issues but that does NOT mean I expect anything.

Everybody does things in their time - thanks for such a great start !!!

after12am commented 4 years ago

It looks fixed now.

tower rule tower md 44 { {s 2 5 3 }box {y 5 rx 10 rz 10 s 0.95 } tower }

screencapture-192-168-11-5-9000-examples-1586744670715

tower rule tower md 44 { {s 2 5 3 }box {y 5 rx 10 rz 10 s 0.95 1 1 } tower }

screencapture-192-168-11-5-9000-examples-1586744446686

9 {ry 22.5 y -1 s 1.4} 1 {ry -22.5}box

screencapture-192-168-11-5-9000-examples-1586744818935

screencapture-192-168-11-5-9000-examples-1586744831516

after12am commented 4 years ago

@kronpano Is it ok to close this issue?

after12am commented 4 years ago

If the issue hasn't been fixed, please reopen issue.