Hi everyone,
So, the problem I'm trying to solve is to use an iPhone/iPod acceleration to manipulate directly a 3D object. For that i've been searching lot's of stuff (Euler angles, Quaternions, etc). I'm using OpenSG, where I have a 3D environment and want to manipulate a certain object (just rotating in all possible iPhone/iPod degrees of freedom using only accelerometer). So, I tried to figure it out a solution for this problem but it still doesn't have the expected result and get some weird rotations in some angles. Can someone tell me what I'm doing wrong? Or, is there a better way of doing this without using quaternions?
The acceleration variable is a Vec3f containing the accelerometer values from iPhone/iPod filtered with a low-pass filter.
acceleration.normalize();
Vec3f reference = OSG::Vec3f(0, 0, 1);
OSG::Vec3f axis = acceleration.cross( reference );
angle = acos( acceleration.dot( reference ) );
OSG::Quaternion quat;
quat.setValueAsAxisRad(axis, angle);
After this code, I update my scene node using quaternion quat.
Thank you.