Sign in to follow this  

Converting Screen-Space Coordinates to Real-World Coordinates

Recommended Posts


I am working on an application for Android - what we need is for the output of the Accelerometer to be transformed by the orientation of the device.

There are two sensors: Accelerometer and Orientation.

Accelerometer returns (in screen-space)... acceleration for X, Y, and Z.
Orientation returns angles for X, Y, and Z.

Screen-Space to Android seems to be equivalent to Object-Space. If I push the phone 'forward' from the top of it, it will show acceleration with Y = acceleration.

My thought: I need to convert the output from the orientation into a vector, which will give me the Y vector (forward) (ignoring z):

vec.x = Math.cos(x) * Math.cos(y);
vec.y = Math.sin(x) * Math.cos(y);
vec.z = Math.sin(y);

From there, am I correct in that I would need to generate a rotation matrix (equivalent to a modelview matrix), from which I would rotate the acceleration vector given by the acceleration sensor?

Basically, I want to cancel out the affect of rotation on the device - gravity should (though wouldn't due to errors) always show as Z = -G, but as is the acceleration is affected by rotation (as it is in screenspace/object space).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this