Quote:
However, it is much more complicated than I thought.
on the surface it looks very complex I'd admit, but when you start to use matrices, especially in object from such as a matrix class, it becomes much, much simpler..
for example,
...
//set camera
glLoadIdentiy();
glLookAt(.. target ..)
... first object
glPushMatrix()..
glTranslate(x,y,z);
glRotate(1,0,0,90);
gl...
.. draw
glPop();
etc
would just simply be:
somewhere else:
camera.lookAt(.. target ..)
object.position() += velocity * time;
object.rotate(rotationalMomentum * time);
then in rendering:
//set camera
glLoadMatrix(camera.inverse());
glPushMatrix();
glMultMatrix(object);
.. draw
glPopMatrix();
etc.
imo much simpler, much easier.
The most important use of this idea, is to make rendering seperate from everything else (say, in a class).
That way, the code that says how an object is positioned and rotated does not need to go with the rendering setup/drawing code. The same for the camera. Some other code can set the camera, not the rendering code.
good old OO. [smile]
Further, if you do use operator overloading like I did in the example code, then things get doubly useful. Being able to rotate 3D and 4D vectors by matrices easily with *,*= and /,/= operators is really, really useful.
a really simple example (that would be really hard any other way)
say you have a space ship, X
it can rotate in any direction any way possible.
instantly you can't do this with glRotate, you need a matrix (some will say a quaternion but I think thats a bad idea).
So there is a class called SpaceShip, and inside there, is a matrix called 'matrix'.
Every frame, if the user is holding down the left arrow, then matrix.rotateZ(..) is called. To rotate the ship left. Simply. From that, pretty much infinite rotation angles are possible.
Say then, you wanted to fire a bullet.
Think about it, how on earth would you get the direction the bullet will travel if using glRotate, etc... You would probably end up using lots and lots and lots of cos/sin combinations. And it wouldn't be accurate still.
Well, in the example, it is:
bullet.velocity = Vector3(0,1,0) * matrix;
Thats it.
In 'ship space' 0,1,0 is forward, so [0,1,0]*matrix is forward in world space. (I'm assuming * won't apply a translation)
btw in this example, bullet.velocity / matrix would equal [0,1,0]