diff --git a/src/game/editor.c b/src/game/editor.c index c3879d9..6718988 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -121,9 +121,12 @@ void editor_init(struct Editor* editor) editor->tool_snap_enabled = 1; editor->axis_line_length = 500.f; vec3_fill(&editor->tool_mesh_position, 0.f, 0.f, 0.f); - vec4_fill(&editor->tool_mesh_color, 0.f, 0.3f, 1.f, 1.f); - vec4_fill(&editor->selected_entity_colour, 0.f, 1.f, 0.f, 1.f); + vec4_fill(&editor->tool_mesh_color, 0.f, 1.f, 1.f, 1.f); + vec4_fill(&editor->selected_entity_colour, 1.f, 1.f, 0.f, 1.f); vec4_fill(&editor->grid_color, 0.3f, 0.3f, 0.3f, 0.1f); + vec4_fill(&editor->axis_color_x, 1.f, 0.f, 0.f, 1.f); + vec4_fill(&editor->axis_color_y, 0.f, 1.f, 0.f, 1.f); + vec4_fill(&editor->axis_color_z, 0.f, 0.f, 1.f, 1.f); debug_vars_list = array_new(struct Debug_Variable); empty_indices = array_new(int); @@ -180,17 +183,9 @@ void editor_render(struct Editor* editor, struct Camera * active_camera) float half_axis_line_length = editor->axis_line_length / 2.f; - im_begin(position, rotation, scale, (vec4) { 1.f, 0.f, 0.f, 1.f }, GDM_LINES, 1); // X Axis - im_pos(-half_axis_line_length, 0.f, 0.f); im_pos(half_axis_line_length, 0.f, 0.f); - im_end(); - - im_begin(position, rotation, scale, (vec4) { 0.f, 1.f, 0.f, 1.f }, GDM_LINES, 1); // Y Axis - im_pos(0.f, -half_axis_line_length, 0.f); im_pos(0.f, half_axis_line_length, 0.f); - im_end(); - - im_begin(position, rotation, scale, (vec4) { 0.f, 0.f, 1.f, 1.f }, GDM_LINES, 1); // Z Axis - im_pos(0.f, 0.f, -half_axis_line_length); im_pos(0.f, 0.f, half_axis_line_length); - im_end(); + im_line((vec3) { -half_axis_line_length, 0.f, 0.f }, (vec3) { half_axis_line_length, 0.f, 0.f }, position, rotation, scale, editor->axis_color_x, GDM_LINES, 1); // X Axis + im_line((vec3) { 0.f, -half_axis_line_length, 0.f }, (vec3) { 0.f, half_axis_line_length, 0.f }, position, rotation, scale, editor->axis_color_y, GDM_LINES, 1); // Y Axis + im_line((vec3) { 0.f, 0.f, -half_axis_line_length }, (vec3) { 0.f, 0.f, half_axis_line_length }, position, rotation, scale, editor->axis_color_z, GDM_LINES, 1); // Z Axis //Draw Grid if(editor->grid_enabled) @@ -390,7 +385,7 @@ void editor_update(struct Editor* editor, float dt) { nk_layout_row_begin(context, NK_DYNAMIC, editor->top_panel_height - 5, 8); - nk_layout_row_push(context, 0.1f); + nk_layout_row_push(context, 0.12f); nk_labelf(context, NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE, "Cursor: %.1f %.1f %.1f", editor->tool_mesh_position.x, editor->tool_mesh_position.y, editor->tool_mesh_position.z); nk_layout_row_push(context, 0.1f); @@ -405,7 +400,7 @@ void editor_update(struct Editor* editor, float dt) nk_layout_row_push(context, 0.1f); nk_labelf(context, NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE, "Grid Length: %d", editor->grid_num_lines); - nk_layout_row_push(context, 0.4f); + nk_layout_row_push(context, 0.38f); nk_spacing(context, 1); nk_layout_row_push(context, 0.1f); @@ -435,31 +430,27 @@ void editor_update(struct Editor* editor, float dt) { if(editor->current_mode == EDITOR_MODE_TRANSLATE) { - im_sphere(0.5f, editor->tool_mesh_position, (quat) { 0.f, 0.f, 0.f, 1.f }, editor->tool_mesh_color, GDM_TRIANGLES, 2); - //im_box(editor->grid_scale, editor->grid_scale, editor->grid_scale, editor->tool_mesh_position, (quat) { 0.f, 0.f, 0.f, 1.f }, editor->tool_mesh_color, GDM_TRIANGLES); + quat rotation = { 0.f, 0.f, 0.f, 1.f }; + vec3 scale = { 1.f, 1.f, 1.f }; + im_sphere(0.5f, editor->tool_mesh_position, rotation, editor->tool_mesh_color, GDM_TRIANGLES, 2); //Draw Axes - im_begin(editor->tool_mesh_position, (quat) { 0.f, 0.f, 0.f, 1.f }, (vec3) { 1.f, 1.f, 1.f }, (vec4) { 0.f, 1.f, 1.f, 1.f }, GDM_LINES, 3); switch(editor->current_axis) { case EDITOR_AXIS_XZ: - im_pos(-editor->axis_line_length, 0.f, 0.f); im_pos(editor->axis_line_length, 0.f, 0.f); - im_pos(0.f, 0.f, -editor->axis_line_length); im_pos(0.f, 0.f, editor->axis_line_length); + im_line((vec3) { -editor->axis_line_length, 0.f, 0.f }, (vec3) { editor->axis_line_length, 0.f, 0.f }, editor->tool_mesh_position, rotation, scale, editor->axis_color_x, GDM_LINES, 3); + im_line((vec3) { 0.f, 0.f, -editor->axis_line_length }, (vec3) { 0.f, 0.f, editor->axis_line_length }, editor->tool_mesh_position, rotation, scale, editor->axis_color_z, GDM_LINES, 3); break; case EDITOR_AXIS_Y: - im_pos(0.f, -editor->axis_line_length, 0.f); - im_pos(0.f, editor->axis_line_length, 0.f); + im_line((vec3) { 0.f, -editor->axis_line_length, 0.f }, (vec3) { 0.f, editor->axis_line_length, 0.f }, editor->tool_mesh_position, rotation, scale, editor->axis_color_y, GDM_LINES, 3); break; case EDITOR_AXIS_X: - im_pos(-editor->axis_line_length, 0.f, 0.f); - im_pos(editor->axis_line_length, 0.f, 0.f); + im_line((vec3) { -editor->axis_line_length, 0.f, 0.f }, (vec3) { editor->axis_line_length, 0.f, 0.f }, editor->tool_mesh_position, rotation, scale, editor->axis_color_x, GDM_LINES, 3); break; case EDITOR_AXIS_Z: - im_pos(0.f, 0.f, -editor->axis_line_length); - im_pos(0.f, 0.f, editor->axis_line_length); + im_line((vec3) { 0.f, 0.f, -editor->axis_line_length }, (vec3) { 0.f, 0.f, editor->axis_line_length }, editor->tool_mesh_position, rotation, scale, editor->axis_color_z, GDM_LINES, 3); break; } - im_end(); } } } @@ -543,9 +534,9 @@ void editor_on_mousemotion(const struct Event* event) switch(editor->current_axis) { - case EDITOR_AXIS_X: editor->tool_mesh_position.x += event->mousemotion.xrel; break; - case EDITOR_AXIS_Y: editor->tool_mesh_position.y += -event->mousemotion.yrel; break; - case EDITOR_AXIS_Z: editor->tool_mesh_position.z += -event->mousemotion.yrel; break; + case EDITOR_AXIS_X: editor->tool_mesh_position.x += event->mousemotion.xrel / 2; break; + case EDITOR_AXIS_Y: editor->tool_mesh_position.y += -event->mousemotion.xrel / 2; break; + case EDITOR_AXIS_Z: editor->tool_mesh_position.z += -event->mousemotion.xrel / 2; break; case EDITOR_AXIS_XZ: { Plane ground_plane; diff --git a/src/game/editor.h b/src/game/editor.h index 38e493f..854978a 100755 --- a/src/game/editor.h +++ b/src/game/editor.h @@ -35,6 +35,9 @@ struct Editor vec4 tool_mesh_color; int tool_mesh_draw_enabled; float axis_line_length; + vec4 axis_color_x; + vec4 axis_color_y; + vec4 axis_color_z; }; void editor_init(struct Editor* editor_state); diff --git a/src/game/im_render.c b/src/game/im_render.c index 4b29039..d57d3f7 100755 --- a/src/game/im_render.c +++ b/src/game/im_render.c @@ -152,6 +152,14 @@ void im_sphere(float radius, vec3 position, quat rotation, vec4 color, int draw_ active_geom = NULL; } +void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec3 scale, vec4 color, int draw_mode, int draw_order) +{ + im_begin(position, rotation, scale, color, draw_mode, draw_order); + im_pos(p1.x, p1.y, p1.z); + im_pos(p2.x, p2.y, p2.z); + im_end(); +} + void im_end(void) { active_geom->num_vertices = active_vertex_index + 1; diff --git a/src/game/im_render.h b/src/game/im_render.h index 6e3947c..9770863 100755 --- a/src/game/im_render.h +++ b/src/game/im_render.h @@ -43,6 +43,7 @@ void im_begin(vec3 position, quat rotation, vec3 scale, vec4 color, int draw_mod void im_pos(float x, float y, float z); void im_box(float x, float y, float z, vec3 position, quat rotation, vec4 color, int draw_mode, int draw_order); void im_sphere(float radius, vec3 position, quat rotation, vec4 color, int draw_mode, int draw_order); +void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec3 scale, vec4 color, int draw_mode, int draw_order); void im_end(void); void im_render(struct Camera* active_viewer); diff --git a/todo.txt b/todo.txt index 3b159ef..71cebfd 100644 --- a/todo.txt +++ b/todo.txt @@ -1,12 +1,15 @@ Todo: - - Make axis lines always follow the same colour scheme for consistency across all tools, red for X axis, green for Y axis and blue for Z axis - - Toggle between relative and static grid i.e, grid that moves along with the selected object or grid that remains stationary at the origin + - Implement circle drawing with immediate mode renderer + - Implement arc drawing with renderer + - Rotate mode tool widget + - Complete rotate mode - Better, more accurate picking - Highlight if we are about to select an entity or perform the tool action like translate when mouse is hovered and an entity can be selected at that location - Display the projected position if we perform the action for example display what the new location would be right next to the tool mesh - Editor Undo - Scale Mode - - Rotate Mode + - Color picker + - Color palette, picker and dropper - Add other axis combinations like YZ and XY to transform tool - Transformation space selection for translation, rotation and scale. - Use actual selected entity's mesh for tool mesh when the entity already has a mesh and use a placeholder like a sphere when there is not mesh @@ -242,4 +245,6 @@ Done: * Display Axis selection in top bar * Immediate mode render order, drawing axis and helpers on top of grid * Draw coloured axes lines at world origin or grid origin + * Make axis lines always follow the same colour scheme for consistency across all tools, red for X axis, green for Y axis and blue for Z axis + * Toggle between relative and static grid i.e, grid that moves along with the selected object or grid that remains stationary at the origin