Guest User

Untitled

a guest
May 1st, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. stock GetXYZInfrontOfVehicle(vehid,Float:distance,&Float:x,&Float:y,&Float:z)
  2. {
  3.     new Float:Quaternion[4];
  4.     new Float:transformationmatrix[4][4];
  5.  
  6.     GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
  7.  
  8.     new Float:xx = Quaternion[0] * Quaternion[0];
  9.     new Float:xy = Quaternion[0] * Quaternion[1];
  10.     new Float:xz = Quaternion[0] * Quaternion[2];
  11.     new Float:xw = Quaternion[0] * Quaternion[3];
  12.     new Float:yy = Quaternion[1] * Quaternion[1];
  13.     new Float:yz = Quaternion[1] * Quaternion[2];
  14.     new Float:yw = Quaternion[1] * Quaternion[3];
  15.     new Float:zz = Quaternion[2] * Quaternion[2];
  16.     new Float:zw = Quaternion[2] * Quaternion[3];
  17.  
  18.     transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
  19.     transformationmatrix[0][1] =     2 * ( xy - zw );
  20.     transformationmatrix[0][2] =     2 * ( xz + yw );
  21.     transformationmatrix[0][3] = 0.0;
  22.  
  23.     transformationmatrix[1][0] =     2 * ( xy + zw );
  24.     transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
  25.     transformationmatrix[1][2] =     2 * ( yz - xw );
  26.     transformationmatrix[1][3] = 0.0;
  27.  
  28.     transformationmatrix[2][0] =     2 * ( xz - yw );
  29.     transformationmatrix[2][1] =     2 * ( yz + xw );
  30.     transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
  31.     transformationmatrix[2][3] = 0;
  32.  
  33.     transformationmatrix[3][0] = 0;
  34.     transformationmatrix[3][1] = 0;
  35.     transformationmatrix[3][2] = 0;
  36.     transformationmatrix[3][3] = 1;
  37.     GetVehiclePos(vehid,x,y,z);
  38.     z +=( -1 * transformationmatrix[0][1] + transformationmatrix[0][3])*distance;
  39.     y +=( -1 * transformationmatrix[1][1] + transformationmatrix[1][3])*distance;
  40.     x +=( -(-1 * transformationmatrix[2][1] + transformationmatrix[2][3]))*distance;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment