私はWinSock接続を使用して、加速度計情報とiPhoneを取得し、Direct3Dアプリケーションに取り込みます。私はApples GLGravityのサンプルコードを変更して、ヘリコプターを重力に関して動かすようにしましたが、ヘリコプターが逆さまに飛べないように動きを「キャップ」する必要があります。私は加速度計の出力を制限しようとしましたDirect3D&iPhone Accelerometer Matrix
if (y < -0.38f) {
y = -0.38f;
}
これはうまくいきません!私が考えることができるのは、カスタムマトリクスを変更する必要があることだけですが、変更する必要があるものの周りに頭を浮かべているようには見えません。行列は以下のコードです。
_x = acceleration.x;
_y = acceleration.y;
_z = acceleration.z;
float length;
D3DXMATRIX matrix, t;
memset(matrix, '\0', sizeof(matrix));
D3DXMatrixIdentity(&matrix);
// Make sure acceleration value is big enough.
length = sqrtf(_x * _x + _y * _y + _z * _z);
if (length >= 0.1f && 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;
}
誰でも助けていただければ幸いです。
あなたは今どのような行動をしていますか? – bayda
iphoneのdirectxですか? – hhafez
いいえ、私は彼が制御装置のようにiphoneを使用したと思います – bayda