11.10.2010, 03:43
Код:
GetPlayerVehicleAngle(playerid, &Float:x, &Float:y, &Float:z); QuatToEulers(Float:qw, Float:qx, Float:qy, Float:qz, &Float:rX, &Float:rY, &Float: rZ);
pawn Код:
stock GetPlayerVehicleAngle(playerid, &Float:x, &Float:y, &Float:z)
{
if(IsPlayerInAnyVehicle(playerid))
{
new
Float:qw,
Float:qx,
Float:qy,
Float:qz;
GetVehicleRotationQuat(GetPlayerVehicleID(playerid), qw, qx, qy, qz);
QuatToEulers(qw, qx, qy, qz, x, y, z);
return 1;
}
else return 0;
}
stock QuatToEulers(Float:qw, Float:qx, Float:qy, Float:qz, &Float:rX, &Float:rY, &Float: rZ)
{
/**Can be non-normalised/normalised Quaternion will return Eulers Angle*/
new Float:sqw = qw*qw;
new Float:sqx = qx*qx;
new Float:sqy = qy*qy;
new Float:sqz = qz*qz;
new Float:unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
new Float:test = qx*qy + qz*qw;
//Check for Gimbal Lock
if (test > 0.499*unit) { // singularity at north pole
rX = 2 * atan2(qx,qw);
rZ = 3.1415926535/2;
rY = 0;
while(rX < 0.0) rX += 360.0; while(rX > 360.0) rX -= 360.0;
while(rZ < 0.0) rZ += 360.0; while(rZ > 360.0) rZ -= 360.0;
return 1;
}
if (test < -0.499*unit) { // singularity at south pole
rX = -2 * atan2(qx,qw);
rZ = -3.1415926535/2;
rY = 0;
while(rX < 0.0) rX += 360.0; while(rX > 360.0) rX -= 360.0;
while(rZ < 0.0) rZ += 360.0; while(rZ > 360.0) rZ -= 360.0;
return 1;
}
//No Gimbal Lock
rX = atan2(2*qy*qw-2*qx*qz , sqx - sqy - sqz + sqw);
rZ = asin(2*test/unit);
rY = atan2(2*(qx*qw-2)*(qy*qz) , -sqx + sqy - sqz + sqw);
while(rX < 0.0) rX += 360.0; while(rX > 360.0) rX -= 360.0;
while(rY < 0.0) rY += 360.0; while(rY > 360.0) rY -= 360.0;
while(rZ < 0.0) rZ += 360.0; while(rZ > 360.0) rZ -= 360.0;
return 1;
}