Total chaos in Euler Rotation convention (closed)

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Total chaos in Euler Rotation convention (closed)

Post by devsh »

There is a total convention chaos, sometimes the arguments are called pitch-yaw-roll sometimes pitch-roll-yaw etc.

Please clean this up, and say rotationAboutX, rotationAboutY, rotationAboutZ and clarify all rotations are anti-clockwise around the axis and XYZ is a right-handed system with rotation around the z axis occuring first, y second and x third



All below is untrue and irrelevant to Irrlicht 1.8.4 (my bad, my bug)

I fixed the set() function which has been shrouded by _IRR_TEST_BROKEN_QUATERION_USE_

Code: Select all

 
// sets new quaternion based on euler angles
inline quaternion& quaternion::set(const float& roll, const float& pitch, const float& yaw)
{
    f64 angle;
 
    angle = roll * 0.5;
    const f64 sr = sin(angle);
    const f64 cr = cos(angle);
 
    angle = pitch * 0.5;
    const f64 sp = sin(angle);
    const f64 cp = cos(angle);
 
    angle = yaw * 0.5;
    const f64 sy = sin(angle);
    const f64 cy = cos(angle);
 
    const f64 cpcy = cp * cy;
    const f64 spcy = sp * cy;
    const f64 cpsy = cp * sy;
    const f64 spsy = sp * sy;
 
    *reinterpret_cast<vectorSIMDf*>(this) = vectorSIMDf(sr,cr,cr,cr)*vectorSIMDf(cpcy,spcy,cpsy,cpcy)+vectorSIMDf(-cr,sr,-sr,sr)*vectorSIMDf(spsy,cpsy,spcy,spsy);
 
    return *this;
}
 
P.S. Personally I will remove all mention of P-Y-R and euler angles and require quaternion use throughout, and the only way to set euler angles will be just in the quaternion constructor!
Last edited by devsh on Tue Feb 28, 2017 12:47 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Broken Quaternion From Euler (and total chaos in convent

Post by CuteAlien »

Maybe I'm just too tired.. but I don't see Irrlicht using roll/pitch/yaw anywhere in quaternions. Is this maybe one of your own changes you did for your version?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Broken Quaternion From Euler (and total chaos in convent

Post by devsh »

yeah you're right its my own function, its because I made it from the 3x3 matrix conversion functions above it
and the conversion to 4x4 matrix and back is definitely broken (as the flag indicates)

your fromEuler function is correct

Code: Select all

inline quaternion& quaternion::set(f32 x, f32 y, f32 z)
{
    f64 angle;
 
    angle = x * 0.5;
    const f64 sr = sin(angle);
    const f64 cr = cos(angle);
 
    angle = y * 0.5;
    const f64 sp = sin(angle);
    const f64 cp = cos(angle);
 
    angle = z * 0.5;
    const f64 sy = sin(angle);
    const f64 cy = cos(angle);
 
    const f64 cpcy = cp * cy;
    const f64 spcy = sp * cy;
    const f64 cpsy = cp * sy;
    const f64 spsy = sp * sy;
 
    X = (f32)(sr * cpcy - cr * spsy);
    Y = (f32)(cr * spcy + sr * cpsy);
    Z = (f32)(cr * cpsy - sr * spcy);
    W = (f32)(cr * cpcy + sr * spsy);
 
    return normalize();
}
 
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Total chaos in Euler Rotation convention (closed)

Post by Mel »

Quaternion to XYZ Euler... BRRR! i just get goosebumps remembering when i tried to get something straight out of it from the internet... Looks like everybody deliberately avoids the XYZ Euler rotation order! D:
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Total chaos in Euler Rotation convention (closed)

Post by devsh »

Its because there are at least 6 different conventions you could use regarding the order in which the rotations about the axes get applied, a quaternion removes this ambiguity by specifying a single rotation axis and requiring the rotation to be anti-clockwise
Post Reply