07.01.2014, 16:29
It's not that I didn't tried to use these vector matrix after I failed with rotations
Thats what I created, both ways I know how to solve a System of linear equations
Well in both ways there were special cases if the vehicle was on a hill that it returned an invalid z value
It could be possible that I made a mistake with Gauss but I doubt it because it works fine on normal roads
Thats what I created, both ways I know how to solve a System of linear equations
pawn Код:
stock Float: Det3x3({ Float, _ }: mat[][]) {
return
(mat[0][0] * mat[1][1] * mat[2][2] + mat[0][1] * mat[1][2] * mat[2][0] + mat[0][2] * mat[1][0] * mat[2][1]) -
(mat[2][0] * mat[1][1] * mat[0][2] + mat[2][1] * mat[1][2] * mat[0][0] + mat[2][2] * mat[1][0] * mat[0][1])
;
}
pawn Код:
stock OffsetFromVehiclePosition(vehicle, Float: x, Float: y, Float: z, & Float: offX, & Float: offY, & Float: offZ) {
//initial processing step - gather information
new
Mat4x3[MatrixParts][MatrixIndicator]
;
GetVehicleMatrix(vehicle, Mat4x3);
// offset calculation
x -= Mat4x3[mp_POS][mi_X];
y -= Mat4x3[mp_POS][mi_Y];
z -= Mat4x3[mp_POS][mi_Z];
#if 1 // Cramer's rule
new
Float: Mat3x3_1[3][3],
Float: Mat3x3_2[3][3],
Float: Mat3x3_3[3][3]
;
Mat3x3_1[0][0] = Mat4x3[mp_PITCH][mi_X];
Mat3x3_1[1][0] = Mat4x3[mp_PITCH][mi_Y];
Mat3x3_1[2][0] = Mat4x3[mp_PITCH][mi_Z];
Mat3x3_1[0][1] = Mat4x3[mp_ROLL][mi_X];
Mat3x3_1[1][1] = Mat4x3[mp_ROLL][mi_Y];
Mat3x3_1[2][1] = Mat4x3[mp_ROLL][mi_Z];
Mat3x3_1[0][2] = Mat4x3[mp_YAW][mi_X];
Mat3x3_1[1][2] = Mat4x3[mp_YAW][mi_Y];
Mat3x3_1[2][2] = Mat4x3[mp_YAW][mi_Z];
offZ = Det3x3(Mat3x3_1);
if(offZ != 0.0) {
Mat3x3_2 = Mat3x3_1;
Mat3x3_3 = Mat3x3_1;
Mat3x3_1[0][0] = Mat3x3_2[0][1] = Mat3x3_3[0][2] = x;
Mat3x3_1[1][0] = Mat3x3_2[1][1] = Mat3x3_3[1][2] = y;
Mat3x3_1[2][0] = Mat3x3_2[2][1] = Mat3x3_3[2][2] = z;
offX = Det3x3(Mat3x3_1) / offZ;
offY = Det3x3(Mat3x3_2) / offZ;
offZ = Det3x3(Mat3x3_3) / offZ;
}
#else // Gaussian elimination
new
Float: pX = Mat4x3[mp_PITCH][mi_X],
Float: pY = Mat4x3[mp_PITCH][mi_Y],
Float: pZ = Mat4x3[mp_PITCH][mi_Z],
Float: rX = Mat4x3[mp_ROLL][mi_X],
Float: rY = Mat4x3[mp_ROLL][mi_Y],
Float: rZ = Mat4x3[mp_ROLL][mi_Z],
Float: yX = Mat4x3[mp_YAW][mi_X],
Float: yY = Mat4x3[mp_YAW][mi_Y],
Float: yZ = Mat4x3[mp_YAW][mi_Z]
;
offZ = ((z * pX - pZ * x) * rX - (rZ * pX - pZ * rX) * x) / ((yZ * pX - pZ * yX) * rX - (rZ * pX - pZ * rX) * yX);
offY = (y * pX - pY * x - offZ * (yY * pX - pY * yX)) / (rY * pX - pY * rX);
offX = (x - offZ * yX - offY * rX) / pX;
#endif
}
It could be possible that I made a mistake with Gauss but I doubt it because it works fine on normal roads