Following is my current camera code that allows for pan, tilt and zoom using the mouse. What I'm now trying to add is object detection so that the camera dosn't get blocked from viewing the player entity. However, I'm having no luck with this. In fact, when ever I try to set the camera postion relivtive to the target returned by c_trace I get a hard crash.
Any ideas?
if(mouse_right)
{
cam_ang.pan+=rotspd*mouse_force.x;
cam_ang.tilt+=rotspd*mouse_force.y;
cam_ang.tilt=clamp(cam_ang.tilt,minang,maxang);
}
// orbit no tilt
if(mouse_left)
{
cam_ang.pan+=rotspd*mouse_force.x;
}
// zoom with mousewheel
cam_dist-=integer(mickey.z);
cam_dist=clamp(cam_dist,mindist,maxdist);
// do some trig to find camera location and then aim it at pFocus
camera.x=my_entity.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.y=my_entity.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.z=my_entity.z+sin(cam_ang.tilt)*cam_dist;
vec_set(temp,my_entity.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);
// Find objects between player and camera. c_trace(my_entity.x,vector(camera.x,camera.y,camera.z),IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS|IGNORE_SPRITES);
if(trace_hit == 1)
{
vec_set(miscTemp,target);
//vec_diff(miscTemp,camera,target);
//vec_set(cameraTPos,target);
// offset from the wall along normal by the near clipping dist
//vec_normalize(normal,(camera.clip_near/2));
//vec_add(cameraTPos,normal);
} else {vec_set(miscTemp,vector(0,0,0));}