devkitPro / citro3d

Homebrew PICA200 GPU wrapper library for Nintendo 3DS
zlib License
244 stars 34 forks source link

Optimized Matrix Inverse Function #14

Closed tommai78101 closed 8 years ago

tommai78101 commented 8 years ago

This is a helper function to calculate the inverse of the matrix. The argument passed in is a pointer that points to a matrix. Used Mtx_Identity(C3D_Mtx* out) as a reference point for code format.

Returns 0 if Successful. Returns -1 if Failed. (Matrix is singular/degenerate, or Determinant is 0)

I believed this approach is the most direct method for checking the results.

Used for:

Camera View Matrix Unprojection (Raycasting, Raytracing, voxel-based projection, etc.) Object model matrix manipulation (Perspective Illusion, picking up 3D objects and moving camera around, etc.) Checks if Matrix is singular/degenerate. Other matrix manipulations. make results: Compiles successfully. libcitro3d.a is generated.

-wedr: Suggested by mtheall to add this into Citro3D. -Cruel`: Tabs/Spaces are misaligning the code. This is somewhat fixed. I did my best.

fincs commented 8 years ago

Thank you for your contribution, it will be merged. However it would be good if the indentation were completely fixed. Tabs should only be used for indentation and not alignment. For example: (<--> = tab, .... = spaces):

<-->inv[8] = out->m[4] * out->m[9]  * out->m[15] -
<-->.........out->m[4] * out->m[11] * out->m[13] -

And yes, I am aware that this mixes tabs and spaces at the beginning of the line. I do not believe in the arbitrary/cargo-cult rule that disallows it because it otherwise makes it impossible to correctly format the code above. Alternatively, this style is also acceptable:

<-->inv[8] =
<--><-->out->m[4] * out->m[9]  * out->m[15] -
<--><-->out->m[4] * out->m[11] * out->m[13] -

In addition, lines should never have trailing whitespace, nor should them be composed solely of whitespace.

tommai78101 commented 8 years ago

Thank you for your contribution, it will be merged. However it would be good if the indentation were completely fixed. Tabs should only be used for indentation and not alignment. For example: (<--> = tab, .... = spaces)

I'll fix it then.

In addition, lines should never have trailing whitespace, nor should them be composed solely of whitespace.

This includes separating the inv[x] = out... segments?

fincs commented 8 years ago

I referred to the fact that you had whitespace at the end of lines (after the last + for example), not in the middle of lines.

tommai78101 commented 8 years ago

Ah, didn't know. I'll go ahead and fix what you've mentioned.

fincs commented 8 years ago

Thank you again.