void Camera::Update() { UpdateBasis(); MathLib::vector4& camera_xAxis = GetXAxis(); MathLib::vector4& camera_yAxis = GetYAxis(); MathLib::vector4& camera_zAxis = GetZAxis(); MathLib::vector4& camera_position = GetPosition(); // Create world to camera space transform. { MathLib::matrix4x4 worldToCameraTransform_basisComponent ( camera_xAxis.extractX(), camera_xAxis.extractY(), camera_xAxis.extractZ(), 0.0f, camera_yAxis.extractX(), camera_yAxis.extractY(), camera_yAxis.extractZ(), 0.0f, camera_zAxis.extractX(), camera_zAxis.extractY(), camera_zAxis.extractZ(), 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ); MathLib::matrix4x4 worldToCameraTransform_translationComponent ( 1.0f, 0.0f, 0.0f, -camera_position.extractX(), 0.0f, 1.0f, 0.0f, -camera_position.extractY(), 0.0f, 0.0f, 1.0f, -camera_position.extractZ(), 0.0f, 0.0f, 0.0f, 1.0f ); MathLib::matrix4x4 worldToCameraTransform; MathLib::matrix4x4_mul(worldToCameraTransform_basisComponent, worldToCameraTransform_translationComponent, worldToCameraTransform); MathLib::matrix4x4_copy(worldToCameraSpaceMatrix, worldToCameraTransform); } // Create camera to world space transform. { MathLib::matrix4x4 orientation ( camera_xAxis.extractX(), camera_yAxis.extractX(), camera_zAxis.extractX(), 0.0f, camera_xAxis.extractY(), camera_yAxis.extractY(), camera_zAxis.extractY(), 0.0f, camera_xAxis.extractZ(), camera_yAxis.extractZ(), camera_zAxis.extractZ(), 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ); MathLib::matrix4x4 translation ( 1.0f, 0.0f, 0.0f, camera_position.extractX(), 0.0f, 1.0f, 0.0f, camera_position.extractY(), 0.0f, 0.0f, 1.0f, camera_position.extractZ(), 0.0f, 0.0f, 0.0f, 1.0f ); MathLib::matrix4x4_mul(translation, orientation, cameraToWorldSpaceMatrix); } }
//************************************************ //*操纵杆输入线程 //************************************************ DWORD WINAPI t1::InputThreadProcedure(LPVOID lpStartupParam) { // get the data we passed to the thread. Note that we don't have to use this // at all if we don't want MYDATA* pMyData = (MYDATA*)lpStartupParam; // access some imaginary members of MYDATA, which you can define on // your own later pMyData->nTime = GetCurrentTime(); // imaginary function I created pMyData->nNumber = 5; // here's the thread's main loop ?kind of like the main loop in WinMain MSG msg; int i; for (;;) { //处理外部消息 if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { GetMessage(&msg, NULL, 0, 0); if (msg.message == WM_THREADSTOP) break; // only way out of the for( ;; ) loop TranslateMessage(&msg); DispatchMessage(&msg); } else { switch (m_TestState) { case STATE_DISPLAYINSTURCTION: case STATE_DISPLAYNEXT: case STATE_DISPLAYOPTION: //呈现开始选项,等待按任意键开始测试 if (JoystickUpdate()) { for (i = 0; i<8; i++) { if (IsButtonDown(KEY_YES)) { m_TrialNo++; TestInit(); m_TestState = STATE_DISPLAYOBJ; break; } } } break; case STATE_DISPLAYOBJ: case STATE_MOVINGOBJ: //测试过程中获得操纵杆输入 if (JoystickUpdate()) { JoyX = GetXAxis();//GetYAxis();// JoyY = GetYAxis();//-GetZAxis();// if (m_Setting.m_MoveMode == MODE_MOVEROATE) { JoyZ = GetZAxis();//GetXAxis();// post_fai = (float)(JoyZ - post_fai0)*(3600.0 / 1024.0) / m_HardSetting.m_KnobSensitive;//GetZAxis()*PI/400.0; while (post_fai<-180) { post_fai = post_fai + 360; } while (post_fai>180) { post_fai = post_fai - 360; } } } break; case STATE_OVER: //测试结束,等待按任意键退出 if (JoystickUpdate()) { for (i = 0; i<12; i++) { if (IsButtonDown(i)) { PostThreadMessage(dwInputThreadID, WM_THREADSTOP, 0, 0); m_TestState = STATE_NEXT;// STATE_EXIT --> STATE_NEXT } } } break; default: break; } // do the task ?add in your own stuff here // yield to other threads, because we almost never get messages // (note that we may be yielding to WinMain too) //以键盘代替操纵杆 if (JOY == 0) { if (IsButtonDown(DIK_ESCAPE)) { PostThreadMessage(dwInputThreadID, WM_THREADSTOP, 0, 0); m_TestState = STATE_EXIT; } } } Sleep(1); } g_nThreadExitCount++; return 0; }