Game FAQ: Camera Class for PS2 Dev Kit

Question: John, could you please post your camera class for the Playstation2 Development Kit?

Sure. At the links listed below you’ll find the zipped files for my camera.h and camera.cpp files. They have been very useful for me in completing my course work, because they save me the effort of rewriting the camera controls each time.

But first, here is a video of the camera class in action:

And now the zipped files:

AlaskaJohn’s Camera Class for PS2 [zip]: This camera class uses the basic framework for PS2 development as provided by Henry Fortuna. Specifically:

  • #include “PS2Defines.h”
  • #include “ps2maths.h”
  • #include “ps2matrix4x4.h”
  • #include “ps2vector4.h”

AlaskaJohn’s Camera Class for D3D9 [zip]: This camera class is the original that I wrote in October of 2007. It uses basic DirectX/D3D functionality and requires that you pass the D3D device.

  • IDirect3DDevice9* Device;

Also note the following for both versions:

  • The class requires a “correctly” calculated upVector (perpendicular to the vector between camera position and camera lookat)
  • If you initialize or update cameraPosition and/or cameraLookAt without defining upVector one will be calculated (best guess) for you based on the positive y-axis (the functions are overloaded)
  • All angles are expected in degrees.

The functions use quaternion math to do the majority of the calculations, but I am not using any of the built-in quaternion functions. The code is also full of comments in addition to various “commented out” code that although completely useless for all practical purposes, might allude to my thought processes.

The following camera movement functions are publicly available through the class:


//Camera Administration
void diagnostics(void);
void init(Vector4 location, Vector4 lookAt);
void init(Vector4 location, Vector4 lookAt, Vector4 up);
void Cleanup(void);
//Camera Position Translation Controls
void zoom(float value);
//Camera Position and LookAt Translation Controls
void moveIn(float value);
void pan(float horizontal, float vetical); //vertical is similar to lift
//Camera Rotation Controls
void pivit(float theat); //same as aircraft yaw
void tilt(float theta); //same as aircraft pitch
void roll(float theta);
//Orbital Controls
void geoSynchronousOrbit(float theta);
void polarOrbit(float theta);
//Manual Camera Updates
void definePosition(Vector4 newLocation);
void definePosition(Vector4 newLocation, Vector4 up);
void defineLookAt(Vector4 newLocation);
void defineLookAt(Vector4 newLocation, Vector4 up);
//Keyboard Controls
void checkKeyboard();

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.