Implemented Scale Tool

dev
Shariq Shah 6 years ago
parent aaa8c879d7
commit 9c5e96503e
  1. 74
      src/game/editor.c
  2. 1
      src/game/editor.h
  3. 6
      todo.txt

@ -133,10 +133,11 @@ void editor_init(struct Editor* editor)
editor->tool_rotate_allowed = false; editor->tool_rotate_allowed = false;
editor->axis_line_length = 500.f; editor->axis_line_length = 500.f;
editor->picking_enabled = true; 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); 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->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->selected_entity_color, 0.96, 0.61, 0.17, 0.5f);
vec4_fill(&editor->grid_color, 0.3f, 0.3f, 0.3f, 0.7f); 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) switch(editor->current_tool)
{ {
case EDITOR_TOOL_SCALE:
case EDITOR_TOOL_TRANSLATE: case EDITOR_TOOL_TRANSLATE:
{ {
quat rotation = { 0.f, 0.f, 0.f, 1.f }; 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->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) if(editor->current_axis != EDITOR_AXIS_NONE)
transform_copy(editor->selected_entity, editor->cursor_entity, false); transform_copy(editor->selected_entity, editor->cursor_entity, false);
} break;
else if(editor->current_tool == EDITOR_TOOL_ROTATE && editor->tool_rotate_rotation_started) case EDITOR_TOOL_ROTATE:
{ if(editor->tool_rotate_rotation_started)
editor->picking_enabled = true; {
editor->tool_rotate_rotation_started = false; editor->picking_enabled = true;
transform_copy(editor->selected_entity, editor->cursor_entity, false); editor->tool_rotate_rotation_started = false;
editor->tool_rotate_total_rotation = 0.f; transform_copy(editor->selected_entity, editor->cursor_entity, false);
editor->tool_rotate_starting_rotation = 0.f; editor->tool_rotate_total_rotation = 0.f;
editor->draw_cursor_entity = false; 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) if(game_state->game_mode != GAME_MODE_EDITOR && nk_window_is_any_hovered(&gui->context) == 0)
return; return;
if(event->mousebutton.button == MSB_RIGHT && !editor->camera_looking_around)
{
}
if(event->mousebutton.button == MSB_LEFT && editor->selected_entity) if(event->mousebutton.button == MSB_LEFT && editor->selected_entity)
{ {
if(editor->current_tool == EDITOR_TOOL_ROTATE && editor->tool_rotate_allowed) if(editor->current_tool == EDITOR_TOOL_ROTATE && editor->tool_rotate_allowed)
@ -900,6 +911,23 @@ void editor_on_mousemotion(const struct Event* event)
} }
break; 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; default: break;
} }
} }
@ -965,7 +993,7 @@ void editor_tool_set(struct Editor* editor, int tool)
editor->current_tool = 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; editor->draw_cursor_entity = true;
else else
editor->draw_cursor_entity = false; 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_total_rotation = 0.f;
editor->tool_rotate_allowed = false; editor->tool_rotate_allowed = false;
editor->tool_rotate_rotation_started = 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; editor->picking_enabled = true;
if(editor->current_tool == EDITOR_TOOL_TRANSLATE) if(editor->current_tool == EDITOR_TOOL_TRANSLATE)
editor_axis_set(editor, EDITOR_AXIS_XZ); 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; 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) void editor_camera_update(struct Editor* editor, float dt)

@ -46,6 +46,7 @@ struct Editor
float tool_rotate_total_rotation; float tool_rotate_total_rotation;
float tool_rotate_starting_rotation; float tool_rotate_starting_rotation;
vec3 tool_scale_amount; vec3 tool_scale_amount;
bool tool_scale_started;
float axis_line_length; float axis_line_length;
vec4 axis_color_x; vec4 axis_color_x;
vec4 axis_color_y; vec4 axis_color_y;

@ -6,7 +6,7 @@ Todo:
? Disable entity picking when tool is in use or only allow picking when pressing ALT ? Disable entity picking when tool is in use or only allow picking when pressing ALT
- Disable editor event recievers on game mode change - Disable editor event recievers on game mode change
- Editor Undo - Editor Undo
- Scale Mode - Duplicate with Ctrl-D
- Color picker - Color picker
- Color palette, picker and dropper - Color palette, picker and dropper
- Key binding and function to snap editor camera to selected entity - Key binding and function to snap editor camera to selected entity
@ -86,6 +86,7 @@ Improvements:
- Depth testing for editor grid - Depth testing for editor grid
- Improve picking and automatically improve everything in editor - Improve picking and automatically improve everything in editor
- Improve culling - Improve culling
- Allow scaling on all axes at once
Bugs: Bugs:
- Better handling of wav format checking at load time - Better handling of wav format checking at load time
@ -95,6 +96,8 @@ Bugs:
- Investigate memory usage increase when window is minimized - Investigate memory usage increase when window is minimized
- Fix hang on fullscreen toggle - Fix hang on fullscreen toggle
- Fix axis lines not aligning with grid lines - Fix axis lines not aligning with grid lines
- Fix rotation arc starting and ending degree calculations
- Fix broken spot light degree/radian conversions
Done: Done:
* Input * Input
@ -276,4 +279,5 @@ Done:
consistent consistent
* Implemented reverting back to previously selected axis when not * Implemented reverting back to previously selected axis when not
moving the camera any more and rotate tool is selected. moving the camera any more and rotate tool is selected.
* Scale Mode

Loading…
Cancel
Save