WinSock 연결을 사용하여 가속도 정보 및 iPhone을 가져 와서 Direct3D 응용 프로그램에 연결합니다. Apels GLGravity의 샘플 코드를 수정하여 헬리콥터가 중력과 관련하여 움직이게 만들었지 만 헬리콥터가 거꾸로 날아 가지 않도록 움직임을 "캡핑"해야합니다! 나는 가속도계의 출력을 제한하려고 시도했다.Direct3D 및 iPhone 가속도계 매트릭스
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
아이폰에서 directx? – hhafez
아니, 나는 그가 제어 장치와 마찬가지로 아이폰을 사용했다고 생각한다 – bayda