Raised This Month: $51 Target: $400
 12% 

converting euler angles to axis


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cakabow
New Member
Join Date: Oct 2021
Old 10-24-2021 , 07:00   converting euler angles to axis
Reply With Quote #1

Hi,

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
192.168.l.l routerlogin 192.168.0.1
my fork code:

the call comes from ConvertEulerToAxisAngle(angles);

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(x * x + y * y + z * 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)

Thanks in advance.

Last edited by cakabow; 11-12-2021 at 17:29.
cakabow is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-25-2021 , 07:19   Re: converting euler angles to axis
Reply With Quote #2

You don't have to do it manually.

https://forums.alliedmods.net/showthread.php?t=331814
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:59.


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