10.04.2009, 02:28
QuatToEuler(Float:qx, Float:qy, Float:qz, Float:qw, &Float:ex, &Float:ey, &Float:ez, bool:normalize = false)
To convert from GTA quaternions to SAMP angles
To convert from GTA quaternions to SAMP angles
pawn Код:
#define q2e(%0) QuatToEuler(%0)
QuatToEuler(Float:qx, Float:qy, Float:qz, Float:qw, &Float:ex, &Float:ey, &Float:ez, bool:normalize = false)
{
new
Float:sqx = qx * qx,
Float:sqy = qy * qy,
Float:sqz = qz * qz,
Float:sqw = qw * qw
;
ex = atan2(-sqy - sqx + sqz + sqw, 2.0 * (qy * qz + qx * qw)) - 90.0;
ey = asin(-2.0 * (qx * qz - qy * qw));
ez = atan2(sqy - sqx - sqz + sqw, 2.0 * (qx * qy + qz * qw)) - 90.0;
if (normalize)
{
if (ex < 0.0) ex += 360.0;
if (ey < 0.0) ey += 360.0;
if (ez < 0.0) ez += 360.0;
if (ex == 360.0) ex = 0.0;
if (ey == 360.0) ey = 0.0;
if (ez == 360.0) ez = 0.0;
}
}