PS2 Linux Programming
Drawing 3D World Axes
This tutorial demonstrates the rendering of lines (using the line primitive of the GS) to display world and local axes. World axes are used as a useful debug feature to help visualise the location of objects in 3D space. Local axes are useful to help visualise the orientation of objects within a virtual world. The tutorial also demonstrates the rendering of different primitives (triangle strips and lines) using the same vector unit 1 program.
The VU1 program is the same as that used in the tutorial “Ambient Light and 3 Directional Coloured lights”, so the data that is sent to the VU must also be in the same format as used in that tutorial. To summarise, the data structure has the following layout: 4 qwords for the transformation matrix, 4 qwords for the world matrix, 1 qword for the scaling vector,3 qwords for the light directional vectors, 3 qwords for the light colours, 1 qword for the ambient light intensity and 1 qword for the GIFTag. Following the GIFTag is the vertex data in the format texture coordinate followed by normal, followed by position. Two vertices are needed to draw a line primitive, one at each end of the line.
In order to differentiate between the x, y and z axes they are drawn with different colours: red for the x axis, green for the y axis and blue for the z axis. The method of rendering the lines with the required colours is a bit of a “hack”. It is achieved by setting up three coloured lights (red, green and blue) mutually perpendicular to each other and configuring the x axis with normals that point directly at the red light, the y axis with normals that point directly at the green light and the z axis with normals that point directly at the blue light. The world matrix used in the lighting calculations for the lines is always set to the identity matrix so that the vertex normals always point to their respective light source.
The GIFTag is set to render a line primitive and the number of vertices expected by the GIF is set to 6, two vertices for each of the three lines to be rendered.
In order to render the axes the graphics packet in the structure outlined above must be constructed. As already stated, the world matrix is set to the identity matrix and the concatenated world-view-projection matrix is set to the coordinate system (or space) for the object being rendered. Drawing both world and local axes is demonstrated in the accompanying application.
This tutorial has demonstrated the rendering of world and local axes which are useful for debugging 3D applications. The tutorial also illustrates the rendering of two different GS primitives using the same VU micro program.
Dr Henry S Fortuna
University of Abertay Dundee