paint: cleanup
This commit is contained in:
+53
-53
@@ -7,7 +7,7 @@ bool camera_controls_down = false;
|
||||
|
||||
static bool camera_wrap_mouse() {
|
||||
if (mouse_view_x() < 0 || mouse_view_x() > sys_w() || mouse_view_y() < 0 || mouse_view_y() > sys_h()) {
|
||||
if (!config_raw->wrap_mouse || !camera_controls_down) {
|
||||
if (!g_config->wrap_mouse || !camera_controls_down) {
|
||||
return false;
|
||||
}
|
||||
if (mouse_view_x() < 0) {
|
||||
@@ -34,7 +34,7 @@ static void camera_orbit_action(bool modif, bool default_keymap) {
|
||||
camera_object_t *camera = scene_camera;
|
||||
camera_redraws = 2;
|
||||
|
||||
if (context_raw->camera_pivot == CAMERA_PIVOT_CURSOR) {
|
||||
if (g_context->camera_pivot == CAMERA_PIVOT_CURSOR) {
|
||||
static f32 pivot_x = 0;
|
||||
static f32 pivot_y = 0;
|
||||
static f32 pivot_z = 0;
|
||||
@@ -44,23 +44,23 @@ static void camera_orbit_action(bool modif, bool default_keymap) {
|
||||
operator_shortcut(any_map_get(config_keymap, "action_rotate"), SHORTCUT_TYPE_STARTED) || (mouse_started("right") && !modif && default_keymap);
|
||||
if (rotate_started) {
|
||||
util_render_pick_pos_nor_tex();
|
||||
pivot_valid = math_abs(context_raw->posx_picked) < 50 && math_abs(context_raw->posy_picked) < 50 && math_abs(context_raw->posz_picked) < 50;
|
||||
pivot_valid = math_abs(g_context->posx_picked) < 50 && math_abs(g_context->posy_picked) < 50 && math_abs(g_context->posz_picked) < 50;
|
||||
if (pivot_valid) {
|
||||
pivot_x = context_raw->posx_picked;
|
||||
pivot_y = context_raw->posy_picked;
|
||||
pivot_z = context_raw->posz_picked;
|
||||
pivot_x = g_context->posx_picked;
|
||||
pivot_y = g_context->posy_picked;
|
||||
pivot_z = g_context->posz_picked;
|
||||
}
|
||||
}
|
||||
|
||||
if (pivot_valid) {
|
||||
f32 angle_x = -mouse_movement_x / 100.0 * config_raw->camera_rotation_speed;
|
||||
f32 angle_y = -mouse_movement_y / 100.0 * config_raw->camera_rotation_speed;
|
||||
f32 angle_x = -mouse_movement_x / 100.0 * g_config->camera_rotation_speed;
|
||||
f32 angle_y = -mouse_movement_y / 100.0 * g_config->camera_rotation_speed;
|
||||
|
||||
transform_rotate(camera->base->transform, vec4_z_axis(), angle_x);
|
||||
vec4_t right = camera_object_right_world(camera);
|
||||
transform_rotate(camera->base->transform, right, angle_y);
|
||||
vec4_t up_world = camera_object_up_world(camera);
|
||||
if (up_world.z < 0 && !config_raw->camera_upside_down) {
|
||||
if (up_world.z < 0 && !g_config->camera_upside_down) {
|
||||
transform_rotate(camera->base->transform, right, -angle_y);
|
||||
angle_y = 0.0;
|
||||
}
|
||||
@@ -81,11 +81,11 @@ static void camera_orbit_action(bool modif, bool default_keymap) {
|
||||
|
||||
f32 dist = camera_distance();
|
||||
transform_move(camera->base->transform, camera_object_look_world(camera), dist);
|
||||
transform_rotate(camera->base->transform, vec4_z_axis(), -mouse_movement_x / 100.0 * config_raw->camera_rotation_speed);
|
||||
transform_rotate(camera->base->transform, camera_object_right_world(camera), -mouse_movement_y / 100.0 * config_raw->camera_rotation_speed);
|
||||
transform_rotate(camera->base->transform, vec4_z_axis(), -mouse_movement_x / 100.0 * g_config->camera_rotation_speed);
|
||||
transform_rotate(camera->base->transform, camera_object_right_world(camera), -mouse_movement_y / 100.0 * g_config->camera_rotation_speed);
|
||||
vec4_t up_world = camera_object_up_world(camera);
|
||||
if (up_world.z < 0 && !config_raw->camera_upside_down) {
|
||||
transform_rotate(camera->base->transform, camera_object_right_world(camera), mouse_movement_y / 100.0 * config_raw->camera_rotation_speed);
|
||||
if (up_world.z < 0 && !g_config->camera_upside_down) {
|
||||
transform_rotate(camera->base->transform, camera_object_right_world(camera), mouse_movement_y / 100.0 * g_config->camera_rotation_speed);
|
||||
}
|
||||
transform_move(camera->base->transform, camera_object_look_world(camera), -dist);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ static void camera_rotate_action(bool modif, bool default_keymap) {
|
||||
transform_t *t = context_main_object()->base->transform;
|
||||
vec4_t up = transform_up(t);
|
||||
|
||||
if (context_raw->camera_pivot == CAMERA_PIVOT_CURSOR) {
|
||||
if (g_context->camera_pivot == CAMERA_PIVOT_CURSOR) {
|
||||
static f32 pivot_x = 0;
|
||||
static f32 pivot_y = 0;
|
||||
static f32 pivot_z = 0;
|
||||
@@ -106,24 +106,24 @@ static void camera_rotate_action(bool modif, bool default_keymap) {
|
||||
operator_shortcut(any_map_get(config_keymap, "action_rotate"), SHORTCUT_TYPE_STARTED) || (mouse_started("right") && !modif && default_keymap);
|
||||
if (rotate_started) {
|
||||
util_render_pick_pos_nor_tex();
|
||||
pivot_valid = math_abs(context_raw->posx_picked) < 50 && math_abs(context_raw->posy_picked) < 50 && math_abs(context_raw->posz_picked) < 50;
|
||||
pivot_valid = math_abs(g_context->posx_picked) < 50 && math_abs(g_context->posy_picked) < 50 && math_abs(g_context->posz_picked) < 50;
|
||||
if (pivot_valid) {
|
||||
pivot_x = context_raw->posx_picked;
|
||||
pivot_y = context_raw->posy_picked;
|
||||
pivot_z = context_raw->posz_picked;
|
||||
pivot_x = g_context->posx_picked;
|
||||
pivot_y = g_context->posy_picked;
|
||||
pivot_z = g_context->posz_picked;
|
||||
}
|
||||
}
|
||||
|
||||
if (pivot_valid) {
|
||||
f32 angle_x = (mouse_movement_x / 120.0) * config_raw->camera_rotation_speed;
|
||||
f32 angle_y = (mouse_movement_y / 120.0) * config_raw->camera_rotation_speed;
|
||||
f32 angle_x = (mouse_movement_x / 120.0) * g_config->camera_rotation_speed;
|
||||
f32 angle_y = (mouse_movement_y / 120.0) * g_config->camera_rotation_speed;
|
||||
vec4_t right = camera_object_right_world(camera);
|
||||
|
||||
transform_rotate(t, up, angle_x);
|
||||
transform_rotate(t, right, angle_y);
|
||||
transform_build_matrix(t);
|
||||
vec4_t tup = transform_up(t);
|
||||
if (tup.z < 0 && !config_raw->camera_upside_down) {
|
||||
if (tup.z < 0 && !g_config->camera_upside_down) {
|
||||
transform_rotate(t, right, -angle_y);
|
||||
angle_y = 0.0;
|
||||
}
|
||||
@@ -141,31 +141,31 @@ static void camera_rotate_action(bool modif, bool default_keymap) {
|
||||
return;
|
||||
}
|
||||
|
||||
transform_rotate(t, up, (mouse_movement_x / 120.0) * config_raw->camera_rotation_speed);
|
||||
transform_rotate(t, up, (mouse_movement_x / 120.0) * g_config->camera_rotation_speed);
|
||||
vec4_t right = camera_object_right_world(camera);
|
||||
transform_rotate(t, right, (mouse_movement_y / 120.0) * config_raw->camera_rotation_speed);
|
||||
transform_rotate(t, right, (mouse_movement_y / 120.0) * g_config->camera_rotation_speed);
|
||||
transform_build_matrix(t);
|
||||
vec4_t tup = transform_up(t);
|
||||
if (tup.z < 0 && !config_raw->camera_upside_down) {
|
||||
transform_rotate(t, right, -(mouse_movement_y / 120.0) * config_raw->camera_rotation_speed);
|
||||
if (tup.z < 0 && !g_config->camera_upside_down) {
|
||||
transform_rotate(t, right, -(mouse_movement_y / 120.0) * g_config->camera_rotation_speed);
|
||||
}
|
||||
}
|
||||
|
||||
f32 camera_get_zoom_speed() {
|
||||
i32 sign = config_raw->zoom_direction == ZOOM_DIRECTION_VERTICAL_INVERTED || config_raw->zoom_direction == ZOOM_DIRECTION_HORIZONTAL_INVERTED ||
|
||||
config_raw->zoom_direction == ZOOM_DIRECTION_VERTICAL_HORIZONTAL_INVERTED
|
||||
i32 sign = g_config->zoom_direction == ZOOM_DIRECTION_VERTICAL_INVERTED || g_config->zoom_direction == ZOOM_DIRECTION_HORIZONTAL_INVERTED ||
|
||||
g_config->zoom_direction == ZOOM_DIRECTION_VERTICAL_HORIZONTAL_INVERTED
|
||||
? -1
|
||||
: 1;
|
||||
camera_object_t *camera = scene_camera;
|
||||
f32 fov_adjust = camera->data->fov;
|
||||
return (config_raw->camera_zoom_speed * sign) / (float)fov_adjust;
|
||||
return (g_config->camera_zoom_speed * sign) / (float)fov_adjust;
|
||||
}
|
||||
|
||||
f32 camera_get_zoom_delta() {
|
||||
return config_raw->zoom_direction == ZOOM_DIRECTION_VERTICAL ? -mouse_movement_y
|
||||
: config_raw->zoom_direction == ZOOM_DIRECTION_VERTICAL_INVERTED ? -mouse_movement_y
|
||||
: config_raw->zoom_direction == ZOOM_DIRECTION_HORIZONTAL ? mouse_movement_x
|
||||
: config_raw->zoom_direction == ZOOM_DIRECTION_HORIZONTAL_INVERTED ? mouse_movement_x
|
||||
return g_config->zoom_direction == ZOOM_DIRECTION_VERTICAL ? -mouse_movement_y
|
||||
: g_config->zoom_direction == ZOOM_DIRECTION_VERTICAL_INVERTED ? -mouse_movement_y
|
||||
: g_config->zoom_direction == ZOOM_DIRECTION_HORIZONTAL ? mouse_movement_x
|
||||
: g_config->zoom_direction == ZOOM_DIRECTION_HORIZONTAL_INVERTED ? mouse_movement_x
|
||||
: -(mouse_movement_y - mouse_movement_x);
|
||||
}
|
||||
|
||||
@@ -235,17 +235,17 @@ static void camera_fly_action(bool modif_key) {
|
||||
}
|
||||
}
|
||||
|
||||
f32 d = sys_delta() * fast * camera_ease * 2.0 * ((move_forward || move_backward) ? config_raw->camera_zoom_speed : config_raw->camera_pan_speed);
|
||||
f32 d = sys_delta() * fast * camera_ease * 2.0 * ((move_forward || move_backward) ? g_config->camera_zoom_speed : g_config->camera_pan_speed);
|
||||
if (d > 0.0) {
|
||||
transform_move(camera->base->transform, camera_dir, d);
|
||||
if (context_raw->camera_type == CAMERA_TYPE_ORTHOGRAPHIC) {
|
||||
viewport_update_camera_type(context_raw->camera_type);
|
||||
if (g_context->camera_type == CAMERA_TYPE_ORTHOGRAPHIC) {
|
||||
viewport_update_camera_type(g_context->camera_type);
|
||||
}
|
||||
}
|
||||
|
||||
camera_redraws = 2;
|
||||
transform_rotate(camera->base->transform, vec4_z_axis(), -mouse_movement_x / 200.0 * config_raw->camera_rotation_speed);
|
||||
transform_rotate(camera->base->transform, camera_object_right(camera), -mouse_movement_y / 200.0 * config_raw->camera_rotation_speed);
|
||||
transform_rotate(camera->base->transform, vec4_z_axis(), -mouse_movement_x / 200.0 * g_config->camera_rotation_speed);
|
||||
transform_rotate(camera->base->transform, camera_object_right(camera), -mouse_movement_y / 200.0 * g_config->camera_rotation_speed);
|
||||
}
|
||||
|
||||
void camera_init() {
|
||||
@@ -253,7 +253,7 @@ void camera_init() {
|
||||
}
|
||||
|
||||
i32 camera_index() {
|
||||
return context_raw->view_index_last > 0 ? 1 : 0;
|
||||
return g_context->view_index_last > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
void camera_pan_action(bool modif, bool default_keymap) {
|
||||
@@ -261,8 +261,8 @@ void camera_pan_action(bool modif, bool default_keymap) {
|
||||
if (operator_shortcut(any_map_get(config_keymap, "action_pan"), SHORTCUT_TYPE_DOWN) || (mouse_down("middle") && !modif && default_keymap)) {
|
||||
camera_redraws = 2;
|
||||
f32 f = 150 * (1.0 / (float)(camera_distance() / 4.0));
|
||||
vec4_t look = vec4_mult(transform_look(camera->base->transform), mouse_movement_y / (float)f * config_raw->camera_pan_speed);
|
||||
vec4_t right = vec4_mult(transform_right(camera->base->transform), -mouse_movement_x / (float)f * config_raw->camera_pan_speed);
|
||||
vec4_t look = vec4_mult(transform_look(camera->base->transform), mouse_movement_y / (float)f * g_config->camera_pan_speed);
|
||||
vec4_t right = vec4_mult(transform_right(camera->base->transform), -mouse_movement_x / (float)f * g_config->camera_pan_speed);
|
||||
camera->base->transform->loc = vec4_add(camera->base->transform->loc, look);
|
||||
camera->base->transform->loc = vec4_add(camera->base->transform->loc, right);
|
||||
camera_origins->buffer[camera_index()]->v = vec4_add(camera_origins->buffer[camera_index()]->v, look);
|
||||
@@ -273,22 +273,22 @@ void camera_pan_action(bool modif, bool default_keymap) {
|
||||
|
||||
void camera_set_pivot_center_to_mouse() {
|
||||
util_render_pick_pos_nor_tex();
|
||||
bool is_mesh = math_abs(context_raw->posx_picked) < 50 && math_abs(context_raw->posy_picked) < 50 && math_abs(context_raw->posz_picked) < 50;
|
||||
bool is_mesh = math_abs(g_context->posx_picked) < 50 && math_abs(g_context->posy_picked) < 50 && math_abs(g_context->posz_picked) < 50;
|
||||
if (!is_mesh) {
|
||||
return;
|
||||
}
|
||||
|
||||
vec4_box_t *o = camera_origins->buffer[camera_index()];
|
||||
o->v.x = context_raw->posx_picked;
|
||||
o->v.y = context_raw->posy_picked;
|
||||
o->v.z = context_raw->posz_picked;
|
||||
o->v.x = g_context->posx_picked;
|
||||
o->v.y = g_context->posy_picked;
|
||||
o->v.z = g_context->posz_picked;
|
||||
|
||||
camera_redraws = 2;
|
||||
camera_object_t *camera = scene_camera;
|
||||
vec4_t up = vec4_mult(transform_up(camera->base->transform), camera_distance());
|
||||
camera->base->transform->loc.x = context_raw->posx_picked;
|
||||
camera->base->transform->loc.y = context_raw->posy_picked;
|
||||
camera->base->transform->loc.z = context_raw->posz_picked;
|
||||
camera->base->transform->loc.x = g_context->posx_picked;
|
||||
camera->base->transform->loc.y = g_context->posy_picked;
|
||||
camera->base->transform->loc.z = g_context->posz_picked;
|
||||
camera->base->transform->loc = vec4_add(camera->base->transform->loc, up);
|
||||
camera_object_build_mat(camera);
|
||||
}
|
||||
@@ -300,7 +300,7 @@ void camera_update(void *_) {
|
||||
|
||||
bool modif_key = keyboard_down("alt") || keyboard_down("shift") || keyboard_down("control");
|
||||
bool modif = modif_key || string_equals(any_map_get(config_keymap, "action_rotate"), "middle");
|
||||
bool default_keymap = string_equals(config_raw->keymap, "default.json");
|
||||
bool default_keymap = string_equals(g_config->keymap, "default.json");
|
||||
|
||||
if (operator_shortcut(any_map_get(config_keymap, "action_rotate"), SHORTCUT_TYPE_STARTED) ||
|
||||
operator_shortcut(any_map_get(config_keymap, "action_zoom"), SHORTCUT_TYPE_STARTED) ||
|
||||
@@ -321,7 +321,7 @@ void camera_update(void *_) {
|
||||
return;
|
||||
}
|
||||
|
||||
camera_controls_t controls = context_raw->camera_controls;
|
||||
camera_controls_t controls = g_context->camera_controls;
|
||||
|
||||
if (controls == CAMERA_CONTROLS_ORBIT &&
|
||||
(operator_shortcut(any_map_get(config_keymap, "action_rotate"), SHORTCUT_TYPE_DOWN) || (mouse_down("right") && !modif && default_keymap))) {
|
||||
@@ -346,15 +346,15 @@ void camera_update(void *_) {
|
||||
|
||||
if (operator_shortcut(any_map_get(config_keymap, "rotate_envmap"), SHORTCUT_TYPE_DOWN)) {
|
||||
camera_redraws = 2;
|
||||
context_raw->envmap_angle -= mouse_movement_x / 100.0;
|
||||
g_context->envmap_angle -= mouse_movement_x / 100.0;
|
||||
}
|
||||
|
||||
if (camera_redraws > 0) {
|
||||
camera_redraws--;
|
||||
context_raw->ddirty = 2;
|
||||
g_context->ddirty = 2;
|
||||
|
||||
if (context_raw->camera_type == CAMERA_TYPE_ORTHOGRAPHIC) {
|
||||
viewport_update_camera_type(context_raw->camera_type);
|
||||
if (g_context->camera_type == CAMERA_TYPE_ORTHOGRAPHIC) {
|
||||
viewport_update_camera_type(g_context->camera_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user