Monday, 3 November 2008

The problem, the overhaul, and the camera...

ive finally found a reason why i have struggled so much with the camera class, and it boils down to this:
I did not understand how any of this had anything to do with what i see.
I mean, i have the screen in front of me. i understand that what is being presented to me doesnt really "exist" that its just a representation of numbers displayed so that we puny humans can understand what we're doing, but the leap in logic that leads me from ones and zero's to matrices and verts to...well ones and zero's (as words) i suppose, was completely beyond me.

which leads to my first problem.

My matrix transformations are doing the wrong thing. This whole time i had thaught that our matrix transformations (rotation etc) should be giving out a vertice, after taking one and moving it, in actuality, i now realise, our transformations are there to store a specific transformation for general use.

This of course is a somewhat...devestating realisation, one that came about due to the input of my study partner (who i suspect at this moment is writing a blog post very similar to this) and our friend, who saw us working on it, and then pointed out, quite happily that we had made something that really wasn't useful in any way whatsoever.

This of course, leads me inevitably to the following. over the last week i have rewritten, hacked apart, and (hopefully) fixed all my issues, my solution should now do what it was supposed to do in the first place, my camera class has now, also hopefully, been finished, and (as far as i am aware) i can now load objects correctly.

i also managed to get namespaces to work correctly, which was a small issue that was suddenly swamped by the larger "it fails at doing stuff" issue.

however, due to the recreation of, essentially, my whole programme, my rendering pipeline work isn't complete (as of time of writing), hopefully more work on this may be finished by the next tutorial, however i find it unlikely at this juncture.

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


Monday, 20 October 2008

the wonderful world of matrice's...

...and how the fourth dimesnion isn't really time at all.

thats right, the fourth dimension is W. yep. thats right. W.

as a matrix is (essentially) a multidimensional array, of X, Y, and Z usually, the fourth dimension should follow on from those, and seeings as theres no more alphabet after Z, we'll start working our way backwards, to W. With this Knowledge firmly in my somewhat bemused hand (mind), i set forth into this strange new dimension, a place where objects are transformed, translated, and translucent...wait...forget that last bit.


i chose to base my Matrix class directly on the framework of my Vectors class, this however did cause some problems, including but not limited to:
  • How am i relating static voids to my main. (turns out in the matrix class the "static" part is dropped, and they become voids, which are called in the usual manner of Matrix::add(variables)
  • multiplication seeming far more complex (something that i will comparing shortly)
  • the Matrix Header issue.

Lets start with the last point shall we, there is a peculiar effect, when adding a file to a solution from outside of the solutions containing folder (ie from my documents rather than my document/visualstudio2008/projects/Vector etc), as when you do add that file, a file of that name is created within the containing folder, but all changes and saves are written to the original file. This causes 2 major problems.

The first is that, while you are updating the original file, the solution is attempting to read from the copy within its containing folder, the one that hasn't changed, thus preventing it from compiling correctly.

the second is that when you've finished your programming session, deep into the long hours of the night, you save, and you backup that solution, the updated file is lost from the backup, causing you to lose what could be hours of work.

however, a lesson learned is the first part of winning the programming war, and from now on i'll make sure i put my new external files into the containing folder before trying to add them.

now then, multiplication. Multiplication with a scalar is, as is typical, very simple, however multiplication of vectors becomes a long and drawn out process. Within this process a simple formula exists, row A X collumn B(as it was explained to me by a peer).

in reality that turned out as the heaving monstrocity shown below


result._m[0][0] = matrix1._m[0][0] * matrix2._m[0][0] + matrix1._m[0][1] * matrix2._m[1][0] + matrix1._m[0][2] * matrix2._m[2][0] + matrix1._m[0][3] * matrix2._m[3][0] ;
result._m[0][1] = matrix1._m[0][0] * matrix2._m[0][1] + matrix1._m[0][1] * matrix2._m[1][1] + matrix1._m[0][2] * matrix2._m[2][1] + matrix1._m[0][3] * matrix2._m[3][1] ;
result._m[0][2] = matrix1._m[0][0] * matrix2._m[0][2] + matrix1._m[0][1] * matrix2._m[1][2] + matrix1._m[0][2] * matrix2._m[2][2] + matrix1._m[0][3] * matrix2._m[3][2] ;
result._m[0][3] = matrix1._m[0][0] * matrix2._m[0][3] + matrix1._m[0][1] * matrix2._m[1][3] + matrix1._m[0][2] * matrix2._m[2][3] + matrix1._m[0][3] * matrix2._m[3][3] ;
result._m[1][0] = matrix1._m[1][0] * matrix2._m[0][0] + matrix1._m[1][1] * matrix2._m[1][0] + matrix1._m[1][2] * matrix2._m[2][0] + matrix1._m[1][3] * matrix2._m[3][0] ;
result._m[1][1] = matrix1._m[1][0] * matrix2._m[0][1] + matrix1._m[1][1] * matrix2._m[1][1] + matrix1._m[1][2] * matrix2._m[2][1] + matrix1._m[1][3] * matrix2._m[3][1] ;
result._m[1][2] = matrix1._m[1][0] * matrix2._m[0][2] + matrix1._m[1][1] * matrix2._m[1][2] + matrix1._m[1][2] * matrix2._m[2][2] + matrix1._m[1][3] * matrix2._m[3][2] ;
result._m[1][3] = matrix1._m[1][0] * matrix2._m[0][3] + matrix1._m[1][1] * matrix2._m[1][3] + matrix1._m[1][2] * matrix2._m[2][3] + matrix1._m[1][3] * matrix2._m[3][3] ;
result._m[2][0] = matrix1._m[2][0] * matrix2._m[0][0] + matrix1._m[2][1] * matrix2._m[2][0] + matrix1._m[2][2] * matrix2._m[2][0] + matrix1._m[2][3] * matrix2._m[3][0] ;
result._m[2][1] = matrix1._m[2][0] * matrix2._m[0][1] + matrix1._m[2][1] * matrix2._m[2][1] + matrix1._m[2][2] * matrix2._m[2][1] + matrix1._m[2][3] * matrix2._m[3][1] ;
result._m[2][2] = matrix1._m[2][0] * matrix2._m[0][2] + matrix1._m[2][1] * matrix2._m[2][2] + matrix1._m[2][2] * matrix2._m[2][2] + matrix1._m[2][3] * matrix2._m[3][2] ;
result._m[2][3] = matrix1._m[2][0] * matrix2._m[0][3] + matrix1._m[2][1] * matrix2._m[2][3] + matrix1._m[2][2] * matrix2._m[2][3] + matrix1._m[2][3] * matrix2._m[3][3] ;
result._m[3][0] = matrix1._m[3][0] * matrix2._m[0][0] + matrix1._m[3][1] * matrix2._m[1][0] + matrix1._m[3][2] * matrix2._m[2][0] + matrix1._m[3][3] * matrix2._m[3][0] ;
result._m[3][1] = matrix1._m[3][0] * matrix2._m[0][1] + matrix1._m[3][1] * matrix2._m[1][1] + matrix1._m[3][2] * matrix2._m[2][1] + matrix1._m[3][3] * matrix2._m[3][1] ;
result._m[3][2] = matrix1._m[3][0] * matrix2._m[0][2] + matrix1._m[3][1] * matrix2._m[1][2] + matrix1._m[3][2] * matrix2._m[2][2] + matrix1._m[3][3] * matrix2._m[3][2] ;
result._m[3][3] = matrix1._m[3][0] * matrix2._m[0][3] + matrix1._m[3][1] * matrix2._m[1][3] + matrix1._m[3][2] * matrix2._m[2][3] + matrix1._m[3][3] * matrix2._m[3][3] ;

yeah, isn't that grand. though to be fair, it follows a simple logic, and parts are easily copied and pasted into the right places.

for more on transformations, check back next time, when my brain has resolidified enough to make a coherent and informative post (the above is due some editing)

Wednesday, 15 October 2008

Friday, 10 October 2008

Technical Difficulties

It is a shame that, when doing a serious blog, one that tries to emphasise the technical element of a given career set, or learning module, that the host somehow confuses you with a computer, and tells you that your very own blog is spam. This, by the way, is my explanation of the lateness of this new post.


--------------------------------------------------------------

Vectors (going back over a week unfortunately)


I found My first steps into the world of graphics programming a daunting prospect, one that seemed to loom far above me as i ran headlong into to its immense foot.


Metaphor really isnt my thing. Taking on board that this was something that i will be needing to know for the rest of the year, i promptly began to look through available information, trawling through pages of literature, and not really understanding. MSDN (http://msdn.microsoft.com/en-gb/default.aspx) once again proves itself as a useful tool for would be developers, giving easy to understand information, and tutorials on coding. a small problem persists, whenever i attempt to run my code (of which i will be talking more on shortly) i get 17 build errors. I know the code is right, all the components are there for the programme to run and show a simple line on screen, but it just doesn't happen. after consulting with a number of my peers, i finally learn that this is a result of a rookie mistake, i have only been building the main .cpp file (by using build solution, visual studio ONLY builds the .cpp file where the main function is.) instead of the whole programme, that sorted, and a lesson learned, i moved on.


Vectors, Drawing Code, and Microsoft windows.h header files


I would like to start this post by detailing the issue with the Windows.h header file, in case any fellow students are reading this for help, and are having the same issue. It seems, through some fluke of programming or settings error, that some users on the university network do not have access to the windows.h header file. This isnt usually a problem, unless you are a programmer, and you are trying to do your introduction to 3d programming tutorials. The error appears to stem from the user settings applied to each university students account, though i am not sure of the specifics, it would seem resetting your account solves the problem.


Microsoft Visual studio is an incredible tool, one i know i won't be using forever, but as it stands, and for the p[urposes we are using it, it is an incredible thing to have access to. I say this because, for the first tutorials for intro to 3d, the majority of the code can be automatically built for you, something that saves a lot of time, however it is important that one knows what this code does, at least in the general sense, so that when visual studio is not available, you can still use the framework.


working through the first tutorials (bar my minor issue with rookie mistakes) was easy enough, once i understood the basic theory, which was easy enough to achieve with a little discussion among my peers, and a lot of looking at msdn to figure out why it wasn't working properly.


in the end, the actual code for drawing a line, or line of text, is simple enough


the code just below here is used to write the phrase "welcome to my blog!" in black, with an underline of blue.



void OnPaint(HDC hdc)
{
Graphics graphics (hdc);
Pen pen
(Color(255,0,0,255), 5);
SolidBrush
brush(Color(255,0,0,0));
FontFamily
fontFamily(L"Times New Roman");Font
font (&fontFamily,24,FontStyleRegular,
UnitPixel);
PointF
pointF(10.0f,20.0f);
graphics.DrawLine(&pen, 10,
50, 230,
50);
graphics.DrawString(L"Welcome to my blog!", -1, &font,
pointF,
&brush);
}



The resulting screen should resemble the one below


the window that is opened with the effects of the code snippet above inside, is mostly generated by windows visual studio. the only modifications made to the original code were to allow for the use of GDI+ and vector drawing code to work in the window.

One more note, on the use of time, i realise that i did not put as much time into learning about vectors as i should have, and i will put more time into understanding matrice's.

Tuesday, 30 September 2008

The Start of a Wonderful Journey

I realise, of course, that web logs, or blogs, are often used as places for personal discussion, to rant ones feelings about the world around them, and the like, however, this blog is less about my personal life, and more about my professional life, my learning, and my career in Games, and in Programming in general.

i am a Computer Games Programming Student at the University of Derby. I am in my Second year, and will be using this blog to showcase my achievements, and my work. I suppose this could be considered an online portfolio.