Implmented consistent colors for axes and line drawing function for immediate mode renderer

dev
Shariq Shah 6 years ago
parent 9c4882ef8a
commit c7c7d0f4ca
  1. 51
      src/game/editor.c
  2. 3
      src/game/editor.h
  3. 8
      src/game/im_render.c
  4. 1
      src/game/im_render.h
  5. 11
      todo.txt

@ -121,9 +121,12 @@ void editor_init(struct Editor* editor)
editor->tool_snap_enabled = 1; editor->tool_snap_enabled = 1;
editor->axis_line_length = 500.f; editor->axis_line_length = 500.f;
vec3_fill(&editor->tool_mesh_position, 0.f, 0.f, 0.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->tool_mesh_color, 0.f, 1.f, 1.f, 1.f);
vec4_fill(&editor->selected_entity_colour, 0.f, 1.f, 0.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->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); debug_vars_list = array_new(struct Debug_Variable);
empty_indices = array_new(int); 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; 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_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_pos(-half_axis_line_length, 0.f, 0.f); im_pos(half_axis_line_length, 0.f, 0.f); 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_end(); 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
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();
//Draw Grid //Draw Grid
if(editor->grid_enabled) 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_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_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); 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_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_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_spacing(context, 1);
nk_layout_row_push(context, 0.1f); 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) 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); quat rotation = { 0.f, 0.f, 0.f, 1.f };
//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); 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 //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) switch(editor->current_axis)
{ {
case EDITOR_AXIS_XZ: 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_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_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; break;
case EDITOR_AXIS_Y: case EDITOR_AXIS_Y:
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);
im_pos(0.f, editor->axis_line_length, 0.f);
break; break;
case EDITOR_AXIS_X: case EDITOR_AXIS_X:
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);
im_pos(editor->axis_line_length, 0.f, 0.f);
break; break;
case EDITOR_AXIS_Z: case EDITOR_AXIS_Z:
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);
im_pos(0.f, 0.f, editor->axis_line_length);
break; break;
} }
im_end();
} }
} }
} }
@ -543,9 +534,9 @@ void editor_on_mousemotion(const struct Event* event)
switch(editor->current_axis) switch(editor->current_axis)
{ {
case EDITOR_AXIS_X: editor->tool_mesh_position.x += event->mousemotion.xrel; 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.yrel; 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.yrel; break; case EDITOR_AXIS_Z: editor->tool_mesh_position.z += -event->mousemotion.xrel / 2; break;
case EDITOR_AXIS_XZ: case EDITOR_AXIS_XZ:
{ {
Plane ground_plane; Plane ground_plane;

@ -35,6 +35,9 @@ struct Editor
vec4 tool_mesh_color; vec4 tool_mesh_color;
int tool_mesh_draw_enabled; int tool_mesh_draw_enabled;
float axis_line_length; float axis_line_length;
vec4 axis_color_x;
vec4 axis_color_y;
vec4 axis_color_z;
}; };
void editor_init(struct Editor* editor_state); void editor_init(struct Editor* editor_state);

@ -152,6 +152,14 @@ void im_sphere(float radius, vec3 position, quat rotation, vec4 color, int draw_
active_geom = NULL; 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) void im_end(void)
{ {
active_geom->num_vertices = active_vertex_index + 1; active_geom->num_vertices = active_vertex_index + 1;

@ -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_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_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_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_end(void);
void im_render(struct Camera* active_viewer); void im_render(struct Camera* active_viewer);

@ -1,12 +1,15 @@
Todo: 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 - Implement circle drawing with immediate mode renderer
- 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 arc drawing with renderer
- Rotate mode tool widget
- Complete rotate mode
- Better, more accurate picking - 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 - 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 - 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 - Editor Undo
- Scale Mode - Scale Mode
- Rotate Mode - Color picker
- Color palette, picker and dropper
- Add other axis combinations like YZ and XY to transform tool - Add other axis combinations like YZ and XY to transform tool
- Transformation space selection for translation, rotation and scale. - 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 - 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 * Display Axis selection in top bar
* Immediate mode render order, drawing axis and helpers on top of grid * Immediate mode render order, drawing axis and helpers on top of grid
* Draw coloured axes lines at world origin or grid origin * 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

Loading…
Cancel
Save