tag:blogger.com,1999:blog-39625153010357643832020-02-28T03:47:40.439-08:00Technically Correctsaecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-3962515301035764383.post-38809097957449355772011-12-14T22:57:00.000-08:002011-12-14T22:57:39.602-08:00Math, Can't Outrun ItSo my next big push is going to involve, adding a new function clone() to gladius.math to allow for cloning of matrices without incurring a new allocation. New branch created for this: <a href="https://github.com/saecob/gladius.math/tree/alpha">https://github.com/saecob/gladius.math/tree/alpha</a><br /><br />Simple enough with a source and destination parameter, copy one into the other. The next step is to bring transform.js in line with the api. The difficulty now is understanding the linear algebra used.<br /><ul><li>Scale()</li><li>Rotate()</li><li>Translate()</li></ul>Coming up with some clever tests and resources for this bit of code will be part of the challenge.<br /> <br />After getting things sorted out with transform, one last pass over the unit tests to add some variety will need to be done. After this maybe it will be time to take a look at our Algorithm scripts.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com0tag:blogger.com,1999:blog-3962515301035764383.post-31172371271255369152011-12-12T17:42:00.000-08:002011-12-12T17:42:47.472-08:00Progress CentralToday after my exam i decided to knock out a bunch of implementations for Gladius.Math. We now have a 90% complete implementation of the new API and its exciting. Check it out here: <a href="https://github.com/saecob/gladius.math">https://github.com/saecob/gladius.math</a><br /><br />The main work was done to Matrices of the 3x3 and 4x4 variety and of course the ever loved test scripts to go along with them. The biggest change to get used to is definitely the addition of matrix lists as parameters for almost all of the matrix implementations.<br /><br />Because of this, i decided to iterate through the matrix list in each respective function and call the base Matrix class to complete the additions. This looping system may have a pretty big impact on performance for long lists of matrices but for now it seems to be working fine.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-2punVqzf3Aw/Tuas9LRUf3I/AAAAAAAAAAk/3z-YTgiVPE0/s1600/Transform_Fix.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-2punVqzf3Aw/Tuas9LRUf3I/AAAAAAAAAAk/3z-YTgiVPE0/s1600/Transform_Fix.jpg" /></a></div>Along the way while updating Matrix4, i managed to break the transform methods as they were relying on the old method calls to multiply. A simple fix but it will go in along with my next big update. All i would need to do is to add the 2 matrices being multiplied to a list and pass that parameter.<br /><br />The next big update will include Quaternion and Transform method implementations and tests, along with some way to allow a developer to clone a matrix/vector without incurring a new allocation.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com0tag:blogger.com,1999:blog-3962515301035764383.post-55059096694066798802011-12-01T05:05:00.001-08:002011-12-01T05:14:42.088-08:00End In SightSo the end of the school term is fast approaching and I am definitely feeling the crunch. I pushed up a new commit to my Github account (<a href="https://github.com/saecob/gladius.math/tree/develop">https://github.com/saecob/gladius.math/tree/develop</a>) under the develop branch in preparation for a major pull request for implementations of all Matrix functions.<br /><br />Everything seems to be working fine, except for inverse().<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-lclSh1y7fWM/Ttd9CAmIjyI/AAAAAAAAAAc/y2G5goZeWvY/s1600/InverseTest.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="105" src="http://3.bp.blogspot.com/-lclSh1y7fWM/Ttd9CAmIjyI/AAAAAAAAAAc/y2G5goZeWvY/s320/InverseTest.jpg" width="320" /></a></div>Not exactly sure what is wrong yet but i think i may have missed a movement of some sort with the matrix indexes. Ill take a look at it during the day today.<br /><br />Next up: Matrix3 and finally Matrix4 which already has implementations but needs to be brought in line with the API.<br />Also, I need to change some of the tests for Matrix as the API now states that our functions should accept an array of Matrices which is not being tested as of yet.<br /><br />Check back tonight.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com0tag:blogger.com,1999:blog-3962515301035764383.post-90426505119469331522011-11-27T23:45:00.001-08:002011-11-27T23:59:25.636-08:00The Matrix, Is Out ThereAfter getting started with the new matrix implementations, having the input parameters as a list of matrices is turning out to be a bit more of a pain than anticipated.<br /><br />The main downside is the fact that we now have to iterate through the list of matrices in order to perform add(), subtract(), multiply() on each. We also have to save the results of the previous additions and pass those on for the next set. Something like this:<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-7axv2Y1e6-k/TtM9Ns3XbmI/AAAAAAAAAAU/hCqFT6D7VIQ/s1600/addFunction.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="146" src="http://3.bp.blogspot.com/-7axv2Y1e6-k/TtM9Ns3XbmI/AAAAAAAAAAU/hCqFT6D7VIQ/s320/addFunction.jpg" width="320" /></a></div><br /><br /><br /><br /><br />I haven't run any speed tests but this seems like it may be slow, but for now it will have to do.<br /><br />Now for my two concerns regarding the API and reality.<br /><br /><ol><li>Our add(), subtract(), and multiply() functions all take 2 parameters, <i><b>ml</b></i>, the list of matrices and <b><i>result</i></b>, the optional variable in which we will store our result. The API specifies that if the list is only one matrix long then we will return the one matrix. What if the result parameter has values in it and the list only has one matrix? then we will not add the two properly. Maybe this will never happen, ill wait to ask in iRC.</li><li>The <i><b>inverse(m) </b></i>function returns the inverse of the given matrix. A square matrix will only have an inverse if the determinant of that matrix is not zero. This situation is not covered in the api.</li></ol>That is about it for now, going to get these cleared up and then move forward.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com0tag:blogger.com,1999:blog-3962515301035764383.post-54568641258408056582011-11-24T17:47:00.001-08:002011-11-24T17:54:09.096-08:00Boys Are Back In TownSo I've managed to get myself in gear and get contributing to Math.Gladius again. The math library underwent a massive refactoring in which it was broken down in to small chunks consisting of a script for each size of Vector and Matrix object.<br /><br />When I left off, work had been completed to Vector through to Vector4 tests included. Now I am beginning to work on the Matrix functions. There are a few differences in the way we deal with matrices, such as the operation functions (+, -, /, *) taking a list of matrices.<br /><br />Check it out: <a href="https://github.com/alankligman/gladius.math/wiki/Math-api-reference">https://github.com/alankligman/gladius.math/wiki/Math-api-reference</a><br /><br />I will assume the input is always valid, so from there I'll just have to figure out a clever way of:<br /><ul><li>Finding out how many Matrices there are in the list</li><li>Performing the required operation quickly and efficiently</li></ul>I'll have more later tonight.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com0tag:blogger.com,1999:blog-3962515301035764383.post-69617856216853270732011-10-04T16:08:00.000-07:002011-10-04T16:08:45.083-07:00Equality Among FloatsWell the Gladius Math library is coming along swimmingly and is taking shape very quickly now that we have the API outline almost complete. (<a href="https://github.com/alankligman/gladius.math">https://github.com/alankligman/gladius.math</a>) Check out the wiki section.<br /><br />After implementing the functions for 2 dimensional vectors [x,y] an interesting issue presented itself in the form of one glaring logic error and a unit test case issue.<br /><ol><li>In our library we have a function, normalize(v1, result); which returns a unit vector with same direction as the given vector v1. Result is the optional parameter in which we store the resulting vector. Our code for this function was as follows:</li></ol><blockquote style="background-color: #fff2cc;"><i>// Return a Vector(result) with same direction as v having unit length<br /> normalize: function( v, result ) {<br /> for( var i = 0, len = v.length; i < len; ++ i ) {<br /> result[i] = v[i] / len;<br /> }<br /><br /> return result;<br /> }</i></blockquote><blockquote> Normalizing a vector is done by calculating its length and dividing each component by the length. At first glance this code looks to be correct but we will quickly see how a small flaw <i>ruins</i> any results this function returns.</blockquote><blockquote>The problem caused by <i style="background-color: #fff2cc;">len = v.length.<span style="background-color: white;"> </span></i><span style="background-color: #fff2cc;"><span style="background-color: white;">When we use <i><span style="background-color: #fff2cc;">v.length</span><span style="background-color: white;"> </span></i><span style="background-color: white;">it is in fact returning the length of the array holding our vector, in this case [x,y] which would cause the function to just divide components by 2.</span></span></span></blockquote><blockquote>By changing the code to <i style="background-color: #fff2cc;"> len = vector.length(v);</i> we open up the next set of problems. <i>Vector lengths</i> (<a href="http://en.wikipedia.org/wiki/Euclidean_vector#Length">http://en.wikipedia.org/wiki/Euclidean_vector#Length</a>)</blockquote><ul><li>By calculating the absolute length of vectors, some pretty unpleasant numbers can be returned as a result. For example, when we call <span style="background-color: #d9ead3;">normalize() for the vector v1 = [12,-5]</span> the <span style="background-color: #d9ead3;">resulting vector is expressed as v2 = [(12/13), (-5/13)]</span>. This would not be a problem if a computer were able to show the results as the above expression but of course it can not and it will return a float with a set number of decimals.</li><li>This problem is compounded when you start to add other operations on the resulting vector which will continue to use the float representation of the result. This is very evident in the unit tests:</li></ul><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-V37GOjD8swo/TouQ9reLpFI/AAAAAAAAAAQ/jhtDCWT9ZxQ/s1600/TestResult.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="162" src="http://4.bp.blogspot.com/-V37GOjD8swo/TouQ9reLpFI/AAAAAAAAAAQ/jhtDCWT9ZxQ/s320/TestResult.jpg" width="320" /></a></div> You can see above that the expected results and the computed results are identical up until the sixth digit after the decimal. For all intensive purposes this is "equal", we now have to add an equal(v1, v2, e) function which will compare 2 vectors up to a set number of decimals for use to call them equal.<br /><br />And that is what i'm working on now, as well as figuring out how to compare only a set number of decimals in the Qunit tests.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com0tag:blogger.com,1999:blog-3962515301035764383.post-89732003263047464362011-10-01T00:12:00.000-07:002011-10-01T00:12:24.576-07:00Unit Tests, Love HateToday I decided to try and get some unit tests created for the matrix functions which I implemented in yesterdays push (<a href="https://github.com/saecob/gladius.math/tree/Matrix2">https://github.com/saecob/gladius.math/tree/Matrix2</a>).<br /><br />After spending some time identifying how unit tests are launched (index.html),<br /><br /><div class="separator" style="clear: both; text-align: left;"><a href="http://2.bp.blogspot.com/-e2zNdUki_eM/Toa3ZUCh6MI/AAAAAAAAAAM/qCBZ2JTqQHs/s1600/LaunchJunitTest.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="http://2.bp.blogspot.com/-e2zNdUki_eM/Toa3ZUCh6MI/AAAAAAAAAAM/qCBZ2JTqQHs/s320/LaunchJunitTest.jpg" width="320" /></a></div><br />I created my own test script with the name Math.Matrix2.js which tests 2 x 2 matrices.<br /><br />When I first ran the newly created test, I noticed that none of the coded implementations of any size matrix had been tested. After further inspection, the matrix functions seem to be direct logic and code copies of all the implemented vector functions.<br /><br />At first glance this doesn't seem to be such a big problem but I don't think that they correlate exactly.<br /><br />The second issue which came about from these discoveries is, that at the moment I feel like I am implementing and adding functions arbitrarily not knowing if they will even be useful to someone using the library.<br /><br />For example, we have a function rotate() which creates a rotation matrix given a Quaternion(<a href="http://en.wikipedia.org/wiki/Quaternion">http://en.wikipedia.org/wiki/Quaternion</a>). This function is implemented under matrix4 functions, i.e 4x4 matrices.<br /><br />The question is: Do we need this function for 2x2 and 3x3 matrices as well?<br /><br /><span style="font-size: small;"><i style="background-color: #d0e0e3; font-family: "Courier New",Courier,monospace;"> // Construct a 2x2 rotation matrix from a Quaternion.<br /> rotate: function() {<br /> if( 0 === arguments.length ) {<br /> return Matrix( 4, that.matrix2.identity );<br /> } else if( 1 === arguments.length ) {<br /> var v = arguments[0];<br /> var r = v[0];<br />// return Matrix( 4, [] );<br /> // Todo (Quaternion = w + xi + yj + zk)<br /> } else {<br /> return Matrix( 4, arguments );<br /> }<br /> }<br /> };</i></span><br /><br />It seems like it would be a good idea to collaborate with the different areas of the project (Physics, Rendering, etc.) and come up with an interface with a list of functions, parameters, and return types/values so that everything put in Gladius.Math is useful as a library.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com0tag:blogger.com,1999:blog-3962515301035764383.post-58844554377888607952011-09-29T23:15:00.000-07:002011-09-30T00:44:12.480-07:00An Ode To MathRecently I decided to contribute to the Gladius/Paladin (<a href="https://github.com/alankligman/gladius">https://github.com/alankligman/gladius</a>) open source project, more specifically, the Gladius.Math(<a href="https://github.com/alankligman/gladius.math">https://github.com/alankligman/gladius.math</a>) library. Having only recently decided to get involved with the project, I was feeling a<i> little</i> overwhelmed but excited as well.<br /><br />The issues/tickets I have decided to work on are the implementations of several math functions involving various size matrices and vectors.<br /><br />In order to scope this correctly I decided to start with all the functions for 2x2 matrices, then 3x3 and so forth. For each matrix size from 2x2 to 4x4 there are a number of functions which perform various operations, or specifically:<br /><ul><li>Translate</li><li>Scale</li><li>Rotate </li></ul>Everyone loves wiki links:<br />Translations - <a href="http://en.wikipedia.org/wiki/Translation_%28geometry%29">http://en.wikipedia.org/wiki/Translation_%28geometry%29</a><br />Scaling - <a href="http://en.wikipedia.org/wiki/Scaling_%28geometry%29">http://en.wikipedia.org/wiki/Scaling_%28geometry%29</a><br />Rotations - <a href="http://en.wikipedia.org/wiki/Rotation_matrix">http://en.wikipedia.org/wiki/Rotation_matrix</a><br /><br />Also an interesting read: <a href="http://knol.google.com/k/matrices-for-3d-applications-translation-rotation#">http://knol.google.com/k/matrices-for-3d-applications-translation-rotation#</a><br /><br />For my first push I implemented these functions for 2x2 matrices. The unit testing will be the next major focus in order to determine performance and test logic.<br /><br />Take a look at the code yourself : <a href="https://github.com/saecob/gladius.math/commit/20caebde7578ca3a772440a7bc2b2421740b51e6#L0R548">https://github.com/saecob/gladius.math/commit/20caebde7578ca3a772440a7bc2b2421740b51e6#L0R548</a><br /><br />While coding I noticed that there were a number of basic matrix functions which were missing and a number which didn't seem to be present in other math libraries which i used for code examples.<br /><br />If I'm going to spend some time with this library I think I'll need to look at some other game engine math libraries to see if there are functions which would help to include.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com0tag:blogger.com,1999:blog-3962515301035764383.post-24770503204211407052011-09-29T15:24:00.000-07:002011-09-29T15:24:07.165-07:00To Git, Or Not To GitAfter being introduced to GitHub (<a href="http://www.github.com/">www.github.com</a>) a few weeks ago, I thought that things were pretty straight forward and easy to use, that is until you actually start doing some work of course. <br /><br />The Git Bash tool, used to communicate with the Git server and to organized your branches and repositories, uses many different commands to do these things which I found very difficult to remember when it came down to working with them. <br /><br />Luckily Git provides lots of support and guides to help new users like me along. Here are some which I found helpful.<br /><br /><a href="http://help.github.com/">http://help.github.com/</a> - The main hub of information on all things Git<br /><a href="http://help.github.com/git-cheat-sheets/">http://help.github.com/git-cheat-sheets/</a> - A compilation of cheat sheets and quick guides to using the bash commands.<br /><br />I found these resources very helpful and I thought I would share.saecobhttp://www.blogger.com/profile/07787653930456584171noreply@blogger.com2