Famous / engine

MIT License
1.75k stars 250 forks source link

[bug?] Rotation values not set to the ones I specify. #477

Closed trusktr closed 8 years ago

trusktr commented 8 years ago

I thought I could rotate something simply by ding something like this:

        viewNode.setRotation(0,0,0)
        Engine.getClock().setInterval(function() {
            let current = viewNode.getRotation()
            let w = current[3]
            let currentY = current[1]
            let newY = currentY + Math.PI/4
            console.log('rotation:', currentY, newY, w)
            viewNode.setRotation(0, newY, 0)
        }, 1000)

But the expected doesn't happen. Instead of the Y rotation incrementing by Math.PI/4, the value of the increment turns out to be smaller and smaller each tick of the interval.

Here is the repeated output of the console.log('rotation:', currentY, newY, w):

screenshot from 2015-08-22 19-23-58

On the first output, you see

rotation: 0.6599896550178528 1.445387818415301 0.7512747049331665

. The expectation is that on the second output, the first of the three numbers will be the second number of the first output, so the expected second output would be something like

rotation: 1.445387818415301 2.2307859818127493 0.7512747049331665

As you can see, that's not what's happening, and the fourth number of the rotation (w) is also changing on it's own. The actual second output is this:

rotation: 0.6614075899124146 1.4468057533098628 0.7500267028808594

The first number of this output is only slightly bigger than the first number of the previous output. After a while, the delts from output to output becomes smaller and smaller, which is why at the last output in the screenshot we see a counter indicating how many of the same output has been logged.

Any ideas what's going on here? I'm not setting the 4th arg when I call Node#setRotation, so I'm just expecting to manipulate X, Y, and Z rotation. Is there something I'm not getting about rotation in Mixed Mode? Or might this be a bug?

alexanderGugel commented 8 years ago

This is expected. Rotations are always being stored as quaternions. Therefore getRotation returns the rotation as a quaternion.

Calling setRotation afterwards with euler angles results into the passed in rotation to be converted to a quaternion and stored as such.

In order to achieve the expected behavior you would have to store the set rotation separately. Converting the quaternion back to euler angles after getRotation won't work due to the nature of quaternions.

trusktr commented 8 years ago

@alexanderGugel Gotcha. So define the unit vector, then right hand rule for positive rotation?