📱 Erkannter Endgerättyp 🔇 Sound ist aus. ⛱️ Tag und Nacht. Verbraucht keinen oder einen 🍪.
guest
Login 🍪 0 Anzahl Ihrer gespeicherten Kekse, führt zur Keksdose

Chromes Device Orientation API with Quaternions

Portrait
Device laying on table, top is facing earth north 

q0 is pitch is yz  e₂₃
q1 is yaw   is zx  e₃₁
q2 is roll  is xy  e₁₂

z is backwards so you need to flip q[0] and q[1]

When using s e₂₃ e₃₁ e₁₂ and LH z forward

orientationRotor4[0] = q[3];
orientationRotor4[1] = -q[0];
orientationRotor4[2] = -q[1];
orientationRotor4[3] = q[2];

Screen Orientation compensate

let screenOrientationCompensateRotor = ROTOR4_IDENTITY.slice();

if (screen.orientation.type == 'portrait-primary') {

    screenOrientationCompensateRotor = ROTOR4_IDENTITY.slice();

}

// thats +90° so ccw in xy roll, so to compensate -90°
if (screen.orientation.type == 'landscape-primary') {

    // i totally guessed this
    screenOrientationCompensateRotor = rotor4.fromAngleAndPlane(-Math.PI / 2, BIVECTOR4_XY)

}

// thats +180° so ccw in xy roll, so to compensate -180°
if (screen.orientation.type == 'portrait-secondary') {

    // i totally guessed this
    screenOrientationCompensateRotor = rotor4.fromAngleAndPlane(-Math.PI, BIVECTOR4_XY)

}

// thats +270° so ccw in xy roll, so to compensate +90°
if (screen.orientation.type == 'landscape-secondary') {

    // i totally guessed this
    screenOrientationCompensateRotor = rotor4.fromAngleAndPlane(Math.PI / 2, BIVECTOR4_XY)

}

Compensate is LOCAL

You need to multiply this on the LEFT with your camera or objects orientation. FIRST compensate, THEN orient. Because you want to compensate the SOURCE of orientation.

First account whereever for the rotated screen/device, THEN read it in regards to earth

Now if you would rotate on the right you would first orient the device to earth but then no matter this value compensate a global xy roll. Thats only correct in 1 position, all other will be wrong.

(i guessed this though)

orientationRotor4 = rotor4.multiply(screenOrientationCompensateRotor, orientationRotor4);

Device looking forward compensate

This is a bit easier because you compensate after the screen(!) for a device not laying down on earth but looking ahead. So thats a simple yz 90°

let lookaheadRotor = rotor4.fromAngleAndPlane(Math.PI / 2, BIVECTOR4_YZ);
orientationRotor4 = rotor4.multiply(orientationRotor4, lookaheadRotor);

BUT. It needs to be right multiplied now ... why? Well. I dono lol

Current PTF

Hintergrund ändern. Verbraucht keinen oder einen 🍪.

Verknüpften Viewport öffnen

🎮 Steuerung
Dokumentation 🕹️
Sie sind leider kein Entwickler :(

Content Nodes Amount

Diligence / PTF Amount

FPS

Vertex-Count