{"id":61,"date":"2015-05-15T19:43:38","date_gmt":"2015-05-15T19:43:38","guid":{"rendered":"http:\/\/blog.qubekwest.com\/?p=61"},"modified":"2016-04-14T18:34:19","modified_gmt":"2016-04-14T18:34:19","slug":"mathd","status":"publish","type":"post","link":"https:\/\/blog.qubekwest.com\/?p=61","title":{"rendered":"Math&#8217;d"},"content":{"rendered":"<p>Once I managed to get an entirely unimaginative red 2D triangle or three onto the screen in a few different ways, I knew that I had to expand into the 3rd dimension. \u00a0To that end, I dropped back to a single 3D triangle, left it red, and prepared myself for what should be on the screen. \u00a0A couple seconds of compiling and firing up the program revealed that while the triangle was in fact on my screen, it looked no different from my 2D version.<\/p>\n<p>This is simply because by default OpenGL happily ignores the Z-Axis entirely. \u00a0In the old fixed pipeline days, you could probably fix that by simply setting some configuration value or other to one that makes 3D stuff happen. \u00a0In the fancy new shader pipeline you need to tell the card how to do that. \u00a0That means passing a few matrices down with all of your fun geometry. \u00a0In English, that means you need to tell the card how to use the Z-axis.<\/p>\n<p>In one of the books I&#8217;m reading it was mentioned that OpenGL &#8220;is not a math library.&#8221; \u00a0This is especially true with LWJGL. \u00a0In C\/C++ you can use the library mentioned by the book called vmath. \u00a0In Java you are on your own. \u00a0This fact has sent me down the multi-week long detour of crafting a math package of my own and making sure the tests for it prove it behaves the way math should.<\/p>\n<p>The current list of things in my math library are as follows:<\/p>\n<ul>\n<li><em>For graphics:<\/em>\n<ul>\n<li>Vector2 &#8211; Vector of 2 floating points.<\/li>\n<li>Vector3 &#8211; Vector of 3 floating points.<\/li>\n<li>Vector4 &#8211; Vector of 4 floating points.<\/li>\n<\/ul>\n<\/li>\n<li><em>For pixel level precision:<\/em>\n<ul>\n<li>IntVector2 &#8211; Vector of 2 integers.<\/li>\n<li>IntVector3 &#8211; Vector of 3 integers.<\/li>\n<li>IntVector4 &#8211; Vector of 4 integers.<\/li>\n<\/ul>\n<\/li>\n<li><em>For transforms:<\/em>\n<ul>\n<li>Matrix33 &#8211; A 3&#215;3 matrix of floating points.<\/li>\n<li>Matrix44 &#8211; A 4&#215;4 matrix of floating points.<\/li>\n<li>Quaternion &#8211; Numbers in the form (a + b<em>i<\/em> + c<em>j<\/em> + d<em>k<\/em>)\u00a0using floating point values.<\/li>\n<\/ul>\n<\/li>\n<li><em>For fractals:<\/em>\n<ul>\n<li>ComplexNumber &#8211; Numbers in the form (a + b<em>i<\/em>) using floating point values.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>This list is perhaps a bit larger than I needed with the goal of simply producing a a proper perspective projection matrix. \u00a0I was however on a roll and my test cases provided actual evidence of progress which is nice to have sometimes when you feel a bit stalled in a project. \u00a0I also created a little test program to see how well these things perform. \u00a0Specifically how quickly I can multiply a Matrix44 by another Matrix44, and how fast multiplying a Matrix44 by a Vector4 was. \u00a0I was satisfied with the numbers I was seeing so hopefully it will be enough.<\/p>\n<p>As of right now, my test coverage tool tells me that around 89% of my math package is covered with tests. \u00a0I am shooting for a perfect 100% for this package because if I can&#8217;t trust my math library, how can I know when I&#8217;ve built things that use it and have problems whether it&#8217;s the math that&#8217;s wrong or the thing I built on top of it?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once I managed to get an entirely unimaginative red 2D triangle or three onto the screen in a few different ways, I knew that I had to expand into the 3rd dimension. \u00a0To that end, I dropped back to a single 3D triangle, left it red, and prepared myself for what should be on the &hellip; <a href=\"https:\/\/blog.qubekwest.com\/?p=61\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Math&#8217;d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-61","post","type-post","status-publish","format-standard","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=\/wp\/v2\/posts\/61","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=61"}],"version-history":[{"count":4,"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=\/wp\/v2\/posts\/61\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=\/wp\/v2\/posts\/61\/revisions\/68"}],"wp:attachment":[{"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qubekwest.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}