Hey,
i have just about got a third person camera working! and thought i would share the code for A) people who want to make a third person camera. and B) for people to help me make it better !
i Still need to implement collision detection for the camera so if you rotate into a wall it will stop and slide along it rather than go through it.
just pass the object id of the object you wish to follow in your main loop and you should be good to go
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;
float my,mx;
void ThirdPerson (int obj)
{
my = dbMouseMoveY ( );
mx = dbMouseMoveX ( );
float x = dbCameraAngleX ();
float y = dbCameraAngleY ();
float z = dbCameraAngleZ ();
dbPositionCamera( dbObjectPositionX(obj),dbObjectPositionY(obj),dbObjectPositionZ(obj) );
dbRotateCamera( dbObjectAngleX(obj),dbObjectAngleY(obj),dbObjectAngleZ(obj) );
dbPitchCameraDown (40);
dbMoveCamera( -300 );
if (dbMouseClick() == 2)
{
dbPointCamera (x,y,z);
fCameraAngleX = dbWrapValue ( fCameraAngleX + my * 0.4f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + mx * 0.4f );
dbPositionMouse (dbScreenWidth() /2, dbScreenHeight() /2);
dbXRotateCamera (fCameraAngleX );
dbYRotateObject (obj, fCameraAngleY);
dbYRotateCamera (fCameraAngleY );
dbHideMouse();
}
else
{
dbPointCamera (dbObjectPositionX (obj),dbObjectPositionY (obj), dbObjectPositionZ(obj));
dbPitchCameraUp (20);
dbShowMouse();
}
}