function clamp_to_view(VECTOR* vec)
{
var hull_h, hull_v;
VECTOR temp_vec, h1, h2, v1, v2;
vec_set(temp_vec.x,vec.x);
vec_to_screen(temp_vec.x,camera);
// set horizontal border position
vec_set(h1.x,vector((camera_border * 0.5),temp_vec.y,temp_vec.z));
vec_set(h2.x,vector(screen_size.x - (camera_border * 0.5),temp_vec.y,temp_vec.z));
// set vertical border position
vec_set(v1.x,vector(temp_vec.x,0,temp_vec.z));
vec_set(v2.x,vector(temp_vec.x,screen_size.y,temp_vec.z));
// set border position to world value
vec_for_screen(h1.x,camera);
vec_for_screen(h2.x,camera);
vec_for_screen(v1.x,camera);
vec_for_screen(v2.x,camera);
// get hull size
hull_h = (vec_dist(vector(my.min_x,0,0),vector(my.max_x,0,0)) / 2);
hull_v = (vec_dist(vector(0,my.min_y,0),vector(0,my.max_y,0)) / 2);
// clamp to on-screen position
vec.x = clamp(vec.x,h1.x + hull_h,h2.x - hull_h);
vec.y = clamp(vec.y,v2.y + hull_v,v1.y - hull_v);
}