[hide]
...
//external variables
BYTE camera = 1;
int camera_x = 40;
int camera_y = 30;
int camera_width = 200;
int camera_height = 150;
//internal variables
float camera_vieworg[3];
float camera_viewangles[3];
...
...
//on the nearest enemy/player
camera_vieworg[0] = cl_entity_pointer->origin[0];
camera_vieworg[1] = cl_entity_pointer->origin[1];
camera_vieworg[2] = cl_entity_pointer->origin[2];
camera_viewangles[0] = cl_entity_pointer->angles[0];
camera_viewangles[1] = cl_entity_pointer->angles[1];
camera_viewangles[2] = cl_entity_pointer->angles[2];
...
in PostV_CalcRefdef:
void PostV_CalcRefdef(struct ref_params_s *pparams)
{
if(pparams->nextView==0)
{
//prevent collision with V_CalcSpectatorRefdef
if(camera==1&&pEngfuncs->GetLocalPlayer()->curstate.solid!=SOLID_NOT)
{
pparams->nextView = 1;
}
}
else if(pparams->nextView==1)
{
//prevent collision with V_CalcSpectatorRefdef
if(pEngfuncs->GetLocalPlayer()->curstate.solid!=SOLID_NOT)
{
pparams->nextView = 0;
pparams->onlyClientDraw = 0;
pparams->viewport[0] = camera_x;
pparams->viewport[1] = camera_y;
pparams->viewport[2] = camera_width;
pparams->viewport[3] = camera_height;
pparams->vieworg[0] = camera_vieworg[0];
pparams->vieworg[1] = camera_vieworg[1];
pparams->vieworg[2] = camera_vieworg[2];
pparams->viewangles[0] = camera_viewangles[0];
pparams->viewangles[1] = camera_viewangles[1];
pparams->viewangles[2] = camera_viewangles[2];
}
}
}
Just basic code, can be improved.
[/hide]