Advertisement
SHOROOP

IPL->Pawn Converter

Aug 2nd, 2013 (edited)
1,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.58 KB | None | 0 0
  1. #include <a_samp>
  2. #include <sscanf2>
  3.  
  4. #define IPL_NAME "test.ipl"
  5.  
  6. public OnFilterScriptInit()
  7. {
  8.     printf ("Converter started.");
  9.     new line[1024], File: file;
  10.     new File:output;
  11.     new model, Float:px, Float:py, Float:pz, Float:rx, Float:ry, Float:rz, Float:qx, Float:qy, Float:qz, Float:qw;
  12.     file = fopen(IPL_NAME, io_read);
  13.     if (file)
  14.     {
  15.         printf ("Input file loaded.");
  16.         output = fopen ("converted.txt", io_append);
  17.         if (!output)
  18.         {
  19.             printf ("Output file missing.");
  20.             return 1;
  21.         }
  22.         printf ("Output file loaded.");
  23.         while (fread(file, line))
  24.         {
  25.            
  26.             sscanf(line, "p<,>i{s[32]i}fffffff{i}", model, px, py, pz, qx, qy, qz, qw);
  27.             printf(line);
  28.             QuatToEulerZXY(qx, qy, qz, qw, rx, ry, rz);
  29.                     AddObject(model, px, py, pz, rx, ry, rz, output);
  30.         }
  31.     }
  32.     else printf ("Input file missing.");
  33.     fclose(file);
  34.     fclose(output);
  35.     return 1;
  36. }
  37.  
  38. stock AddObject(model, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, File:handle)
  39. {
  40.     new str[256];
  41.     format(str, 256, "\tCreateObject(%d, %f, %f, %f, %f, %f, %f, 300.0);\n", model, x, y, z, rx, ry, rz);
  42.     printf(str);
  43.     fwrite(handle, str);
  44.     return 1;
  45. }
  46.  
  47. stock QuatToEulerZXY(Float:quat_x, Float:quat_y, Float:quat_z, Float:quat_w, &Float:x, &Float:y, &Float:z)
  48. {
  49.     x = -asin(2 * ((quat_x * quat_z) + (quat_w * quat_y)));
  50.     y = atan2(2 * ((quat_y * quat_z) + (quat_w * quat_x)), (quat_w * quat_w) - (quat_x * quat_x) - (quat_y * quat_y) + (quat_z * quat_z));
  51.     z = -atan2(2 * ((quat_x * quat_y) + (quat_w * quat_z)), (quat_w * quat_w) + (quat_x * quat_x) - (quat_y * quat_y) - (quat_z * quat_z));
  52.     return 1;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement