views:

159

answers:

2

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.

A: 

The ever wonderful Brad Larson posted an excellent description of his initial experiences of a 3d viewer while writing his Moleculs app.

His method for rotations was achieved as follows:

GLfloat currentModelViewMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, currentModelViewMatrix);   
glRotatef(xRotation, currentModelViewMatrix[1], currentModelViewMatrix[5], currentModelViewMatrix[9]);
glGetFloatv(GL_MODELVIEW_MATRIX, currentModelViewMatrix);
glRotatef(yRotation, currentModelViewMatrix[0], currentModelViewMatrix[4], currentModelViewMatrix[8]);

but whether or not this is helpful I can't recommend this blog entry enough Brad learns a lesson or two

Editing to add that I may have misread the question, but will keep the post here as it will likely help people searching with similar keywords.

davbryn
Ok, thank you for trying anyway.
PLinhol
A: 

Can someone help me with this issue? When the angle goes from 180 to 0 degrees the object makes a 360 spin around the Y axis.

However, this method I used to set the object orientation is not what I expected...When the iPod is in landspace orientation the rotation is not what is supposed to be, when it isn't, it's fine.

Anyone has a better solution?

PLinhol