SetObjectMaterialText & AttachObjectToVehicle
#1

Hello!

I have two 'problems', the first one is I use this/these function(s) to get vehicle offset after I edited an object;
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])
    ;
}

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 works sometimes but most of the time after my code has passed this line;
pawn Код:
OffsetFromVehiclePosition(vehicleid, fX, fY, fZ, vText[vehicleid][slot][tX], vText[vehicleid][slot][tY], vText[vehicleid][slot][tZ]);
'tX' and 'tY' are 0.00000 and 'tZ' is NaN (If I use printf to check their values), what it also does is if I try to edit the object then the cursor appears and the object/text (As I use a transparent background) appears in the left upper corner of my screen but if I press space to change my camera angle (So I should be able to edit the object) it's like the object/text is attached to my screen because it'll just move with my camera.

The second thing I have is a lot more simple I guess but I noticed when I used AttachObjectToVehicle when the above didn't happen (So you'd say the code would work fine then) the offset is a little off, if I would put the text right on the roof and press save, it would get attached/float 2/3mm above the roof, what it also does, at least with white text, is that when it gets attached the text gets whiter (Too white, like there are two objects over each other while there aren't.). If anyone knows wether the color change is normal and how to fix the offset any help would be appreciated but the first problem I have is much more important!

Best regards,
Jesse
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)