Note that there are some explanatory texts on larger screens.

plurals
  1. PODirect3D & iPhone Accelerometer Matrix
    primarykey
    data
    text
    <p>I am using a WinSock connection to get the accelerometer info off and iPhone and into a Direct3D application. I have modified Apples GLGravity's sample code to get my helicopter moving in relation to gravity, however I need to "cap" the movement so the helicopter can't fly upside down! I have tried to limit the output of the accelerometer like so</p> <pre><code>if (y &lt; -0.38f) { y = -0.38f; } </code></pre> <p>Except this doesn't seem to work!? The only thing I can think of is I need to modify the custom matrix, but I can't seem to get my head around what I need to be changing. The matrix is code is below.</p> <pre><code> _x = acceleration.x; _y = acceleration.y; _z = acceleration.z; float length; D3DXMATRIX matrix, t; memset(matrix, '\0', sizeof(matrix)); D3DXMatrixIdentity(&amp;matrix); // Make sure acceleration value is big enough. length = sqrtf(_x * _x + _y * _y + _z * _z); if (length &gt;= 0.1f &amp;&amp; kInFlight == TRUE) { // We have a acceleration value good enough to work with. matrix._44 = 1.0f; // // First matrix column is a gravity vector. matrix._11 = _x / length; matrix._12 = _y / length; matrix._13 = _z / length; // Second matrix is arbitrary vector in the plane perpendicular to the gravity vector {Gx, Gy, Gz}. // defined by the equation Gx * x + Gy * y + Gz * z = 0 in which we set x = 0 and y = 1. matrix._21 = 0.0f; matrix._22 = 1.0f; matrix._23 = -_y / _z; length = sqrtf(matrix._21 * matrix._21 + matrix._22 * matrix._22 + matrix._23 * matrix._23); matrix._21 /= length; matrix._22 /= length; matrix._23 /= length; // Set third matrix column as a cross product of the first two. matrix._31 = matrix._12 * matrix._23 - matrix._13 * matrix._22; matrix._32 = matrix._21 * matrix._13 - matrix._23 * matrix._11; matrix._33 = matrix._11 * matrix._22 - matrix._12 * matrix._21; } </code></pre> <p>If anyone can help it would be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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