Saturday, November 20, 2010

Matrix issues and code cleanup

Last night I worked more on the collision detection, including fixing the equation described in the comments of the last post. I was hoping that that would work some miracle of sorts, whereupon everything would function wonderfully and precisely according to my mind's design.

That didn't happen.

Things are still screwy, but I did notice a few glaring errors I had originally overlooked. I fixed those as well, to no immediate avail (certain object parameters were left undefined upon object creation). I'm not quite sure where the problem lies, but I have a few guesses.

It might be in the matrix inversion (i.e., the transformation matrix is not being properly inverted). This is easily tested, however. Just multiply the first times the resulting inverse and it should return the identity matrix. If not, well, there's my answer. If yes...

It could also be in my matrix multiplication routine. After I get the transformation matrices of the two objects being tested for collision, they are multiplied together. This should be a simple nested for loop, except that the matrices are, instead of two-dimensional 4x4 arrays, one-dimensional arrays with 16 elements. This is necessary because it is consistent with how OpenGL handles its matrices. So instead of a nested for loop, I have one for loop with what I hope are correct index definitions in the assignments. I would post the code demonstrating this, but I don't have it handy.

After spending too much time scrutinizing my code, I decided to clean some of it up. I consolidated redundant code into clearly defined methods, added comments describing every step of the process and otherwise organized lines more neatly. I'm really hoping to finish up collision detection by the end of the weekend so that I can move forward with my todo list. I desperately do not want to get hung up on this one task for too long; there's too much to do ahead of me.

No comments:

Post a Comment