sgorsten / linalg

linalg.h is a single header, public domain, short vector math library for C++
The Unlicense
849 stars 68 forks source link

Add a lookat matrix constructor #28

Closed TestingPlant closed 3 years ago

ghost commented 3 years ago

Works for my purposes, though @sgorsten provided a more compact version in #29. There is also the question of generality: I see one use of the ternary operator (?) while frustum_matrix uses it twice (though I don't know what it's doing).

TestingPlant commented 3 years ago

The ternary operator I put on line 717 is designed to handle some edge cases. Assuming up is (0, 1, 0), if z is exactly (0, 1, 0), (0, 1, 0) × (0, 1, 0) would evaluate to (0, 0, 0). Normalizing this would make each component of x nan, which means the resulting matrix wouldn't be really helpful. I'm not exactly sure how using (z.z, z.x, z.y) fixes it, but it made it work in those edge cases in my testing.

TestingPlant commented 3 years ago

Commit 105866d4b558b50cea61f0bd0253531b6f875152 seems to have added lookat_matrix, so I'm closing this now.