Rismosch / ris_engine

Barebones game engine. Home made passion project.
MIT License
2 stars 1 forks source link

world rotation does not preserve quaternion sign #121

Closed Rismosch closed 2 months ago

Rismosch commented 2 months ago

as the title says. for every rotation exist there exist exactly 2 quaternions. +q and -q, where each component is negated.

this causes problems when attempting to change the world rotation via the inspector. due to world space calculations, the original sign is lost, causing the inspector to be the negative of the actual stored quaternion. the rotation is correct, but due to the flipped sign the inspector is out of sync with the quaternion, causing spastic glitches and making some rotations unreachable.

https://github.com/user-attachments/assets/70b32431-9e88-4661-81e9-258851daabd8

here are some logs from the vid. they log the rotation before and after applying the world rotation.

[15:26:14] Trace: hi Quat(0.12700002, 0.49055922, -0.02747122, -0.86166584) Quat(-0.12700002, -0.49055925, 0.027471205, 0.8616658)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(-0.11, 0.4915626, -0.027527409, -0.8634283) Quat(0.10999999, -0.49156258, 0.0275274, 0.86342835)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(0.11900001, 0.4910496, -0.027498681, -0.8625272) Quat(-0.11900002, -0.4910496, 0.027498674, 0.8625272)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(-0.11200001, 0.49145216, -0.027521225, -0.8632343) Quat(0.11200002, -0.49145216, 0.02752123, 0.8632342)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(0.117000006, 0.49116716, -0.027505264, -0.86273366) Quat(-0.11700003, -0.4911672, 0.027505267, 0.8627336)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(-0.113000005, 0.49139616, -0.02751809, -0.86313593) Quat(0.113000035, -0.49139625, 0.027518095, 0.8631358)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(0.11500001, 0.49128264, -0.027511733, -0.86293656) Quat(-0.11500004, -0.49128267, 0.027511744, 0.8629365)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(-0.11200001, 0.49145216, -0.027521225, -0.8632343) Quat(0.11200002, -0.49145216, 0.02752123, 0.8632342)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(0.113000005, 0.49139616, -0.02751809, -0.86313593) Quat(-0.11300002, -0.49139613, 0.02751809, 0.8631359)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

[15:26:14] Trace: hi Quat(-0.111, 0.49150762, -0.027524332, -0.86333174) Quat(0.111, -0.4915076, 0.027524337, 0.86333174)
    in ris_core at crates\ris_core\src\ui_helper\modules\inspector.rs:228

they illustrate the issue well. the sign is flipped after assigning. but imgui keeps the same sign. this flips every frame a value is changed.