Пример #1
0
void CALLBACK MyDispatchProcCC(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
	switch (pData->dwID)
	{
	case SIMCONNECT_RECV_ID_EVENT:
	{
		SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;

		switch (evt->uEventID)
		{
		case EVENT_SIM_START:
			SimConnect_RequestDataOnSimObjectType(hSimConnect, REQUEST_1, DEFINITION_1, 0, SIMCONNECT_SIMOBJECT_TYPE_USER);
			break;
		case EVENT_AIRCRAFT_CHANGED:
			SimConnect_RequestDataOnSimObjectType(hSimConnect, REQUEST_1, DEFINITION_1, 0, SIMCONNECT_SIMOBJECT_TYPE_USER);
			break;
		case EVENT_LEFT:
			currentCameraPosition.fDeltaXMeters -= cameraMovementSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_RIGHT:
			currentCameraPosition.fDeltaXMeters += cameraMovementSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_UP:
			currentCameraPosition.fDeltaZMeters += cameraMovementSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_DOWN:
			currentCameraPosition.fDeltaZMeters -= cameraMovementSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_FORWARD:
			currentCameraPosition.fDeltaYMeters += cameraMovementSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_BACK:
			currentCameraPosition.fDeltaYMeters -= cameraMovementSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_CENTER:
			currentCameraPosition.fDeltaXMeters = 0;
			currentCameraPosition.fDeltaYMeters = 0;
			currentCameraPosition.fDeltaZMeters = 0;
			currentCameraPosition.fPitchDeg = 0.0f;
			currentCameraPosition.fHeadingDeg = 0.0f;
			currentCameraPosition.fBankDeg = 0.0f;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_PITCH_DOWN:
			currentCameraPosition.fPitchDeg += cameraTiltSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_PITCH_UP:
			currentCameraPosition.fPitchDeg -= cameraTiltSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_HEADING_LEFT:
			currentCameraPosition.fHeadingDeg -= cameraTiltSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;
		case EVENT_HEADING_RIGHT:
			currentCameraPosition.fHeadingDeg += cameraTiltSpeed;
			SimConnect_CameraSetRelative6DOF(hSimConnect, currentCameraPosition.fDeltaXMeters, currentCameraPosition.fDeltaYMeters, currentCameraPosition.fDeltaZMeters, currentCameraPosition.fPitchDeg, currentCameraPosition.fBankDeg, currentCameraPosition.fHeadingDeg);
			break;

		case EVENT_CAMERA_CHOOSE_1:
		case EVENT_CAMERA_CHOOSE_2:
		case EVENT_CAMERA_CHOOSE_3:
		case EVENT_CAMERA_CHOOSE_4:
		case EVENT_CAMERA_CHOOSE_5:
		case EVENT_CAMERA_CHOOSE_6:
		case EVENT_CAMERA_CHOOSE_7:
		case EVENT_CAMERA_CHOOSE_8:
		case EVENT_CAMERA_CHOOSE_9:
		{
			ConfigLoader::ConfigType::const_iterator vehicleIterator = cameraConfig.find(aircraftName);
			if (vehicleIterator != cameraConfig.end()) {
				std::map<unsigned int, SIMCONNECT_RECV_CAMERA_6DOF >::const_iterator cameraIterator = vehicleIterator->second.find(evt->uEventID);
				if (cameraIterator != vehicleIterator->second.end()) {
					SIMCONNECT_RECV_CAMERA_6DOF cameraPosition = cameraIterator->second;
					SimConnect_CameraSmoothRelative6DOF(hSimConnect, cameraPosition.fDeltaXMeters, cameraPosition.fDeltaYMeters, cameraPosition.fDeltaZMeters, cameraPosition.fPitchDeg, cameraPosition.fBankDeg, cameraPosition.fHeadingDeg, 0.3f);
					currentCameraPosition = cameraPosition;
				}
			}
			break;
		}
		case EVENT_SAVE_CAMERA_1:
		case EVENT_SAVE_CAMERA_2:
		case EVENT_SAVE_CAMERA_3:
		case EVENT_SAVE_CAMERA_4:
		case EVENT_SAVE_CAMERA_5:
		case EVENT_SAVE_CAMERA_6:
		case EVENT_SAVE_CAMERA_7:
		case EVENT_SAVE_CAMERA_8:
		case EVENT_SAVE_CAMERA_9:
			currentSaveCamera = evt->uEventID - 9;
			save = true;
			SimConnect_RequestCameraRelative6DOF(hSimConnect, REQUEST_CAMERA_POSITION);
			break;

		default:
			break;
		}
		break;
	}
	case SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE:
	{
		SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE*)pData;

		switch (pObjData->dwRequestID)
		{
		case REQUEST_1:
		{
			StructVS *pS = (StructVS*)&pObjData->dwData;
			DWORD cbtitle;
			char *aircraftNameCStr;
			SimConnect_RetrieveString(pData, cbData, &pS->strings, &aircraftNameCStr, &cbtitle);
			aircraftName = std::string(aircraftNameCStr);
			std::replace(aircraftName.begin(), aircraftName.end(), ' ', '_');
			break;
		}
		break;
		}
		break;
	}
	case SIMCONNECT_RECV_ID_CAMERA_6DOF:
	{
		currentCameraPosition = *(SIMCONNECT_RECV_CAMERA_6DOF*)pData;

		if (save) {
			cameraConfig[aircraftName][currentSaveCamera] = currentCameraPosition;
			configLoader.save(cameraConfig);
			save = false;
		}
		break;
	}

	case SIMCONNECT_RECV_ID_QUIT:
		quit = 1;
		break;
	default:
		break;
	}
}