Conversation
…into lcf-hmm2.0
By default if user is overriding trig functions assume their input and internal units are the same.
https://discord.com/channels/239737791225790464/489148972305350656/1055167647274246265 Justified by most implementations of Slerp. EX: http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/
Generics enable by default when available (see lines 97-104). User can also force them by defining HANDMADE_MATH_C11_GENERICS Also fixed some missed things w.r.t renaming. My old tool didn't catch cases like HMM_MultiplyVec3f needing to be HMM_MulV3F instead of HMM_MulV3f.
Also improved quaternion tests. More work could be done here, see discussion here about optimizing slerp: https://discord.com/channels/239737791225790464/489148972305350656/1055167647274246265
Also renamed Transpose to TransposeM4, so that we can have TransposeM2,M3
As can be seen from the tests, precision has declined quite a bit from using the FastNorm implementations for various things. We can only guarantee about 0.001f precision for anything where a norm happens now. If this is undesired we can change back easily.
TODO: Tests for simple 4x4 Inverses
This will make HMM more convenient to use with other graphics APIs such as Direct3d and Metal.
|
Per offline feedback from Ben I've added some commits so that test coverage for the additions is comprehensive. Additionally I've added a configuration option so that projection matrices can use a Z range of [0, 1] for NDCs, this will be helpful for supporting graphics APIs other than OpenGL (DirectX and Metal use this convention that I know of). |
bvisness
left a comment
There was a problem hiding this comment.
Looks great overall. I have a few suggested changes but nothing major. I'll test out the renaming script on my Mac and report back with how that goes.
Thanks for all your work on this!
HandmadeMath.h
Outdated
| HMM_Vec2 Result; | ||
| float* Column = Elements[Index]; | ||
|
|
||
| Result.Elements[0] = Column[0]; | ||
| Result.Elements[1] = Column[1]; | ||
|
|
||
| return (Result); |
There was a problem hiding this comment.
Can we not just do return Elements[Index];...? Is there something I'm missing?
dev-dwarf
left a comment
There was a problem hiding this comment.
Hi Ben, please see my comments and let me know if additional changes are required.
| Result.Columns[0] = HMM_V4V(HMM_AddV3(HMM_Cross(Matrix.Columns[1].XYZ, B32), HMM_MulV3F(C23, Matrix.Columns[1].W)), -HMM_DotV3(Matrix.Columns[1].XYZ, C23)); | ||
| Result.Columns[1] = HMM_V4V(HMM_SubV3(HMM_Cross(B32, Matrix.Columns[0].XYZ), HMM_MulV3F(C23, Matrix.Columns[0].W)), +HMM_DotV3(Matrix.Columns[0].XYZ, C23)); | ||
| Result.Columns[2] = HMM_V4V(HMM_AddV3(HMM_Cross(Matrix.Columns[3].XYZ, B10), HMM_MulV3F(C01, Matrix.Columns[3].W)), -HMM_DotV3(Matrix.Columns[3].XYZ, C01)); | ||
| Result.Columns[3] = HMM_V4V(HMM_SubV3(HMM_Cross(B10, Matrix.Columns[2].XYZ), HMM_MulV3F(C01, Matrix.Columns[2].W)), +HMM_DotV3(Matrix.Columns[2].XYZ, C01)); |
There was a problem hiding this comment.
Agreed. I hope the name InvGeneral for these functions (rather than just Inv) helps to imply that they are not the best option for most cases.
bvisness
left a comment
There was a problem hiding this comment.
This all looks great. I'm good to merge, but I want to gather feedback from a couple more people first. Will be resolving this in the near future. Thanks again @dev-dwarf!
|
Just took a look through this, and everything looks great. Thanks so much for doing this!!! |
I was hired by @bvisness to work on the list of changes for HMM2.0. The tracking issue for all of the changes is: #147.
Changes
Here are the changes I made:
HMM_USE_DEGREE_INPUTorHMM_USE_TURN_INPUT. There are macros,HMM_AngleRad,HMM_AngleDeg, andHMM_AngleTurnthat will convert an angle to the input representation, such as passing an FOV in degrees:HMM_Perspective_RH(HMM_AngleDeg(120), ... other args ...). There are also functions to convert angles in the input representation to any of the other units,HMM_ToRad,HMM_ToDeg,HMM_ToTurn.HMM_PROVIDE_MATH_FUNCTIONS, removed individual checks for each math function being defined. Users now define this and all of theHMM_SINFand other trig functions, or accept the default crt implementations. Theatanfandatan2ffunctions were unused and have been removed. If users override the functions, they can also use a different unit for the angles in their functions by defining both ofHMM_ANGLE_USER_TO_INTERNALandHMM_ANGLE_INTERNAL_TO_USER.HMM_PREFIXmacro has been removed. Everything now uses an uppercase HMM_ prefix, so it should be easy to find+replace on your local copy.HMM_LinearCombineSSEis nowHMM_LinearCombineV4M4. It will use the SSE code when available but fallback to a slower implementation. This reduces the amount of special cases needed for various Mat4 functions, which previously usedHMM_LinearCombineSSEwhen available and then each had their own implementation.Update Tool
I also created a tool that can be used to update user's code to 2.0 automatically, which you can find in a separate repository here: https://github.com/dev-dwarf/HMM2.0UpdateTool. The tool I created does the following:
The tool is written in one .c file that compiles as C or C++, so any of our users should be able to compile it easily. The tool takes one or more filenames as arguments and updates their contents to 2.0. There are also .bat and .sh scripts to recursively run the tool on all the c/h/cpp/hpp files in a directory. The tool changes the files it touches so it should be used with source control. I can provide compiled executables for windows and linux, but someone else would have to handle mac.
Please take a look and let me know anything that needs changes. Sorry for the huge PR, didn't know a good way to split things up. Happy to answer any questions or make additional changes. Thanks for the opportunity!