What l need help on is implementing the camera when using matrices. If anyone has a guide on this that would be great. ...
I think the net is cluttered with stuff like this but is perhaps not the
best place to grasp deeper knowledge from. A book is much better in this
case esp. if you want to do things from first principles. And there is no
other book like 'Computer Graphics: Principles and Practice' (2nd Edition in
C) within this regard. Matrix transformation and building viewing
transformations, as well as perspective transformation are described in there
quite well from various different angles. It's the bible of Computer Graphics.
... Also can you expand on the frustum/culling or point me to a tutorial? ...
These days frustum culling/clipping is done in an normalized camera/screen
space which is often called clip-space, since clipping a polygon against the
transformed frustum becomes much easier because the plane equations bounding
the frustum become trivial. However, the old-school way of clipping is done
in object-space, which is more difficult due to the non-trivial plane
equations of the frustum. Anyhow. If you try to cull/clip your polygons
against the object-space frustum, you basically solve a collision detection
problem.
Given you have already eliminated many polygons which will not collide with a
give one (using sphere tests etc.). For the remaining ones you have to do (at
the end of the day) an intersection test to determine if a given polygon does
indeed intersect the one in question. So how to do it? Here is a not so
difficult method, it's pure geometrical.
Out of my head...
Part (a):
Given we want to check polygon B against A (both being convex) for collision
resp. intersection. The first thing we do is to look if polygon B intersects
the plane of A (the plane in which A lies), which can easily be checked by
inserting the points of B into the plane equation for A and watching the
signs. If the signs are all the same, then polygon B lies entirely on one side
of polygon A and a such there can't be any intersection. Now if this condition
doesn't hold there is at least one point of B on the other side of A leading
to two intersection points. Both points can be computed by forming the
respective parametrized line equations and inserting them into the plane
equation for A and solving for the parameter, each. The parameter is then used
to compute the intersection point by inserting it into the line equation,
for each line respectively.
Part (b):
Now we have to check if any of the two intersection points fall within the
polygon of A. If one does at least, we found a collision. Well, both points
already lay in the plane of A, but they doesn't necessarily fall within the
bounds of A. So we need to make a 3d containment test, which is the expensive
part. How to do it? Well, when does any of the two intersection points fall
within A? Imagine we construct a plane from each edge of the polygon of A
having a normal perpendicular to the normal of the A. These planes will bound
the interior of A. The test to be made now is simply to check if any of the
two intersection points lay on the same side (same sign) of all the planes
(similar like in Part (a)). If any one does, then this intersection point
falls within A, hence, a collision. The edge planes can easily be computed by
taking the cross-product of the plane's normal of A and an edge of A, for each
edge.
That's it. You just have to organize all the polygons and then test them
against each other. So if you have a wall and a cube for example, you would
simply take each polygon of the cube and test it against the polygon
representing the wall.
Any flaws? For sure. Always. One issue with this method is that a fast moving
polygon may pass another one in one frame without getting detected. However,
there is a way, yet computationally expensive one, to resolved this issue. If
you grow with the method you will get there ... naturally.