android - How to convert Game Rotation Vector sensor result to axis angles -
refer code below, got 4 numbers game_rotation_vector sensor event , want achieve axis angle rotation of phone.
eg. if rotate phone screen counter clock wise 90 degress, want actual value 90deg sensor data.
can provide code convert 4 game rotation vector values 3 axis angle values?
the values placed unit quaternion like so:
sensors_event_t.data[0] = rot_axis.x*sin(theta/2); sensors_event_t.data[1] = rot_axis.y*sin(theta/2); sensors_event_t.data[2] = rot_axis.z*sin(theta/2); sensors_event_t.data[3] = cos(theta/2)
so reverse of just:
double theta = math.acos(vals[3])*2; double sinv = math.sin(theta/2); double xa = vals[0]/sinv; double ya = vals[1]/sinv; double za = vals[2]/sinv;
but xa, xy, , xz aren't angles, they're coordinates of axis described in documentation. i'm not sure want these, better off trying achieve unstated goal unit quaternion directly.
the reason unit quaternion used avoid gimble lock, cannot describe every possible rotation in terms of 3 angles, roll/pitch/yaw, example @ pitch , yaw angle can lose ability roll.
so 1 way make use of convert rotation matrix:
if (event.sensor.gettype() == sensor.type_rotation_vector) { // convert rotation-vector 4x4 matrix. matrix // interpreted open gl inverse of // rotation-vector, want. sensormanager.getrotationmatrixfromvector( mrotationmatrix , event.values); }
Comments
Post a Comment