default_distance = 375
maxdistance = 1100
mindistance = 101
minautopitch = 25
maxautopitch = 90

distance = distance - 25*direction

if (distance < mindistance)
 distance = mindistance
 pitch = minautopitch
else if (distance > maxdistance)
 distance = maxdistance
 pitch = maxautopitch
else
 fraction = (distance-mindistance)/(maxdistance - mindistance)
 pitch = minautopitch + (maxautopitch - minautopitch) * fraction
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
if (fraction_x < 1 and fraction_x > 0)
 anchor_delta_x = (1-fraction_x) * 7 * (distance/maxdistance)
else if (fraction_x > -1 and fraction_x < 0)
 anchor_delta_x = -(1+fraction_x) * 7 * (distance/maxdistance)
endif
endif

fraction_y = edge_distance_y/48
if (fraction_y < 1 and fraction_y > 0)
 anchor_delta_y = (1-fraction_y) * 7 * (distance/maxdistance)
else if (fraction_y > -1 and fraction_y < 0)
 anchor_delta_y = -(1+fraction_y) * 7 * (distance/maxdistance)

endif
endif
endif