PS2 Linux Programming


Cube With User Controlled Movement





This tutorial demonstrated the movement of a cube around the viewer. It also demonstrates the visual artefacts that occur when no frustum clipping is performed.



Example Code


In the example code the rotating cube is positioned at (0, 0, -8), the camera is positioned at the origin looking directly down the negative z axis. The cube rotates continuously on its local y-axis. The DPad left and right buttons can be used to rotate the cube around the viewer. The DPad controls are pressure sensitive, so the harder the pressure the faster the cube will rotate round the viewer.


The code which controls the movement of the cube is repeated below for clarity:



// Set up a world matrix that rotates the cube about it's own axis,

// and then again around the origin.

static float sfRotOrigin = 0.0f;

static float sfRotLocal = 0.0f;


sfRotOrigin += pad[0].pressures[PAD_PLEFT] * 0.1f;

sfRotOrigin -= pad[0].pressures[PAD_PRIGHT] * 0.1f;

sfRotLocal += 0.03f;


Matrix4x4 matWorld, matTrans, matRotLocal, matRotOrigin;


matTrans.Translation(0, 0, -8.0f);




matWorld = matRotLocal * matTrans * matRotOrigin;


// You should be familiar with the idea of building 3D transforms from

// the World * View * Projection matrices

Matrix4x4 matWVP = matWorld * matViewProj;



The combined world, view and projection matrix is passed to the vector unit to be used for processing the vertex data.



Feature Illustration



The purpose of the tutorial is to illustrate what happens when no frustum clipping is performed. Press and hold down the left or right direction buttons to rotate the cube out of view and round the viewer. Large polygons will flash on screen as the cube moves to the left and right of the viewer. When the cube is directly behind the viewer, the it will be rendered on screen but the z-sorting of the polygons is seen to be wrong since the z values have been inverted.





This tutorial has demonstrated the movement of a cube around a stationary viewer. The visual artefacts caused by the lack of frustum clipping have been demonstrated.



Dr Henry S Fortuna

University of Abertay Dundee