If I can offer another €0.02,
For learning about transformations, OpenGL could potentially be a source of confusion because there are different sets of transformations that have different effects and there are different ways to mentally visualise the results.
Using your 2D grid analogy will simplifiy things substantially. Hopefully this will not duplicate any information in the previous posts and doesn't come over too simplistic.
Imagine your (x,y) coordinate point at (1,0).
Now add a circle of radius 1, centre (0,0). Your point sits where this circle crosses the x-axis.
You want to rotate this point 45 degrees about the origin. The resulting point will also lie on the edge of the circle but no longer on the x-axis.
If you were to draw a line through the origin (0,0) and the point (1,1), you point would sit where this diagonal line crosses the edge of the circle (often called a unit-circle).
The question is, how do you calculate the new coordinates.
You use matrix multiplication:
new_point = rotation_matrix * old_point
Code:
(x) = old_point
(y)
(x') = new_point
(y')
(a b) = rotation_matrix
(c d)
To multiply these and calculate (x', y') we apply the formula in ROOts' first post:
x' = a * x + b * y
y' = c * x + d * y
From the
linear algebra / simultaneous equations point of view, we often know (x, y) and (x', y') and we want to FIND a, b, c and d. This is more complicated because there is no guarantee that you will a solution exists and I would suggest that you don't worry about this side of things.
From a
computer graphics / geometry point of view, we often know a, b, c, and d because we know what transformation we want to apply and we want to FIND (x', y').
For the angle 45 degrees,
a = cos(45)
b = -sin(45)
c = sin(45)
d = cos(45)
(NB the signs of b,c can swap depending on the direction of rotation)
If you want to rotate a square, you simply apply the same transformation to all 4 points or vertices that define the square.
The identity matrix is one that performs no transformation:
If a=1, b=0, c=0 and d=1 then you find :
x' = 1 * x + 0 * y = x
y' = 0 * x + 1 * y = y
i.e. the point is not transformed : (x,y) == (x', y')
For different transformations, you use different matrices, commonly you will use rotation and scaling (transforms a square into a bigger, or smaller square). You might also want to be familiar with the terms "similarity" (transforms a square into a rectangle, preserves angles in a geometric shape) and "affine" (transforms a square into a parallelogram, preserves parallel lines).
So far I have avoided translations, the most simple transformation.
The reason for this is that we have to change out coordinate system slightly.
A translated point (x', y') is described like this:
x' = x + u
y' = y + v
where u and v are values in the 2D grid. Now this is a separate addition to our transformation matrix multiplication.
BUT, it is possible to combine the transformation into a single multiplication.
Instead of writing (x,y) we call the original point (x, y, 1) and the transformed point (x', y', 1)
A three dimensional matrix multiplication with these points goes like this:
Code:
(a b u) (x) (x')
(c d v) * (y) = (y')
(0 0 1) (1) (1 )
with
x' = a* x + b * y + 1 * u
y' = c * x + d * y + 1 * v
1 = 0 * x + 0 * y + 1 * 1
so we now incorporate u and v as out translation parameters into a single matrix.
Note that a,b,c and d stay in the matrix in the same place, simply embedding a 2x2 matrix in a 3x3.
We just have to fill the appropriate spaces in the matrix with some suitable 0's and 1's.
To perform only a translation, you would set a,b,c,d to the identity matrix.
Extending this to 3D, gives us 4D vertices to represent 3D postions.
Adding the extra coordinate opens up a whole other can of worms though due to the way opengl uses it.
You have also be using matrix multiplication through the functions glRotate*, glScale* and glTranslate* which save the overhead of creating a matrix.
Seeing as you have obviously managed thus far, I would highly recommend, as a visual aid, drawing a couple of unit cubes on screen and then experimenting with glMultMatrix to see how different matrix change the cube. The compilcations in OpenGL are that you are no longer sticking to a fixed 2D coordinate system. You can change the origin, and relative coordinate systems so that it is easy to get confused about which transformations you are applying.
Check Chapter 3 and Appendix G of The Red Book too.
Anyway, I hope this helps fill in some of the gaps ... I think it is very difficult to learn the maths without active help because you will find everyone (computer bods, mathematicians of a hundred different flavours, physicists, economists and so on) has their own little (or large) subset of an enormous topic and describes it in their own way in there own terms. Lots of aspects are related (fancy describing transformations in terms of eigenvectors and values?) and crop up all over the place under different topics.
Good Luck
[BIG EDIT]
Ok, just noticed this and I don't want to cause confusion:
Quote:
then to get to J3 from J2 you need to procede 1 unit along the x-axis given by
Code:
(1 0 0)
(0 1 0)
(1 0 1)
so basically we have these matrices and we multiply with the modelview matrix to get where we wanna go
|
Here, kev82 has expressed the translation:
Code:
(1 0 0)
(0 1 0)
(u v 1)
This is the same as my explantion, except he is performing calculations like this:
Code:
(x y 1) * (a c 0) = (x' y' 1)
(b d 0)
(u v 1)
where as I would write it differently. They are the same calculation, except that the transformation matrix and vertices have been transposed (column swapped with rows).