Quaternion values and 2.x: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Added a warning notice about how Blizzard stores its quaternion numbers.) |
||
Line 1: | Line 1: | ||
In WoW 2.0+ Blizzard are now storing rotation data in 16bit values instead of 32bit. I don't really understand why as its only a very minor saving in model sizes and adds extra overhead in processing the models. Need this structure to read the data into. | In WoW 2.0+ Blizzard are now storing rotation data in 16bit values instead of 32bit. I don't really understand why as its only a very minor saving in model sizes and adds extra overhead in processing the models. Need this structure to read the data into. | ||
The conversion is done with these two functions: | The conversion is done with these two functions: | ||
Line 28: | Line 28: | ||
float(t.w < 0? t.w + 32768 : t.w - 32767)/ 32767.0f); | float(t.w < 0? t.w + 32768 : t.w - 32767)/ 32767.0f); | ||
} | } | ||
--[[User:Schlumpf|schlumpf_]] 03:58, 19 August 2008 (CEST) and partly from WoWModelViewer's source. | --[[User:Schlumpf|schlumpf_]] 03:58, 19 August 2008 (CEST) and partly from WoWModelViewer's source. | ||
--Koward 08:07, 26 November 2015 (UTC) Please notice that unlike the standard mathematical notations, the scalar part (w) is AFTER the vector part (x,y,z) in the Blizzard structures. | |||
Most well-known math libraries uses the standard (w, x, y, z) so be careful and switch properly. | |||
[[Category:Auxiliary]] | [[Category:Auxiliary]] |
Revision as of 10:09, 26 November 2015
In WoW 2.0+ Blizzard are now storing rotation data in 16bit values instead of 32bit. I don't really understand why as its only a very minor saving in model sizes and adds extra overhead in processing the models. Need this structure to read the data into.
The conversion is done with these two functions:
inline float stf(short Short) { return (Short / float (MAX_SHORT)) - 1.0f; // (Short > 0 ? Short-32767 : Short+32767)/32767.0; }
inline short fts(float Float) { return (Float + 1.0f) * float (MAX_SHORT); // (short)(Float > 0 ? Float * 32767.0 - 32768 : Float * 32767.0 + 32768); }
Doing it for a whole Quaternion is like this:
struct Quat16 { __int16 x,y,z,w; }; struct Quat32 { float x,y,z,w; }; static const Quat32 Quat16ToQuat32(const Quat16 t) { return Quaternion( float(t.x < 0? t.x + 32768 : t.x - 32767)/ 32767.0f, float(t.y < 0? t.y + 32768 : t.y - 32767)/ 32767.0f, float(t.z < 0? t.z + 32768 : t.z - 32767)/ 32767.0f, float(t.w < 0? t.w + 32768 : t.w - 32767)/ 32767.0f); }
--schlumpf_ 03:58, 19 August 2008 (CEST) and partly from WoWModelViewer's source.
--Koward 08:07, 26 November 2015 (UTC) Please notice that unlike the standard mathematical notations, the scalar part (w) is AFTER the vector part (x,y,z) in the Blizzard structures. Most well-known math libraries uses the standard (w, x, y, z) so be careful and switch properly.