default_distance = 100
maxdistance = 300
mindistance = 50
minautopitch = 15
maxautopitch = 70

distance = distance - direction*18

if (distance < mindistance)
 distance = mindistance
 pitch = minautopitch
 min_pitch = 40
 max_pitch = 50
else if (distance > maxdistance)
 distance = maxdistance
 pitch = maxautopitch
 min_pitch = 60
 max_pitch = 90
else
 fraction = (distance-mindistance)/(maxdistance - mindistance)
 pitch = minautopitch + (maxautopitch - minautopitch) * fraction
 max_pitch = 90
 min_pitch = 40 + fraction*45
endif
endif 

# right-click-drag scrolling
do_edge_scroll = 1
if (mouse_move_x ~= 0)
 anchor_delta_x = -mouse_move_x*distance*0.05
 do_edge_scroll = 0
endif

if (mouse_move_y ~= 0)
 anchor_delta_y = -mouse_move_y*distance*0.05
 do_edge_scroll = 0
endif


#edge scrolling
if (do_edge_scroll ~= 0)
fraction_x = edge_distance_x/48
fraction_y = edge_distance_y/48

if (fraction_x < 1 and fraction_x > 0)
 anchor_delta_x = (1-fraction_x)/3
else if (fraction_x > -1 and fraction_x < 0)
 anchor_delta_x = -(1+fraction_x)/3
endif
endif

if (fraction_y < 1 and fraction_y > 0)
 anchor_delta_y = (1-fraction_y)/3
else if (fraction_y > -1 and fraction_y < 0)
 anchor_delta_y = -(1+fraction_y)/3
endif
endif
endif