From 9c5e96503e383a9b6f677e4a5ecd031849d1cce0 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Fri, 3 May 2019 14:35:41 +1000 Subject: [PATCH] Implemented Scale Tool --- src/game/editor.c | 74 +++++++++++++++++++++++++++++++++++------------ src/game/editor.h | 1 + todo.txt | 6 +++- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/game/editor.c b/src/game/editor.c index e6f1442..cb093da 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -133,10 +133,11 @@ void editor_init(struct Editor* editor) editor->tool_rotate_allowed = false; editor->axis_line_length = 500.f; editor->picking_enabled = true; - editor->draw_cursor_entity = false; + editor->draw_cursor_entity = false; + editor->tool_scale_started = false; vec4_fill(&editor->projected_entity_color, 0.f, 1.f, 1.f, 1.f); - vec3_fill(&editor->tool_scale_amount, 0.f, 0.f, 0.f); + vec3_fill(&editor->tool_scale_amount, 1.f, 1.f, 1.f); vec4_fill(&editor->tool_mesh_color, 0.f, 1.f, 1.f, 1.f); vec4_fill(&editor->selected_entity_color, 0.96, 0.61, 0.17, 0.5f); vec4_fill(&editor->grid_color, 0.3f, 0.3f, 0.3f, 0.7f); @@ -511,6 +512,7 @@ void editor_update(struct Editor* editor, float dt) { switch(editor->current_tool) { + case EDITOR_TOOL_SCALE: case EDITOR_TOOL_TRANSLATE: { quat rotation = { 0.f, 0.f, 0.f, 1.f }; @@ -674,19 +676,33 @@ void editor_on_mousebutton_release(const struct Event* event) if(editor->selected_entity && event->mousebutton.button == MSB_LEFT && nk_item_is_any_active(&gui->context) == 0) { - if(editor->current_tool == EDITOR_TOOL_TRANSLATE) + switch(editor->current_tool) { + case EDITOR_TOOL_TRANSLATE: if(editor->current_axis != EDITOR_AXIS_NONE) transform_copy(editor->selected_entity, editor->cursor_entity, false); - } - else if(editor->current_tool == EDITOR_TOOL_ROTATE && editor->tool_rotate_rotation_started) - { - editor->picking_enabled = true; - editor->tool_rotate_rotation_started = false; - transform_copy(editor->selected_entity, editor->cursor_entity, false); - editor->tool_rotate_total_rotation = 0.f; - editor->tool_rotate_starting_rotation = 0.f; - editor->draw_cursor_entity = false; + break; + case EDITOR_TOOL_ROTATE: + if(editor->tool_rotate_rotation_started) + { + editor->picking_enabled = true; + editor->tool_rotate_rotation_started = false; + transform_copy(editor->selected_entity, editor->cursor_entity, false); + editor->tool_rotate_total_rotation = 0.f; + editor->tool_rotate_starting_rotation = 0.f; + editor->draw_cursor_entity = false; + } + break; + case EDITOR_TOOL_SCALE: + if(editor->tool_scale_started) + { + editor->picking_enabled = true; + editor->tool_scale_started = false; + transform_copy(editor->selected_entity, editor->cursor_entity, false); + vec3_fill(&editor->tool_scale_amount, 0.f, 0.f, 0.f); + editor->draw_cursor_entity = false; + } + break; } } @@ -700,11 +716,6 @@ void editor_on_mousebutton_press(const struct Event* event) if(game_state->game_mode != GAME_MODE_EDITOR && nk_window_is_any_hovered(&gui->context) == 0) return; - if(event->mousebutton.button == MSB_RIGHT && !editor->camera_looking_around) - { - - } - if(event->mousebutton.button == MSB_LEFT && editor->selected_entity) { if(editor->current_tool == EDITOR_TOOL_ROTATE && editor->tool_rotate_allowed) @@ -900,6 +911,23 @@ void editor_on_mousemotion(const struct Event* event) } break; + case EDITOR_TOOL_SCALE: + { + if(editor->current_axis != EDITOR_AXIS_NONE && editor->tool_scale_started) + { + switch(editor->current_axis) + { + case EDITOR_AXIS_X: editor->tool_scale_amount.x += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; break; + case EDITOR_AXIS_Y: editor->tool_scale_amount.y += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; break; + case EDITOR_AXIS_Z: editor->tool_scale_amount.z += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; break; + case EDITOR_AXIS_XZ: editor->tool_scale_amount.x += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; editor->tool_scale_amount.z += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; break; + case EDITOR_AXIS_XY: editor->tool_scale_amount.x += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; editor->tool_scale_amount.y += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; break; + case EDITOR_AXIS_YZ: editor->tool_scale_amount.y += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; editor->tool_scale_amount.z += (float)(event->mousemotion.xrel / 2) * editor->grid_scale; break; + } + transform_scale(editor->cursor_entity, &editor->tool_scale_amount); + } + } + break; default: break; } } @@ -965,7 +993,7 @@ void editor_tool_set(struct Editor* editor, int tool) editor->current_tool = tool; } - if(editor->selected_entity && editor->current_tool == EDITOR_TOOL_TRANSLATE) + if(editor->current_tool == EDITOR_TOOL_TRANSLATE) editor->draw_cursor_entity = true; else editor->draw_cursor_entity = false; @@ -1007,6 +1035,8 @@ void editor_tool_reset(struct Editor* editor) editor->tool_rotate_total_rotation = 0.f; editor->tool_rotate_allowed = false; editor->tool_rotate_rotation_started = false; + vec3_fill(&editor->tool_scale_amount, 0.f, 0.f, 0.f); + editor->tool_scale_started = false; editor->picking_enabled = true; if(editor->current_tool == EDITOR_TOOL_TRANSLATE) editor_axis_set(editor, EDITOR_AXIS_XZ); @@ -1045,6 +1075,14 @@ void editor_axis_set(struct Editor* editor, int axis) editor->tool_rotate_amount = 0.f; } } + + if(editor->current_tool == EDITOR_TOOL_SCALE && axis != EDITOR_AXIS_NONE) + { + editor->tool_scale_started = true; + editor->picking_enabled = false; + editor->draw_cursor_entity = true; + vec3_assign(&editor->tool_scale_amount, &editor->cursor_entity->base.transform.scale); + } } } void editor_camera_update(struct Editor* editor, float dt) diff --git a/src/game/editor.h b/src/game/editor.h index 837fd94..37b7c02 100755 --- a/src/game/editor.h +++ b/src/game/editor.h @@ -46,6 +46,7 @@ struct Editor float tool_rotate_total_rotation; float tool_rotate_starting_rotation; vec3 tool_scale_amount; + bool tool_scale_started; float axis_line_length; vec4 axis_color_x; vec4 axis_color_y; diff --git a/todo.txt b/todo.txt index 3b12eed..2aaa866 100644 --- a/todo.txt +++ b/todo.txt @@ -6,7 +6,7 @@ Todo: ? Disable entity picking when tool is in use or only allow picking when pressing ALT - Disable editor event recievers on game mode change - Editor Undo - - Scale Mode + - Duplicate with Ctrl-D - Color picker - Color palette, picker and dropper - Key binding and function to snap editor camera to selected entity @@ -86,6 +86,7 @@ Improvements: - Depth testing for editor grid - Improve picking and automatically improve everything in editor - Improve culling + - Allow scaling on all axes at once Bugs: - Better handling of wav format checking at load time @@ -95,6 +96,8 @@ Bugs: - Investigate memory usage increase when window is minimized - Fix hang on fullscreen toggle - Fix axis lines not aligning with grid lines + - Fix rotation arc starting and ending degree calculations + - Fix broken spot light degree/radian conversions Done: * Input @@ -276,4 +279,5 @@ Done: consistent * Implemented reverting back to previously selected axis when not moving the camera any more and rotate tool is selected. + * Scale Mode