PS2 Linux Programming

 

Simple Racing Car Demo

 

Introduction

 

This application demonstrates a prototype formula 1 type racing game with very basic car controls and movements. Two MilkShape3D ASCII 3D models are used, one for the track and one for the car.

 

 

The Example Code

 

The application uses the previously described 3D API and loads all the models, textures in the normal manner. The camera position and orientation is derived from the car position with the camera being positioned behind and above the car, looking over the car to the road in front of the car. The camera matrix is generated using the method CPipeline::SetCameraMatrix(const Matrix4x4 & Base) which is given below.

 

 

void CPipeline::SetCameraMatrix(const Matrix4x4 & Base)

{

     Vector4 To, From, Up;

    

     Up = Vector4(0.0f, 1.0f, 0.0f, 1.0f);

    

     From = Vector4(Base(3,0)-4*Base(2,0), 4.0f, Base(3,2)-4*Base(2,2), 1.0f);

    

     To = Vector4(Base(3,0)+3*Base(2,0), 0.0f, Base(3,2)+3*Base(2,2), 1.0f);

    

     m_Camera.LookAt(From, To, Up);

    

     m_ViewProjection = m_Camera * m_Projection;

    

}

 

The input parameter of this method will be the world matrix for the car. From this matrix the Up, From and To vectors for the camera are derived as is the camera matrix itself.

 

Car movement information is obtained from the control pads and the car position is updated as necessary. Following this the car and track are rendered together with some diagnostic text.

 

 

Running The Applications

 

On running the application the user is presented with a car sitting on a race track. The car is moved forwards with the CROSS button and the left and right DPADS are used to steer the car round the track.

 

 

Conclusions

 

As will be seen this is a basic application. There are however numerous ways to extend this application by, for example, improving the movement characteristic of the car, and this is left up to the reader to investigate.

 

 

Dr Henry S Fortuna

University of Abertay Dundee

h.s.fortuna@abertay.ac.uk