AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   converting euler angles to axis (https://forums.alliedmods.net/showthread.php?t=331814)

Gold Fish 04-08-2021 15:42

converting euler angles to axis
 
Hello everyone, I started working with angles in L4D2, (Read information about corners here )

found out that all angles are stored in memory as Euler angles, I decided to try to convert them, for the convenience of working with them


found a repository on github with mathematical functions for converting a coordinate system in the pawn language, tried to transfer them to sourcepawn, but it seems that something is not working correctly

my fork code:

the call comes from ConvertEulerToAxisAngle(angles);
PHP Code:


float AxisAngle
[4];
float tmpAngle[4];

enum E_EULER {
    
E_EULER_ALPHA,
    
E_EULER_BETA,
    
E_EULER_GAMMA
}

enum E_QUAT {
    
E_QUAT_W,
    
E_QUAT_X,
    
E_QUAT_Y,
    
E_QUAT_Z
}

enum E_AANGLE {
    
E_AANGLE_ANGLE,
    
E_AANGLE_X,
    
E_AANGLE_Y,
    
E_AANGLE_Z
}

void ConvertEulerToAxisAngle(float euler[E_EULER]) {

    
ConvertEulerToQuat(euler);
    
ConvertQuatToAxisAngle();
}

void ConvertQuatToAxisAngle() {

    
//float size = VectorSize(quat[E_QUAT_X], quat[E_QUAT_Y], quat[E_QUAT_Z]); // w = floatsqroot(1.0 - w * w); // w = floatsin(angle, degrees); // |sin(angle)|
    
float x tmpAngle[E_QUAT_X];
    
float y tmpAngle[E_QUAT_Y];
    
float z tmpAngle[E_QUAT_Z];
    
float size SquareRoot(z);
    
//PrintToChatAll("size %f",size);
    
    
if(size == 0.0) { // no rotation
        
tmpAngle[E_AANGLE_ANGLE] =
        
tmpAngle[E_AANGLE_X] =
        
tmpAngle[E_AANGLE_Y] = 0.0;
        
tmpAngle[E_AANGLE_Z] = 1.0;
    } else {
        
AxisAngle[E_AANGLE_ANGLE] = 2.0 ArcCosine(-tmpAngle[E_QUAT_W]);
        
AxisAngle[E_AANGLE_X] = tmpAngle[E_QUAT_X] / size;
        
AxisAngle[E_AANGLE_Y] = tmpAngle[E_QUAT_Y] / size;
        
AxisAngle[E_AANGLE_Z] = tmpAngle[E_QUAT_Z] / size;
        
//PrintToChatAll("AXIS %f %f %f %f",tmpAngle[0],tmpAngle[1],tmpAngle[2],tmpAngle[3]);
    
}
}



void ConvertEulerToQuat(float euler[E_EULER]) {

    
float a euler[E_EULER_ALPHA] * 0.5;
    
float b euler[E_EULER_BETA]  * 0.5;
    
float g euler[E_EULER_GAMMA] * 0.5;



    
float cosA RadToDeg(Cosine(a));
    
float cosB RadToDeg(Cosine(b));
    
float cosG RadToDeg(Cosine(g));
    
float sinA RadToDeg(Sine(a));
    
float sinB RadToDeg(Sine(b));
    
float sinG RadToDeg(Sine(g));
    
PrintToChatAll("%f %f %f",cosA,cosB,cosG);
    
PrintToChatAll("%f %f %f",sinA,sinB,sinG);
    
    
// type_euler_zxy, // yaw pitch roll 
/*
    float E_QUAT_W,
    float E_QUAT_X,
    float E_QUAT_Y,
    float E_QUAT_Z
    */
    
    
tmpAngle[0] = sinB sinG sinA cosB cosG cosA;  //-134*666,900516575
    
tmpAngle[1] = sinB cosG cosA cosB sinG sinA;
    
tmpAngle[2] = cosB sinG cosA sinB cosG sinA;
    
tmpAngle[3] = cosB cosG sinA sinB sinG cosA;
    
//PrintToChatAll("QUAT %f %f %f %f",tmpAngle[0],tmpAngle[1],tmpAngle[2],tmpAngle[3]);


maybe you find an error :)



in general, I would like to just have angles along the X Y and Z axis, maybe there are better ways to envelope angles)

asherkin 04-12-2021 11:01

Re: converting euler angles to axis
 
It looks like you're looking for the fwd output of GetAngleVectors.


All times are GMT -4. The time now is 04:20.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.