Re: [Mingw-w64-public] [PATCH] headers: Implement quaternion functions in windowsnumerics.h
On Wed, 23 Nov 2022, Alvin Wong wrote: On 22/11/2022 20:07, Martin Storsjö wrote: + inline bool decompose(const float4x4 , float3 *out_scale, quaternion *out_rot, float3 *out_translate) { +float4x4 val = mat; +if (out_translate) + *out_translate = translation(val); +val.m41 = val.m42 = val.m43 = 0.0f; +float3 scale = float3( + length(float3(val.m11, val.m12, val.m13)), + length(float3(val.m21, val.m22, val.m23)), + length(float3(val.m31, val.m32, val.m33)) +); +if (out_scale) + *out_scale = scale; +val = make_float4x4_scale(float3(1.0f/scale.x, 1.0f/scale.y, 1.0f/scale.z)) * val; +if (out_rot) + *out_rot = make_quaternion_from_rotation_matrix(val); +return true; + } I feel that there should be some conditions that cause this function to return false, if the input is not a scale/rotate/translate matrix... Yeah - and when creating the testcase for this, I struck such cases a lot until I managed to create the right for of test input which the reference API accepted. I guess I can try to add more verification of some aspects here - I guess that would primarily be to verify that the length of any of the basis vectors isn't zero, and that the rotation part of the matrix really is orthogonal. // Martin ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] headers: Implement quaternion functions in windowsnumerics.h
On 22/11/2022 20:07, Martin Storsjö wrote: + inline bool decompose(const float4x4 , float3 *out_scale, quaternion *out_rot, float3 *out_translate) { +float4x4 val = mat; +if (out_translate) + *out_translate = translation(val); +val.m41 = val.m42 = val.m43 = 0.0f; +float3 scale = float3( + length(float3(val.m11, val.m12, val.m13)), + length(float3(val.m21, val.m22, val.m23)), + length(float3(val.m31, val.m32, val.m33)) +); +if (out_scale) + *out_scale = scale; +val = make_float4x4_scale(float3(1.0f/scale.x, 1.0f/scale.y, 1.0f/scale.z)) * val; +if (out_rot) + *out_rot = make_quaternion_from_rotation_matrix(val); +return true; + } I feel that there should be some conditions that cause this function to return false, if the input is not a scale/rotate/translate matrix... ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] headers: Implement quaternion functions in windowsnumerics.h
在 2022-11-22 20:07, Martin Storsjö 写道: Also implement a couple make_float4x4_* functions that are useful for constructing input for some tests. This reduces the number of unimplemented functions in this header a little bit. Signed-off-by: Martin Storsjö --- For some tests, this doesn't use literal hardcoded inputs, but composes the test inputs via other utility functions. Some implemented functions, such as the quaternion transform() functions, only match the WinSDK implementation for normalized quaternions (which practically is the only reasonable usecase anyway); the WinSDK implementation assumes normalized quaternions. --- .../include/windowsnumerics.impl.h| 179 -- .../testcases/test_windowsnumerics.cpp| 113 ++- 2 files changed, 271 insertions(+), 21 deletions(-) I have very little knowledge about this, but anyway, it might be good to check these functions in and see how people respond. -- Best regards, LIU Hao OpenPGP_signature Description: OpenPGP digital signature ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public