replace:
Code:
var area_x = 200;
var area_y = 100;
[...]
VECTOR temp1_pos, temp2_pos;

[...]

vec_set(mouse_pos, mouse_cursor);
temp1_pos.x = (screen_size.x - area_x) / 2;
temp2_pos.x = (screen_size.x + area_x) / 2;
mouse_pos.x = clamp(mouse_pos.x, temp1_pos.x, temp2_pos.x);
temp1_pos.y = (screen_size.y - area_y) / 2;
temp2_pos.y = (screen_size.y + area_y) / 2;
mouse_pos.y = clamp(mouse_pos.y, temp1_pos.y, temp2_pos.y);



by:
Code:
var radius = 80; //a circle of radius 100
[...]
VECTOR temp1_pos, temp2_pos;

[...]

vec_set(temp1_pos, mouse_cursor); //set temp1_pos to mouse_cursor coordinates

//set temp2_pos to middle of the screen
temp2_pos.x = screen_size.x/2;
temp2_pos.y = screen_size.y/2;
temp2_pos.z = 0; //don't forget this!! .z wont be at 0 initially, will turn in awkward values at vec_dist)

//mouse is outside circle
if( vec_dist( temp1_pos, temp2_pos ) > radius ) {
//compute new position on the circle
vec_diff(temp1_pos, temp1_pos, temp2_pos); //direction from temp2 to temp1
vec_normalize(temp1_pos, radius); //normalize to the radius
vec_add( temp1_pos, temp2_pos ); //add from screen center
vec_set( mouse_pos, temp1_pos );
}
else {
vec_set( mouse_pos, temp1_pos );
}



Last edited by Joozey; 07/09/09 12:52.

Click and join the 3dgs irc community!
Room: #3dgs