Guest User

Untitled

a guest
Sep 1st, 2010
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.43 KB | None | 0 0
  1. // code by JernejL
  2. // transforms a vector using a 4x4 matrix (translation and scaling is ignored, only 3x3 part is used, we only need rotation!)
  3. stock MatrixTransformVector(Float:vector[3], Float:m[4][4], &Float:resx, &Float:resy, &Float:resz) {
  4.     resz = vector[2] * m[0][0] + vector[1] * m[0][1] + vector[0] * m[0][2] + m[0][3];
  5.     resy = vector[2] * m[1][0] + vector[1] * m[1][1] + vector[0] * m[1][2] + m[1][3];
  6.     resx = -(vector[2] * m[2][0] + vector[1] * m[2][1] + vector[0] * m[2][2] + m[2][3]); // don't ask why -x was needed, i don't know either.
  7. }
  8.  
  9. // something for 0.3b
  10. stock RotatePointVehicleRotation(vehid, Float:Invector[3], &Float:resx, &Float:resy, &Float:resz, worldspace=0) {
  11.  
  12.     new Float:Quaternion[4];
  13.     new Float:transformationmatrix[4][4];
  14.  
  15.     GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
  16.  
  17.     // build a transformation matrix out of the quaternion
  18.     new Float:xx = Quaternion[0] * Quaternion[0];
  19.     new Float:xy = Quaternion[0] * Quaternion[1];
  20.     new Float:xz = Quaternion[0] * Quaternion[2];
  21.     new Float:xw = Quaternion[0] * Quaternion[3];
  22.     new Float:yy = Quaternion[1] * Quaternion[1];
  23.     new Float:yz = Quaternion[1] * Quaternion[2];
  24.     new Float:yw = Quaternion[1] * Quaternion[3];
  25.     new Float:zz = Quaternion[2] * Quaternion[2];
  26.     new Float:zw = Quaternion[2] * Quaternion[3];
  27.  
  28.     transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
  29.     transformationmatrix[0][1] =     2 * ( xy - zw );
  30.     transformationmatrix[0][2] =     2 * ( xz + yw );
  31.     transformationmatrix[0][3] = 0.0;
  32.  
  33.     transformationmatrix[1][0] =     2 * ( xy + zw );
  34.     transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
  35.     transformationmatrix[1][2] =     2 * ( yz - xw );
  36.     transformationmatrix[1][3] = 0.0;
  37.  
  38.     transformationmatrix[2][0] =     2 * ( xz - yw );
  39.     transformationmatrix[2][1] =     2 * ( yz + xw );
  40.     transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
  41.     transformationmatrix[2][3] = 0;
  42.  
  43.     transformationmatrix[3][0] = 0;
  44.     transformationmatrix[3][1] = 0;
  45.     transformationmatrix[3][2] = 0;
  46.     transformationmatrix[3][3] = 1;
  47.  
  48.     // transform the point thru car's rotation
  49.     MatrixTransformVector(Invector, transformationmatrix, resx, resy, resz);
  50.  
  51.     // if worldspace is set it'll return the coords in global space - useful to check tire coords against tire spike proximity directly, etc..
  52.  
  53.     if (worldspace == 1) {
  54.         new Float:fX, Float:fY, Float:fZ;
  55.         GetVehiclePos(vehid, fX, fY, fZ);
  56.         resx += fX;
  57.         resy += fY;
  58.         resz += fZ;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment