14.05.2016, 03:26
Код:
enum MatrixParts
{
mp_PITCH,
mp_ROLL,
mp_YAW,
mp_POS
};
enum MatrixIndicator
{
Float:mi_X,
Float:mi_Y,
Float:mi_Z
};
stock GetVehicleMatrix(vehicleid,Mat4x3[MatrixParts][MatrixIndicator])
{
//initial processing step - gathering information
new
Float:x,
Float:y,
Float:z,
Float:w,
Float:Pos[3];
GetVehicleRotationQuat(vehicleid,w,x,y,z);
GetVehiclePos(vehicleid,Pos[0],Pos[1],Pos[2]);
new
Float:x2 = x * x,
Float:y2 = y * y,
Float:z2 = z * z,
Float:xy = x * y,
Float:xz = x * z,
Float:yz = y * z,
Float:wx = w * x,
Float:wy = w * y,
Float:wz = w * z;
Mat4x3[mp_PITCH][mi_X] = 1.0 - 2.0 * (y2 + z2);
Mat4x3[mp_PITCH][mi_Y] = 2.0 * (xy - wz);
Mat4x3[mp_PITCH][mi_Z] = 2.0 * (xz + wy);
Mat4x3[mp_ROLL][mi_X] = 2.0 * (xy + wz);
Mat4x3[mp_ROLL][mi_Y] = 1.0 - 2.0 * (x2 + z2);
Mat4x3[mp_ROLL][mi_Z] = 2.0 * (yz - wx);
Mat4x3[mp_YAW][mi_X] = 2.0 * (xz - wy);
Mat4x3[mp_YAW][mi_Y] = 2.0 * (yz + wx);
Mat4x3[mp_YAW][mi_Z] = 1.0 - 2.0 * (x2 + y2);
Mat4x3[mp_POS][mi_X] = Pos[0];
Mat4x3[mp_POS][mi_Y] = Pos[1];
Mat4x3[mp_POS][mi_Z] = Pos[2];
return 1;
}
stock PositionFromVehicleOffset(vehicle,Float:offX,Float:offY,Float:offZ,&Float:x,&Float:y,&Float:z)
{
new Mat4x3[MatrixParts][MatrixIndicator];
GetVehicleMatrix(vehicle,Mat4x3);
x = offX * Mat4x3[mp_PITCH][mi_X] + offY * Mat4x3[mp_ROLL][mi_X] + offZ * Mat4x3[mp_YAW][mi_X] + Mat4x3[mp_POS][mi_X];
y = offX * Mat4x3[mp_PITCH][mi_Y] + offY * Mat4x3[mp_ROLL][mi_Y] + offZ * Mat4x3[mp_YAW][mi_Y] + Mat4x3[mp_POS][mi_Y];
z = offX * Mat4x3[mp_PITCH][mi_Z] + offY * Mat4x3[mp_ROLL][mi_Z] + offZ * Mat4x3[mp_YAW][mi_Z] + Mat4x3[mp_POS][mi_Z];
return 1;
}
Код:
PositionFromVehicleOffset(vehid,0.0, 0.0, 2.0,x, y, z); CreateObject(343, x, y, z, 0.0, 0.0, 0.0); // creates a point at a height of 2 meters from the car no matter how it is tilted

