Comments (3)
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.
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.
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
andgravity + linear
, both negated so that they point downwards for convenience and a more intuitive view. - The yellow line goes through the
gravity
andgyroscope
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)
- Pasting causes editor to scroll up to the top HOT 1
- Features request: Notification detector HOT 6
- Request: Sub-second accuracy date/daytime uniforms.
- Request: Add extra preset textures
- Request: Support for read+write variable pairs HOT 2
- Feature Request: Lexer-/Parser-Based Syntax highlighting HOT 3
- [Suggestion]: refactor `ShaderRenderer` HOT 2
- QoL: Hide TAB button when code is hidden HOT 1
- QoL: Search bar in Add uniform/texture HOT 2
- Long errors will get trimmed by Android HOT 11
- Different wallpaper shaders for home screen and lock screen HOT 3
- Sensor didn't work HOT 3
- Variable for dark/night mode HOT 2
- Idea: Use the shaders as custom screensavers
- L0002: Undeclared variable 'iTime' HOT 1
- Touch screen like mouse in computer? HOT 1
- Limit FPS HOT 2
- No matching overload function HOT 2
- Live wallpaper not work in some device HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shadereditor.