{"action":"opened","issue":{"url":"https://api.github.com/repos/gingerBill/gb/issues/15","repository_url":"https://api.github.com/repos/gingerBill/gb","labels_url":"https://api.github.com/repos/gingerBill/gb/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/gingerBill/gb/issues/15/comments","events_url":"https://api.github.com/repos/gingerBill/gb/issues/15/events","html_url":"https://github.com/gingerBill/gb/issues/15","id":190549904,"number":15,"title":"Clarify column-major vs row-major","user":{"login":"jimon","id":1333661,"avatar_url":"https://avatars.githubusercontent.com/u/1333661?v=3","gravatar_id":"","url":"https://api.github.com/users/jimon","html_url":"https://github.com/jimon","followers_url":"https://api.github.com/users/jimon/followers","following_url":"https://api.github.com/users/jimon/following{/other_user}","gists_url":"https://api.github.com/users/jimon/gists{/gist_id}","starred_url":"https://api.github.com/users/jimon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimon/subscriptions","organizations_url":"https://api.github.com/users/jimon/orgs","repos_url":"https://api.github.com/users/jimon/repos","events_url":"https://api.github.com/users/jimon/events{/privacy}","received_events_url":"https://api.github.com/users/jimon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-20T10:11:49Z","updated_at":"2016-11-20T10:11:49Z","closed_at":null,"body":"Reading gb_math.h source sometimes is really confusing.\r\nUsual math notation for matrix is Aij where i is row and j is column:\r\n\r\n\tA00 A01 A02 A03\r\n\tA10 A11 A12 A13\r\n\tA20 A21 A22 A23\r\n\tA30 A31 A32 A33\r\n\r\nNote that this notation is memory-layout free, this is just how matrices are written down on paper in generic science/engineering notation.\r\n\r\nConsidering this:\r\n\r\n```\r\ntypedef union gbMat4 {\r\n\tstruct { gbVec4 x, y, z, w; };\r\n\tgbVec4 col[4];\r\n\tfloat e[16];\r\n} gbMat4;\r\n```\r\n\r\nOne can make an assumption that layout is column-major, awesome. But then reading something like this:\r\n\r\n```\r\ngbFloat4 *gb_float44_m(gbMat4 *m)    { return (gbFloat4 *)m; }\r\n...\r\ngbFloat4 *m = gb_float44_m(out);\r\n...\r\nm[0][0] = 1.0f / (aspect*tan_half_fovy);\r\nm[1][1] = 1.0f / (tan_half_fovy);\r\nm[2][2] = -(z_far + z_near) / (z_far - z_near);\r\nm[2][3] = -1.0f;\r\nm[3][2] = -2.0f*z_far*z_near / (z_far - z_near);\r\n```\r\n\r\nMeans that `m` is still column-major, so it's `m[j][i]` notation instead of `m[i][j]` as accepted in generic mathematics. We can test it like this :\r\n\r\n```\r\nuint8_t a[16] = // column-major\r\n{\r\n\t0x0, 0x1, 0x2, 0x3,\r\n\t0x4, 0x5, 0x6, 0x7,\r\n\t0x8, 0x9, 0xa, 0xb,\r\n\t0xc, 0xd, 0xe, 0xf\r\n};\r\ntypedef uint8_t column_t[4];\r\ncolumn_t * c = (column_t*)a;\r\nprintf(\"%x\\n\", c[2][1]); // prints 9, which means 2 is column, 1 is row\r\n```\r\n\r\nSo would be nice to write down some comments in a lib saying this, and maybe introduce some `_M(i, j)` macro just so algorithms are written down in more mathematics friendly notation, which should enable less error-prone code."}}
{"actor":{"display_login":"jimon"}}