Code Monkey home page Code Monkey logo

Comments (3)

markusfisch avatar markusfisch commented on June 12, 2024

Well, the code in GyroscopeListener is based on the documentation, so I think it's correct. But I may be wrong, of course!

Unfortunately, I haven't got a shader at hand to test whether this correct or not at the moment. But since this open source, you may of course play around with it and see if you can make it work for your sample 😉

Something tells me either the rotation angles should all be negated, or the vector should rather be multiplied by the inverse of deltaRotationMatrix there in order to make sense.

I think inversing isn't required because:

However, since the matrix is a rotation matrix, its transpose is also its inverse, conveniently, it is often the inverse of the rotation that is needed for rendering; it can therefore be used with OpenGL ES directly.

from shadereditor.

planiitis avatar planiitis commented on June 12, 2024

Well, the code in GyroscopeListener is based on the documentation, so I think it's correct. But I may be wrong, of course!

Looking at the comment in the example code:
// rotationCurrent = rotationCurrent * deltaRotationMatrix;
I believe rotationCurrent here is meant to be a matrix, not a vector as in the case of GyroscopeListener.rotation. A rotation matrix can be inverted as needed (and will be by default when provided to OpenGL), a rotated vector cannot be inverted in the same way to get the "inverse-rotated" vector.

I think inversing isn't required because:

However, since the matrix is a rotation matrix, its transpose is also its inverse, conveniently, it is often the inverse of the rotation that is needed for rendering; it can therefore be used with OpenGL ES directly.

Here's how I understand it: If the gyroscope uniform were a matrix, you'd be right. But it's a vector, so the transposition does not happen.

from shadereditor.

planiitis avatar planiitis commented on June 12, 2024

I made a shader to explore the different orientation vectors: https://gist.github.com/planiitis/d940919503d442f0c7287ae10f74b466

Set Sensor Delay to Game or UI for best results.

The shader provides a view of the gyroscope, gravity, magnetic and linear vectors, as well as rotationMatrix. Assuming the device is in its non-rotated screen configuration, you can turn the device around to get a "camera view" of the various vectors.

  • The four small circles around the horizon (denoted by a purple line) show the cardinal directions given by rotationMatrix.
  • A green circle shows the direction of magnetic, pointing to magnetic north.
  • The red and purple circles show gravity and gravity + linear, both negated so that they point downwards for convenience and a more intuitive view.
  • The yellow line goes through the gravity and gyroscope circles.
  • The yellow circle represents the gyroscope vector.

Current code negates the x and y coordinates of the gyroscope vector. That makes the gyroscope circle move correctly with respect to the others when rotating the device about its x or y coordinate. However, rotation around the device's z coordinate is still backwards: Try laying the device on a level, non-magnetic surface with its screen facing up, then rotate the device clockwise. If the magnetic circle is in view, you should see it stay in place relative to yourself, or moving counter-clockwise relative to the device screen, as expected. However, the yellow line that points to the gyroscope vector will rotate clockwise relative to the device screen, rotating at double speed relative to yourself.

from shadereditor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.