Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting displacement from accelerometer data with Core Motion
    text
    copied!<p>I am developing an augmented reality application that (at the moment) wants to display a simple cube on top of a surface, and be able to move in space (both rotating and displacing) to look at the cube in all the different angles. The problem of calibrating the camera doesn't apply here since I ask the user to place the iPhone on the surface he wants to place the cube on and then press a button to reset the attitude. To find out the camera rotation is very simple with the Gyroscope and Core Motion. I do it this way:</p> <pre><code>if (referenceAttitude != nil) { [attitude multiplyByInverseOfAttitude:referenceAttitude]; } CMRotationMatrix mat = attitude.rotationMatrix; GLfloat rotMat[] = { mat.m11, mat.m21, mat.m31, 0, mat.m12, mat.m22, mat.m32, 0, mat.m13, mat.m23, mat.m33, 0, 0, 0, 0, 1 }; glMultMatrixf(rotMat); </code></pre> <p>This works really well. More problems arise anyway when I try to find the displacement in space during an acceleration. The Apple Teapot example with Core Motion just adds the x, y and z values of the acceleration vector to the position vector. This (apart from having not much sense) has the result of returning the object to the original position after an acceleration. (Since the acceleration goes from positive to negative or vice versa). They did it like this:</p> <pre><code>translation.x += userAcceleration.x; translation.y += userAcceleration.y; translation.z += userAcceleration.z; </code></pre> <p>What should I do to find out displacement from the acceleration in some istant? (with known time difference). Looking some other answers, it seems like I have to integrate twice to get velocity from acceleration and then position from velocity. But there is no example in code whatsoever, and I don't think that is really necessary. Also, there is the problem that when the iPhone is still on a plane, accelerometer values are not null (there is some noise I think). How much should I filter those values? Am I supposed to filter them at all?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload