Re: Proposal to add unit quaternion representation to the Device Orientation event.

On Mon, Sep 1, 2014 at 12:29 PM, Mounir Lamouri <mounir@lamouri.fr> wrote:
> On Sun, 31 Aug 2014, at 16:13, Rich Tibbett wrote:
>> It is just that nobody really does this right now. This is simply too
>> complex for common use cases such as applying simple CSS-based
>> transforms to on-screen objects.
>
> Screen Orientation API isn't really widely available. Only Webkit
> browsers exposed a buggy window.orientation (angle), IE and Firefox
> expose a type (but no angle). The current Chrome Beta exposes a usable
> screen.orientation.angle.
>
>> It's just not feasible to expect *every web developer* to do that *all
>> the time*. Whenever they don't do that the device orientation
>> interaction will be broken.
>
> What bothers me with this proposal is that it is assuming that
> developers who wouldn't do a stack overflow search to know how to get
> the correct matrix/quaternion would definitely think about using
> .screenAlpha instead of .alpha from the DeviceOrientationEvent object.

I'm not sure if there is anything inherently wrong with this. If a web
developer wants to use CSS 2D transforms then this would make it work
well out-of-the-box without having to do anything complicated in
JavaScript.

The fixed device frame quaternion approach would be:
1. Obtain the device quaternion via the Device Orientation event.
2. Obtain the screen orientation angle via the Screen Orientation event.
3. Apply screen orientation to device orientation.
4. Convert the screen-adjusted quaternion back to (now
screen-adjusted) Euler angles.
5. Apply the derived screen-adjusted Euler angles directly to your CSS
transform(s).

The screen-adjusted angles approach would be:

1. Obtain the screen-adjusted Euler angles via the Device Orientation event.
2. Apply the provided screen-adjusted Euler angles directly to your
CSS transform(s).

Passing the screen-adjusted values in to the functions at
https://w3c.github.io/deviceorientation/spec-source-orientation.html#worked-example-2
will give you a screen-adjusted quaternion or rotation matrix in the
same way as just passing in the standard values will give you a fixed
device frame quaternion or rotation matrix. This approach solves the
naive implementation use case (directly wiring device orientation to
CSS transforms) as well as giving a good foundation for working in
other rotational representation systems (e.g. quaternions or rotation
matrices).

There may be considerable implementation considerations for this
approach but that is also why we are here to figure them out and
document them :)

>
> -- Mounir

Received on Monday, 1 September 2014 11:28:13 UTC