Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <math.h>
- #include <time.h>
- #include <unistd.h>
- typedef struct LinkedMem {
- UINT32 uiVersion;
- DWORD uiTick;
- float fAvatarPosition[3];
- float fAvatarFront[3];
- float fAvatarTop[3];
- wchar_t name[256];
- float fCameraPosition[3];
- float fCameraFront[3];
- float fCameraTop[3];
- wchar_t identity[256];
- UINT32 context_len;
- unsigned char context[256];
- wchar_t description[2048];
- } LinkedMem;
- LinkedMem *lm = NULL;
- void ErrorExit(LPTSTR lpszFunction)
- {
- // Retrieve the system error message for the last-error code
- LPVOID lpMsgBuf;
- DWORD dw = GetLastError();
- FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dw,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &lpMsgBuf,
- 0, NULL );
- // Display the error message and exit the process
- printf(TEXT("%s failed with error %d: %s"),
- lpszFunction, dw, lpMsgBuf);
- LocalFree(lpMsgBuf);
- }
- int main(void) {
- HANDLE hMapObject = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink");
- float slots[2][3] = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}};
- int slot = 0;
- float distance = 0;
- float speed;
- time_t stamps[2];
- if (hMapObject == NULL) {
- ErrorExit( "unable to open mapping\n" );
- return 0;
- }
- lm = (LinkedMem *) MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(LinkedMem));
- if (lm == NULL) {
- ErrorExit( "unable to map view\n" );
- CloseHandle(hMapObject);
- hMapObject = NULL;
- return 0;
- }
- while(1) {
- slots[slot][0] = lm->fAvatarPosition[0];
- slots[slot][1] = lm->fAvatarPosition[1];
- slots[slot][2] = lm->fAvatarPosition[2];
- stamps[slot] = time( NULL );
- distance = sqrtf(
- powf( slots[1][0] - slots[0][0], 2)
- + powf( slots[1][1] - slots[0][1], 2)
- + powf( slots[1][2] - slots[0][2], 2)
- ) * 39.370078740157f;
- speed = distance / fabsf( difftime( stamps[0], stamps[1] ) );
- /*printf( "timediff: %f\n", fabsf(difftime( stamps[0], stamps[1] ) ));*/
- if( speed > 0 ) {
- printf( "speed: %f\n", speed );
- }
- slot++;
- slot %= 2;
- sleep( 1 );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment