Monday, 27 October 2008

Struggling with the Camera...

I will freely state the following as a fact:




"I struggled, immensely, with the camera stuff".




In part, this may have been because i had not entirely completed my matrix transformations classes beforehand. But also, due to some reshuffling of the timetable this week, my time management plan went down the proverbial toilet. Attempting to shovel in an extra module weeks worth of work into an already packed weekend of work is somewhat...difficult to be sure. Not to mention the immensity of the task set forth within that extra piece of work.




I know what must run through the readers head at this pronouncement: "well you should just manage your time better." or "work harder" or any number of extra little comments. Well when there is no free time to shove work into, time management becomes pointless, as everything needs to get done and you have no time for it. it becomes impossible to work harder when you are trying to evenly spread your ability to work with coherence over more work than you can do, withthout causing ones brain to melt inside ones own head of course, and i'm sorry.




I'm sorry that i have fallen behind, I'm sorry that i have not gotten the work done, and I'm sorry that my ability to reshuffle my timetable is so sorely limited.




Apologies over, now onto the technical aspects of the weeks work.




The camera header/Class:




The header (and by extension the class itself), is very simple, containing only a minimal ammount of functions (as a good deal of the class is already set out in the matrix class), working with my study partner, the following code was developed (this stores a view matrix, and also has a function that uses the matrix to transform a vector)





(My apologies about the small size of the text in this image, i will edit this at a later date)



The View function calls the transform function from the matrix class to compress the 4d matrix into a 4d vector, sending the vector back to the main class (a testing class) to display whatever the vector ends up as as numbers in a console window.



the function itself uses a formula, found at http://gregs-blog.com/, adapted for use in a C++ class. the adaptation is simple enough, the following is an image containing the formula found on gregs blog:

this forms a 3d matrix (while a fourth dimension, used for translation, can be added manually around it). the purpose of this matrix is to allow the user to rotate a vector through a SERIES of rotations, rather than rotating the vector once for x axis, taking the result, using the result to rotate along the y axis, taking the result from that, and then using that result to rotate along the z axis, which im sure you can agree, is far more complicated than neccesary.

The following is a version of the first part of the above code, that can be used in c++:

cameraM._m[0][0]=(1-cos(thetaX))*v1._x*v1._x+cos(thetaX);

as you can see the modification is only slight, changing the variable theta (i am unsure of how to correctly display the theta symbol in blogger) with thetaX (the angle with which to rotate along the x axis). changing the variable vx to the vector's (v1) X axis variable. and adding the result to the matrix cameraM


No comments: