var tile_size = 50;
var tile_z_offset = 0;
var editControlMouseWheelSpeed = 0.8; //Empfindlichkeit/Speed für Mausraddrehung
var editControlScrollSpeedRMB = 50; //Speed für rechtsklick scroll
var editControlScrollSpeedBorder = 25; //Speed für randscroll
var editControlScrollMarginPercent = 0.15; // %
var check_mouseclick = 0;
void clamp_all(ENTITY* obj)
{
tile_position.x = integer(tile_position.x);
tile_position.y = integer(tile_position.y);
tile_position.z = integer(tile_position.z);
tile_position.x = clamp(tile_position.x, -200,200);
tile_position.y = clamp(tile_position.y, -200,200);
tile_position.z = clamp(tile_position.z, 0,200);
obj.x = tile_position.x * tile_size;
obj.y = tile_position.y * tile_size;
obj.z = tile_position.z * tile_size;
}
void draw_cursor(ENTITY* obj)
{
// some mouse buttons are pressed
if (mouse_right || mouse_left)
{
// right button is pressed
if (mouse_right)
{
// adjust editor view for direct scrolling
mouse_mode = 4;
camera->x -= mouse_force.x * editControlScrollSpeedRMB * time_step;
camera->y -= mouse_force.y * editControlScrollSpeedRMB * time_step;
}
}
else
{
// do 3d cursor placement with the mouse
// CB: the following code calculates the tile_position for the mouse cursor
// get 3d points and direction of line, which pierces the screen at mouse position in camera
VECTOR v1, v2, dir;
{
vec_set(&v1, vector(mouse_pos.x, mouse_pos.y, 0));
vec_set(&v2, vector(mouse_pos.x, mouse_pos.y, 99999));
vec_for_screen(&v1, camera);
vec_for_screen(&v2, camera);
vec_diff(&dir, &v2, &v1);
}
var d = vec_dot(vector(0,1,0), &dir);
if (abs(d) != 0) // not parallel to plane
{
// get intersection point with plane
VECTOR dirPlaneFrom;
vec_diff(&dirPlaneFrom, &v1, obj.x);
var n = vec_dot(vector(0,1,0), &dirPlaneFrom);
VECTOR ip;
vec_set(&ip, &dir);
vec_scale(&ip, -n / d);
vec_add(&ip, &v1);
// transform into tile space
tile_position.x = integer((ip.x + tile_size/2) / tile_size);
tile_position.y = integer((ip.y + tile_size/2) / tile_size);
tile_position.z = obj->z / tile_size;
}
// CB: the following code changes the tile_position.z (height) with the mouse wheel!
tile_position.z += sign((int)(mickey.z * editControlMouseWheelSpeed * time_step));
check_mouseclick = 0;
}
clamp_all(obj);
}