Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- else if(packetID==13) {
- char position[3][8]; //X,Y,Z
- cout<<" - Player position: [\n";
- for(int coord=0; coord<3; coord++) {
- scl.read(8, position[coord]); //Reads int bytes to char* (instance of socket class)
- for(int xx=0; xx<8; xx++) //just looping through char* to see the contents
- cout<<(int)position[coord][xx]<<" ";
- cout<<"\n";
- swapBytes(position[coord], 8); //swaping bytes
- for(int xx=0; xx<8; xx++) //Checking if swapped correctly
- cout<<(int)position[coord][xx]<<" ";
- cout<<"\n -> "<<(*((double*)position[coord]));
- if(coord<2)
- cout<<", \n\n";
- }
- cout<<"]\n";
- if(!scl.ignore(41-3*8))break; //Ignoring the rest of the data
- break;
- }
- void swapBytes(char*arr, int length) {
- char b;
- for(int i=0; i<length; i+=2) {
- b = arr[i];
- arr[i] = arr[i+1];
- arr[i+1]=b;
- }
- }
- /*PROGRAM OUTPUT*/
- /*
- - Player position: [
- 64 80 43 -3 12 -3 91 -55
- 80 64 -3 43 -3 12 -55 91
- -> 1.42249e+134,
- 64 85 -89 -82 20 -128 0 0
- 85 64 -82 -89 -128 20 0 0
- -> 1.11376e-310,
- 64 85 64 0 0 0 0 0
- 85 64 0 64 0 0 0 0
- -> 5.30507e-315]
- Over and out!
- Last packet: 13
- actual position is near [63,86,309]
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement