Code:
var camDist = 100;
var camMaxDist = 200;
var camMinDist = 60;
var camAngle = 15;
		VECTOR camGoal;
	var camSpeed = .7;
	var oldCamPos[3];
	
	while(1)
	{
		
		camDist = clamp(camDist + mickey.z*time_step/5,camMinDist,camMaxDist);
		vec_set(camGoal,vector(-camDist*cos(camAngle),0,camDist*sin(camAngle)));

		vec_rotate(camGoal,vector(ship.pan,ship.tilt,ship.roll)); 
		vec_add(camGoal,ship.x);
		
		vec_diff(temp,camGoal,camera.x);vec_scale(temp,time_step*camSpeed);
		vec_add(camera.x,temp);
		
		vec_set(camera.pan,ship.pan);
		
		wait(1);
	}

check out this code, it should do exactly what you wanted it to.

-No need for trig (it tends to mess up in 3d space games anyways)
-easy implementation of shaking cameras
-mouse wheel changes distance to ship
-hope it helps.


~"I never let school interfere with my education"~
-Mark Twain