Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // code by JernejL
- // transforms a vector using a 4x4 matrix (translation and scaling is ignored, only 3x3 part is used, we only need rotation!)
- stock MatrixTransformVector(Float:vector[3], Float:m[4][4], &Float:resx, &Float:resy, &Float:resz) {
- resz = vector[2] * m[0][0] + vector[1] * m[0][1] + vector[0] * m[0][2] + m[0][3];
- resy = vector[2] * m[1][0] + vector[1] * m[1][1] + vector[0] * m[1][2] + m[1][3];
- 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.
- }
- // something for 0.3b
- stock RotatePointVehicleRotation(vehid, Float:Invector[3], &Float:resx, &Float:resy, &Float:resz, worldspace=0) {
- new Float:Quaternion[4];
- new Float:transformationmatrix[4][4];
- GetVehicleRotationQuat(vehid, Quaternion[0], Quaternion[1], Quaternion[2], Quaternion[3]);
- // build a transformation matrix out of the quaternion
- new Float:xx = Quaternion[0] * Quaternion[0];
- new Float:xy = Quaternion[0] * Quaternion[1];
- new Float:xz = Quaternion[0] * Quaternion[2];
- new Float:xw = Quaternion[0] * Quaternion[3];
- new Float:yy = Quaternion[1] * Quaternion[1];
- new Float:yz = Quaternion[1] * Quaternion[2];
- new Float:yw = Quaternion[1] * Quaternion[3];
- new Float:zz = Quaternion[2] * Quaternion[2];
- new Float:zw = Quaternion[2] * Quaternion[3];
- transformationmatrix[0][0] = 1 - 2 * ( yy + zz );
- transformationmatrix[0][1] = 2 * ( xy - zw );
- transformationmatrix[0][2] = 2 * ( xz + yw );
- transformationmatrix[0][3] = 0.0;
- transformationmatrix[1][0] = 2 * ( xy + zw );
- transformationmatrix[1][1] = 1 - 2 * ( xx + zz );
- transformationmatrix[1][2] = 2 * ( yz - xw );
- transformationmatrix[1][3] = 0.0;
- transformationmatrix[2][0] = 2 * ( xz - yw );
- transformationmatrix[2][1] = 2 * ( yz + xw );
- transformationmatrix[2][2] = 1 - 2 * ( xx + yy );
- transformationmatrix[2][3] = 0;
- transformationmatrix[3][0] = 0;
- transformationmatrix[3][1] = 0;
- transformationmatrix[3][2] = 0;
- transformationmatrix[3][3] = 1;
- // transform the point thru car's rotation
- MatrixTransformVector(Invector, transformationmatrix, resx, resy, resz);
- // if worldspace is set it'll return the coords in global space - useful to check tire coords against tire spike proximity directly, etc..
- if (worldspace == 1) {
- new Float:fX, Float:fY, Float:fZ;
- GetVehiclePos(vehid, fX, fY, fZ);
- resx += fX;
- resy += fY;
- resz += fZ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment