[Include] Quaternion Converter - Convert GetVehicleRotationQuat angles to XYZ [1.0.0|13/08/10]
#1

NOTE: This release requires SA-MP 0.3b, (minimum RC1) currently in Release Candidate testing.

Quaternion Converter
Convert GetVehicleRotationQuat angles to XYZ!
What is it?
Quaternion Converter is a simple include which provides functions to convert a quaternion set (most commonly used in GetVehicleRotationQuat) to XYZ. (yaw, pitch and roll)

How do I use it?
Copy the include to your includes directory.
Include the "quaternion.inc" file in any scripts which you would like to use these functions in. (with "#include <quaternion>")

What am I allowed to do with it?
Quaternion Converter is licensed under the GNU General Public License. Please see COPYING in the download package, or http://www.gnu.org/licenses/gpl.html.

Where can I download it?
http://www.megaupload.com/?d=BGXYITTT (1.0.0 @ 13/08/10)
Please abide by the terms of the license!


Function list
Код:
stock QuaternionToYawPitchRoll(Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z,&Float:x,&Float:y,&Float:z)
Takes the quaternion values specified by quat_w, quat_x, quat_y and quat_z, then converts them into roll, pitch and yaw (respectively) and saves them into the variables specified by x, y and z.

Код:
stock QuaternionGetRoll(Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z,&Float:roll)
Takes the quaternion values specified by quat_w, quat_x, quat_y and quat_z, then converts them into roll (respectively) and saves them into the variables specified by roll.

Код:
stock QuaternionGetPitch(Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z,&Float:pitch)
Takes the quaternion values specified by quat_w, quat_x, quat_y and quat_z, then converts them into pitch and saves them into the variables specified by pitch.

Код:
stock QuaternionGetYaw(Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z,&Float:yaw)
Takes the quaternion values specified by quat_w, quat_x, quat_y and quat_z, then converts them into yaw and saves them into the variable specified by yaw.
Reply
#2

must live simply!!!
PHP код:
stock GetVehicleRotation(vehicleid,&Float:x,&Float:y,&Float:z) {
    new 
Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z;
    
GetVehicleRotationQuat(vehicleid,quat_w,quat_x,quat_y,quat_z);
    
atan2(2*((quat_x*quat_y)+(quat_w+quat_z)),(quat_w*quat_w)+(quat_x*quat_x)-(quat_y*quat_y)-(quat_z*quat_z));
    
atan2(2*((quat_y*quat_z)+(quat_w*quat_x)),(quat_w*quat_w)-(quat_x*quat_x)-(quat_y*quat_y)+(quat_z*quat_z));
    
asin(-2*((quat_x*quat_z)+(quat_w*quat_y)));
    return 
1;

Reply
#3

pawn Код:
stock ConvertNonNormaQuatToEuler(Float: qw, Float: qx, Float:qy, Float:qz,
                                &Float:heading, &Float:attitude, &Float:bank)
{
    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
    //если normalised, - один, в противном случае - показатель коррекции
    new Float: test = qx*qy + qz*qw;
    if (test > 0.499*unit)
    { // singularity at north pole - особенность на северном полюсе
        heading = 2*atan2(qx,qw);
        attitude = 3.141592653/2;
        bank = 0;
        return 1;
    }
    if (test < -0.499*unit)
    { // singularity at south pole - особенность на южном полюсе
        heading = -2*atan2(qx,qw);
        attitude = -3.141592653/2;
        bank = 0;
        return 1;
    }
    heading = atan2(2*qy*qw - 2*qx*qz, sqx - sqy - sqz + sqw);
    attitude = asin(2*test/unit);
    bank = atan2(2*qx*qw - 2*qy*qz, -sqx + sqy - sqz + sqw);
    return 1;
}
pawn Код:
stock GetVehicleRotation(vehicleid,&Float:heading, &Float:attitude, &Float:bank)
{
    new Float:quat_w,Float:quat_x,Float:quat_y,Float:quat_z;
    GetVehicleRotationQuat(vehicleid,quat_w,quat_x,quat_y,quat_z);
    ConvertNonNormaQuatToEuler(quat_w,quat_x,quat_z,quat_y, heading, attitude, bank);
    bank = -1*bank;
    return 1;
}
Reply
#4

Good Job!
Reply
#5

Your code, DANGER1979 works really nice with SA-MP objects. = )
Reply
#6

i believe, heres a multiplication needed instead of addidion: (quat_w+quat_z)
Код:
x = atan2(2*((quat_x*quat_y)+(quat_w*quat_z)),(quat_w*quat_w)+(quat_x*quat_x)-(quat_y*quat_y)-(quat_z*quat_z));
Reply
#7

can u add something for this?
https://sampforum.blast.hk/showthread.php?tid=292795

anyway, megaupload is down

edit: requesting answer
Reply
#8

Sorry for my ignorance, but what can I do with this?
Reply
#9

Find out the angles (X+Y) of a vehicle.
Reply
#10

can anyone post the code here since megaupload is down?
Reply
#11

09/12/2010

...
Reply
#12

Quote:
09/12/2010

...

what's the matter?
does anyone have that or a similar code then post it here please.
should just contain the functions from the original include and be working

thank you very much
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)