{"action":"created","issue":{"url":"https://api.github.com/repos/bjz/cgmath-rs/issues/210","labels_url":"https://api.github.com/repos/bjz/cgmath-rs/issues/210/labels{/name}","comments_url":"https://api.github.com/repos/bjz/cgmath-rs/issues/210/comments","events_url":"https://api.github.com/repos/bjz/cgmath-rs/issues/210/events","html_url":"https://github.com/bjz/cgmath-rs/issues/210","id":70771710,"number":210,"title":"Matrix4::invert breaks because of low precision in approx_eq","user":{"login":"jarrett","id":16208,"avatar_url":"https://avatars.githubusercontent.com/u/16208?v=3","gravatar_id":"","url":"https://api.github.com/users/jarrett","html_url":"https://github.com/jarrett","followers_url":"https://api.github.com/users/jarrett/followers","following_url":"https://api.github.com/users/jarrett/following{/other_user}","gists_url":"https://api.github.com/users/jarrett/gists{/gist_id}","starred_url":"https://api.github.com/users/jarrett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarrett/subscriptions","organizations_url":"https://api.github.com/users/jarrett/orgs","repos_url":"https://api.github.com/users/jarrett/repos","events_url":"https://api.github.com/users/jarrett/events{/privacy}","received_events_url":"https://api.github.com/users/jarrett/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-04-24T19:16:28Z","updated_at":"2015-04-24T22:34:09Z","closed_at":null,"body":"When inverting a matrix, we check that the determinant is non-zero [using `approx_eq`](https://github.com/bjz/cgmath-rs/blob/master/src/matrix.rs#L400). If the determinant is approximately zero, the inversion fails.\r\n\r\nBut [`approx_eq`](https://github.com/bjz/cgmath-rs/blob/182f7b41dcdff2b21fbeacd6f3329d98ea72f462/src/approx.rs#L21) only goes to a precision of 10^-5.\r\n\r\nThat's problematic, because projection matrices often have very small determinants. This is especially true when the camera is zoomed out very far. In that case, we're transforming a large volume of world space to the clip space volume. Which means that the determinant tends to be very small. (This is because the determinant is the ratio of the two volumes.)"},"comment":{"url":"https://api.github.com/repos/bjz/cgmath-rs/issues/comments/96085318","html_url":"https://github.com/bjz/cgmath-rs/issues/210#issuecomment-96085318","issue_url":"https://api.github.com/repos/bjz/cgmath-rs/issues/210","id":96085318,"user":{"login":"kvark","id":107301,"avatar_url":"https://avatars.githubusercontent.com/u/107301?v=3","gravatar_id":"","url":"https://api.github.com/users/kvark","html_url":"https://github.com/kvark","followers_url":"https://api.github.com/users/kvark/followers","following_url":"https://api.github.com/users/kvark/following{/other_user}","gists_url":"https://api.github.com/users/kvark/gists{/gist_id}","starred_url":"https://api.github.com/users/kvark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kvark/subscriptions","organizations_url":"https://api.github.com/users/kvark/orgs","repos_url":"https://api.github.com/users/kvark/repos","events_url":"https://api.github.com/users/kvark/events{/privacy}","received_events_url":"https://api.github.com/users/kvark/received_events","type":"User","site_admin":false},"created_at":"2015-04-24T22:34:09Z","updated_at":"2015-04-24T22:34:09Z","body":"> One of the two inversions, inv(V*M) or inv(P), has to fail.\r\n\r\nNo. What I'm saying is - instead of computing `inv(P)` and then transforming a point, you can just *manually* un-project the point, involving no matrix inversion.\r\n\r\nLet's say your orthographic projection is: `w = P(q) = scale*q + offset`, then you can un-project `q` without inversing any matrix: `q = (w - offset) / scale`.\r\n\r\n> Do you know why 10^-5 was chosen as the epsilon?\r\n\r\nI bet it was an arbitrary decision. But whatever you want to change it to would be no less arbitrary, and that's why I don't like it as a solution."}}