CSC303 GameDev 2009 Class Test
Question 1 (4+2+2+4 = 12 marks)
a. Explain the life cycle of an XNA game (including the game loop), and indicate what kinds of thing should be taken care of in each of the sections.
b. What is GameTime, and why is it useful?
c. How might a game compensate if it found itself running too slowly on particular hardware?
d. What is a GameComponent, and how was it used in your course?
I thought it was important that the Update cycle had to update the state of the world without relying on the fact that it may or may not be rendered. Loading and Unloading content also has plenty to do with ensuring that the objects are passed over and cached in GPU memory, and, e.g. textures may need to be resampled at various resolutions. Loading and Unloading content can occur mid-game, eg. when changing to a new level.
b and c: the essential thing you should explain is that by making movement and rotations depend on elapsed time between frames, you decouple the effective speed of the game from the speed of the system. There are many ways to compensate if your game is running slowly: skip drawing, reduce the frustum depth, go for a simpler shading model.
Question 2 (6 marks)
Explain the XNA 3D coordinate system, with particular reference to the statement "XNA is a right- handed Y-up system with row vectors on the left". What other alternatives are you aware of?
See my notes on the XNA SIG group. The row vectors refers to the vertices in the model or object, nothing in the matrix.
Question 3 (4+2+2+2+8+2 = 20 marks)
a. What is a transform matrix, and what separate pieces of information does it encode?
b. Why is the associativity of matrix multiplication so important in high-performance 3D graphics?
c. What is the usual decomposition of responsibilities between the CPU and the GPU?
d. Explain the role of each of the Model.Root, the World, the View, and the Projection matrices.
e. What is the viewing frustum?
A few people confused the transform matrix and the translation matrix. The matrix simultaneously holds rotation (on three axis), scale (in three dimensions), and translation (x, y and z).
Part b seemed to miss the essential heart of what all this stuff is about. The objective is to ultimately figure out where each vertex (and there can be many hundreds of thousands in a scene) should map onto
the screen (the vertex shader), and then to assign each a colour based either on texture or other lighting calculations (the pixel shader). Every vertex (conceptually) has to undergo repeated transforms to achieve this ((((v * m1) * m2) * m3) * m4) BUT the key idea is that because of the associativity we can instead implement v * (m1 * m2 * m3 * m4). i.e. we can precompute a "composite transform", once only, of all the operations before we even start thinking about the vertices. Now every vertex just has to go through one "resultant" matrix.
We generally do the matrix * matrix work in the CPU and get the composite matrix. The GPU is optimized to push large numbers of vertices through our single composite matrix. (vertex * Matrix).
There was confusion around associativity and commutivity. Matrix multiplication is associative, it is not commutative!
The frustum is created on the GPU from a combination of the camera View and Projection matrixes. It is used to optimize pixel shading by early discarding of pixels which are outside the frustum.
Question 4 (6 marks)
Your aeroplane model is on the runway at origin, facing away from you. You wish to put it 10 units in the air, heading to your right, and 100 units away from the origin. Write some XNA code to construct the World transform you'd need to do this.
You have to do the rotation first, then the translation. And because it is "row vectors from the left", that means that the transforms are written left-to-right in the order that the operations will be applied.
world = someRotation * someTranslation;
You also need to know that when looking down the axis from positive towards the origin, positive angles rotate things anticlockwise. So rotating this aeroplane about the Y axis needs a negative 90 degree angle. (the angle has to be expressed in radians, of course!)
Question 5 (3+3 = 6 Marks)
a. In your 2D games, what is a spritesheet and how is it used?
b. In your 2D games, how was the lifecycle of many enemy ships objects managed?
Question 5 (6+4 = 10 marks)
a. Describe the structure of a rigged model, in particular, how the vertices, meshes, and bones relate to one another.
b. Model drawing usually starts with two lines of code shown below. Explain their purpose:
Matrix[] mms = new Matrix[TheModel.Bones.Count];
TheModel.CopyAbsoluteBoneTransformsTo(mms);
The essential thing here is that the model has a heirarchical bone structure, and the impact on a specific vertex in a mesh will be the composite effect of all the transforms at each of the bones / joints leading to the vertext. So the vertices in RuBot's paddle are subject to what is occuring at the pelvis, the next, and the cranium joints. This code walks the skeleton tree, and pre-computes the total skeleton translation of all the sub-translations.
A general comment / hint
Your ability to express your thoughts elegantly and cleanly is often poor. Pause for a moment and ask
"what is the essential, high-level crux of this idea?" Then make sure you get that central idea across briefly and concisely.