Advertisement
EnzoMetlc

[Include] PHY (Phyisics objects).

Feb 10th, 2015
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.99 KB | None | 0 0
  1. #define MAX_PARABOLIC_FIRES 10
  2. #define MAX_PHYSICS_OBJECTS 10
  3.  
  4. enum PhysicsEnum
  5. {
  6.     PHY@ObjectID@internal_,
  7.     Float:PHY@Distance@internal_,
  8.     PHY@CurrentFire@internal_
  9. };
  10. static PHY@Info@internal_[MAX_PHYSICS_OBJECTS][PhysicsEnum];
  11. static Float:PHY@Pos@internal_[MAX_PHYSICS_OBJECTS][MAX_PARABOLIC_FIRES][7];
  12.  
  13.  
  14.  
  15.  
  16. static const Float:Coords[] = {0.133333, 0.250000, 0.349999, 0.433333, 0.500000, 0.566666, 0.649999, 0.750000, /*0.866666*/0.87555, 1.000000};
  17. static const Float:Heigth_Coords[] = {/*0.592592*/0.532592, 0.759259, 0.888888, 0.962962, 1.000000, 0.962962, 0.888888, 0.759259, /*0.592592*/0.512592, 1.000000};
  18. static const Float:SpeedPerHeigth[] = {1.00, 1.50, 2.00, 2.50, 3.00, 2.50, 2.00, /*1.50*/1.75, 1.50, /*2.00*/1.25};
  19.  
  20.  
  21.  
  22. /* Macros */
  23. #define PHY_FinishAdjust(%1) SetObjectRot(PHY@Info@internal_[%1][PHY@ObjectID@internal_], PHY@Pos@internal_[%1][0][5], 0.0, PHY@Pos@internal_[%1][0][4]); MoveObject(PHY@Info@internal_[%1][PHY@ObjectID@internal_], PHY@Pos@internal_[%1][0][0], PHY@Pos@internal_[%1][0][1], PHY@Pos@internal_[%1][0][2], PHY@Pos@internal_[%1][0][3])
  24. #define fix_angle(%1) (%1 > 0.0) ? (%1) : (%1 + 360.0)
  25. #define PHY_GetHeigthAngle(%1,%2) new Float:_PHY@heigthangle = atan2(%1, %2);
  26.  
  27.  
  28.  
  29. stock Float:PHY_GetDistOfNextPoint(slot, fire)
  30. {
  31.     switch(fire)
  32.     {
  33.         case 0 .. 8: return VectorSize(PHY@Pos@internal_[slot][fire][0] - PHY@Pos@internal_[slot][fire + 1][0], PHY@Pos@internal_[slot][fire][1] - PHY@Pos@internal_[slot][fire + 1][1], PHY@Pos@internal_[slot][fire][2] - PHY@Pos@internal_[slot][fire + 1][2]);
  34.         case 9: return VectorSize(PHY@Pos@internal_[slot][8][0] - PHY@Pos@internal_[slot][9][0], PHY@Pos@internal_[slot][8][1] - PHY@Pos@internal_[slot][9][1], PHY@Pos@internal_[slot][8][2] - PHY@Pos@internal_[slot][9][2]);
  35.     }
  36.     return 0.0;
  37. }
  38.  
  39.  
  40.  
  41. stock MovePhysicObject(objectid, Float:fX, Float:fY, Float:fZ, const Float:speed, const Float:max_heigth)
  42. {
  43.     new idx = -1;
  44.    
  45.     for(new i = 0; i < MAX_PHYSICS_OBJECTS; i++)
  46.     {
  47.         if(PHY@Info@internal_[i][PHY@ObjectID@internal_] == -1)
  48.         {
  49.             idx = i;
  50.             PHY@Info@internal_[idx][PHY@ObjectID@internal_] = objectid;
  51.             break;
  52.         }
  53.     }
  54.    
  55.     if(idx == -1) return -1;
  56.    
  57.    
  58.     new Float:Pos[3];
  59.     GetObjectPos(objectid, Pos[0], Pos[1], Pos[2]);
  60.  
  61.     new const Float:dist = VectorSize(Pos[0] - fX, Pos[1] - fY, Pos[2] - fZ);
  62.     new const Float:angle = (atan2(fY - Pos[1], fX - Pos[0]) + 270.0);
  63.     new const Float:total_heigth = (Pos[2] >= fZ) ? (Pos[2]) : (fZ + max_heigth);
  64.  
  65.     for(new i = 0; i < 10; i++)
  66.     {
  67.         PHY@Pos@internal_[idx][i][0] = Pos[0] + ((Coords[i] * dist) * floatsin(-angle, degrees)); // Pos X
  68.         PHY@Pos@internal_[idx][i][1] = Pos[1] + ((Coords[i] * dist) * floatcos(-angle, degrees)); // Pos Y
  69.         PHY@Pos@internal_[idx][i][2] = Heigth_Coords[i] * total_heigth;               // Pos Z
  70.         PHY@Pos@internal_[idx][i][3] = speed / SpeedPerHeigth[i];                 // Speed
  71.     }
  72.  
  73.     PHY@Pos@internal_[idx][9][2] = fZ;
  74.     PHY@Info@internal_[idx][PHY@Distance@internal_] = dist;
  75.     PHY@Info@internal_[idx][PHY@CurrentFire@internal_] = 0;
  76.    
  77.     return idx;
  78. }
  79.  
  80.  
  81.  
  82.  
  83. stock PHY_AdjustHeigthAngle(slot, const Float:start_z, const Float:add_rot = 0.0)
  84. {
  85.     new Float:dist;
  86.     new Float:angle;
  87.    
  88.     for(new i = 1; i < 9; i++)
  89.     {
  90.         dist = VectorSize(PHY@Pos@internal_[slot][i][0] - PHY@Pos@internal_[slot][i + 1][0], PHY@Pos@internal_[slot][i][1] - PHY@Pos@internal_[slot][i + 1][1], PHY@Pos@internal_[slot][i][2] - PHY@Pos@internal_[slot][i + 1][2]);
  91.         angle = atan2(PHY@Pos@internal_[slot][i + 1][2] - PHY@Pos@internal_[slot][i][2], dist) + add_rot;
  92.        
  93.         PHY@Pos@internal_[slot][i][5] = fix_angle(angle);
  94.     }
  95.    
  96.     dist = VectorSize(PHY@Pos@internal_[slot][0][0] - PHY@Pos@internal_[slot][1][0], PHY@Pos@internal_[slot][0][1] - PHY@Pos@internal_[slot][1][1], PHY@Pos@internal_[slot][0][2] - PHY@Pos@internal_[slot][1][2]);
  97.     angle = atan2(PHY@Pos@internal_[slot][0][2] - start_z, dist) + add_rot;
  98.    
  99.     PHY@Pos@internal_[slot][0][5] = fix_angle(angle);
  100.    
  101.    
  102.     dist = VectorSize(PHY@Pos@internal_[slot][8][0] - PHY@Pos@internal_[slot][9][0], PHY@Pos@internal_[slot][8][1] - PHY@Pos@internal_[slot][9][1], PHY@Pos@internal_[slot][8][2] - PHY@Pos@internal_[slot][9][2]);
  103.     angle = atan2(PHY@Pos@internal_[slot][9][2] - PHY@Pos@internal_[slot][8][2], dist) + add_rot;
  104.    
  105.     PHY@Pos@internal_[slot][9][5] = fix_angle(angle);
  106.     return 1;
  107. }
  108.  
  109.  
  110.  
  111. stock PHY_AdjustAngle(slot, const Float:add_angle = 0.0)
  112. {
  113.     for(new i = 0; i < 9; i++)
  114.     {
  115.         PHY@Pos@internal_[slot][i][4] = (atan2(PHY@Pos@internal_[slot][i + 1][1] - PHY@Pos@internal_[slot][i][1], PHY@Pos@internal_[slot][i + 1][0] - PHY@Pos@internal_[slot][i][0]) + 270.0) + add_angle;
  116.     }
  117.  
  118.     PHY@Pos@internal_[slot][9][4] = (atan2(PHY@Pos@internal_[slot][9][1] - PHY@Pos@internal_[slot][8][1], PHY@Pos@internal_[slot][9][0] - PHY@Pos@internal_[slot][8][0]) + 270.0) + add_angle;
  119.     return 1;
  120. }
  121.  
  122.  
  123.  
  124. stock PHY_AdjustCurve(slot, const Float:value, const Float:rot = 0.0)
  125. {
  126.     new const Float:angle = atan2(PHY@Pos@internal_[slot][9][1] - PHY@Pos@internal_[slot][0][1], PHY@Pos@internal_[slot][9][0] - PHY@Pos@internal_[slot][0][0]) + 270.0;
  127.  
  128.     for(new i = 0; i < 10; i++)
  129.     {
  130.         PHY@Pos@internal_[slot][i][0] += (Heigth_Coords[i] * value) * floatsin(-angle + (Heigth_Coords[i] * value), degrees); // Pos X
  131.         PHY@Pos@internal_[slot][i][1] += (Heigth_Coords[i] * value) * floatcos(-angle + (Heigth_Coords[i] * value), degrees); // Pos Y
  132.        
  133.         PHY@Pos@internal_[slot][i][4] += fix_angle(rot * (i + 1));
  134.     }
  135.     return 1;
  136. }
  137.  
  138.  
  139.  
  140.  
  141. public OnObjectMoved(objectid)
  142. {
  143.     new slot = PHY_IsPhysics(objectid);
  144.  
  145.     if(slot != -1)
  146.     {
  147.         if(++PHY@Info@internal_[slot][PHY@CurrentFire@internal_] < 10)
  148.         {
  149.             CallLocalFunction("PHY_OnUpdate", "ddi", objectid, slot, PHY@Info@internal_[slot][PHY@CurrentFire@internal_]);
  150.             return 1;
  151.     }
  152.  
  153.         CallLocalFunction("PHY_OnFinish", "dd", objectid, slot);
  154.     }
  155.     return 1;
  156. }
  157. #if defined _ALS_OnObjectMoved
  158.     #undef OnObjectMoved
  159. #else
  160.     #define _ALS_OnObjectMoved
  161. #endif
  162. #define OnObjectMoved PHY_OnObjectMoved
  163. forward OnObjectMoved(objectid);
  164.  
  165.  
  166.  
  167.  
  168. stock PHY_IsPhysics(objectid)
  169. {
  170.     for(new i = 0; i < MAX_PHYSICS_OBJECTS; i++)
  171.     {
  172.         if(PHY@Info@internal_[i][PHY@ObjectID@internal_] == objectid) return i;
  173.     }
  174.     return -1;
  175. }
  176.  
  177.  
  178. stock PHY_Finish(slot, const bool:destroy = true)
  179. {
  180.     if(slot == -1) return -1;
  181.    
  182.    
  183.     if(destroy) DestroyObject(PHY@Info@internal_[slot][PHY@ObjectID@internal_]);
  184.    
  185.     PHY@Info@internal_[slot][PHY@ObjectID@internal_] = -1;
  186.     PHY@Info@internal_[slot][PHY@CurrentFire@internal_] = 0;
  187.    
  188.     for(new i = 0; i < 10; i++) PHY@Pos@internal_[slot][i][0] = PHY@Pos@internal_[slot][i][1] = PHY@Pos@internal_[slot][i][2] = PHY@Pos@internal_[slot][i][3] = 0.0;
  189.     return 1;
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197. forward PHY_OnUpdate(objectid, slot, fire);
  198. forward PHY_OnFinish(objectid, slot);
  199.  
  200.  
  201. #undef fix_angle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement