Implemnted filled circles and arcs and made arcs handle negative angle values better

dev
Shariq Shah 6 years ago
parent a8dd4b581c
commit 3be1a71957
  1. 29
      src/game/editor.c
  2. 1
      src/game/geometry.c
  3. 1
      src/game/geometry.h
  4. 23
      src/game/im_render.c
  5. 6
      src/game/im_render.h
  6. 12
      todo.txt

@ -121,7 +121,7 @@ void editor_init(struct Editor* editor)
editor->grid_scale = 1.f; editor->grid_scale = 1.f;
editor->tool_mesh_draw_enabled = 1; editor->tool_mesh_draw_enabled = 1;
editor->tool_snap_enabled = 1; editor->tool_snap_enabled = 1;
editor->tool_rotate_arc_radius = 10.f; editor->tool_rotate_arc_radius = 5.f;
editor->tool_rotate_arc_segments = 50.f; editor->tool_rotate_arc_segments = 50.f;
editor->tool_rotate_axis_selection_enabled = true; editor->tool_rotate_axis_selection_enabled = true;
editor->axis_line_length = 500.f; editor->axis_line_length = 500.f;
@ -131,7 +131,7 @@ void editor_init(struct Editor* editor)
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, 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_colour, 0.96, 0.61, 0.17, 1.f); vec4_fill(&editor->selected_entity_colour, 0.96, 0.61, 0.17, 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.7f);
vec4_fill(&editor->axis_color_x, 0.87, 0.32, 0.40, 1.f); vec4_fill(&editor->axis_color_x, 0.87, 0.32, 0.40, 1.f);
vec4_fill(&editor->axis_color_y, 0.53, 0.67, 0.28, 1.f); vec4_fill(&editor->axis_color_y, 0.53, 0.67, 0.28, 1.f);
vec4_fill(&editor->axis_color_z, 0.47, 0.67, 0.89, 1.f); vec4_fill(&editor->axis_color_z, 0.47, 0.67, 0.89, 1.f);
@ -479,16 +479,16 @@ void editor_update(struct Editor* editor, float dt)
{ {
quat rotation = { 0.f, 0.f, 0.f, 1.f }; quat rotation = { 0.f, 0.f, 0.f, 1.f };
vec3 scale = { 1.f, 1.f, 1.f }; vec3 scale = { 1.f, 1.f, 1.f };
im_circle(editor->tool_rotate_arc_radius, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_z, 3); im_circle(editor->tool_rotate_arc_radius, editor->tool_rotate_arc_segments, false, editor->tool_mesh_position, rotation, editor->axis_color_z, 3);
//im_arc(editor->tool_rotate_arc_radius, 0.f, 90.f, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_z, 3); //im_arc(editor->tool_rotate_arc_radius, 0.f, 90.f, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_z, 3);
quat_axis_angle(&rotation, &UNIT_X, -90.f); quat_axis_angle(&rotation, &UNIT_X, -90.f);
im_circle(editor->tool_rotate_arc_radius, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_y, 3); im_circle(editor->tool_rotate_arc_radius, editor->tool_rotate_arc_segments, false, editor->tool_mesh_position, rotation, editor->axis_color_y, 3);
//im_arc(editor->tool_rotate_arc_radius, 90.f, 180.f, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_y, 3); //im_arc(editor->tool_rotate_arc_radius, 90.f, 180.f, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_y, 3);
quat_identity(&rotation); quat_identity(&rotation);
quat_axis_angle(&rotation, &UNIT_Y, -90.f); quat_axis_angle(&rotation, &UNIT_Y, -90.f);
im_circle(editor->tool_rotate_arc_radius, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_x, 3); im_circle(editor->tool_rotate_arc_radius, editor->tool_rotate_arc_segments, false, editor->tool_mesh_position, rotation, editor->axis_color_x, 3);
//im_arc(editor->tool_rotate_arc_radius, 0.f, 90.f, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_x, 3); //im_arc(editor->tool_rotate_arc_radius, 0.f, 90.f, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, editor->axis_color_x, 3);
if(editor->current_axis != EDITOR_AXIS_NONE) if(editor->current_axis != EDITOR_AXIS_NONE)
@ -502,10 +502,15 @@ void editor_update(struct Editor* editor, float dt)
case EDITOR_AXIS_Z: vec4_assign(&arc_color, &editor->axis_color_z); break; case EDITOR_AXIS_Z: vec4_assign(&arc_color, &editor->axis_color_z); break;
} }
if(editor->tool_rotate_amount == 0.f) arc_color.w = 0.1f;
im_arc(editor->tool_rotate_arc_radius / 2.f, 0.f, 1.f, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, arc_color, 2); im_circle(editor->tool_rotate_arc_radius, editor->tool_rotate_arc_segments, true, editor->tool_mesh_position, rotation, arc_color, 2);
else if(editor->tool_rotate_amount != 0.f)
im_arc(editor->tool_rotate_arc_radius / 2.f, 0.f, editor->tool_rotate_amount, editor->tool_rotate_arc_segments, editor->tool_mesh_position, rotation, arc_color, 3); {
arc_color.w = 0.5f;
im_arc(editor->tool_rotate_arc_radius / 2.f, 0.f, editor->tool_rotate_amount, editor->tool_rotate_arc_segments, true, editor->tool_mesh_position, rotation, arc_color, 4);
}
} }
} }
break; break;
@ -712,7 +717,11 @@ void editor_on_mousemotion(const struct Event* event)
} }
else /* Rotate on selected axis */ else /* Rotate on selected axis */
{ {
editor->tool_rotate_amount += editor->current_axis == EDITOR_AXIS_X ? event->mousemotion.xrel / 2 : -event->mousemotion.xrel / 2; editor->tool_rotate_amount += event->mousemotion.xrel / 2;
if(editor->tool_rotate_amount > 360.f)
editor->tool_rotate_amount = editor->tool_rotate_amount - 360.f;
else if(editor->tool_rotate_amount < -360.f)
editor->tool_rotate_amount = editor->tool_rotate_amount + 360.f;
} }
} }
break; break;

@ -31,6 +31,7 @@ void geom_init(void)
draw_modes[GDM_POINTS] = GL_POINTS; draw_modes[GDM_POINTS] = GL_POINTS;
draw_modes[GDM_LINE_STRIP] = GL_LINE_STRIP; draw_modes[GDM_LINE_STRIP] = GL_LINE_STRIP;
draw_modes[GDM_LINE_LOOP] = GL_LINE_LOOP; draw_modes[GDM_LINE_LOOP] = GL_LINE_LOOP;
draw_modes[GDM_TRIANGLE_FAN] = GL_TRIANGLE_FAN;
} }
int geom_find(const char* filename) int geom_find(const char* filename)

@ -17,6 +17,7 @@ enum Geometry_Draw_Mode
GDM_POINTS, GDM_POINTS,
GDM_LINE_STRIP, GDM_LINE_STRIP,
GDM_LINE_LOOP, GDM_LINE_LOOP,
GDM_TRIANGLE_FAN,
GDM_NUM_DRAWMODES GDM_NUM_DRAWMODES
}; };

@ -161,22 +161,30 @@ void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec3 scale, vec4 co
im_end(); im_end();
} }
void im_circle(float radius, int num_divisions, vec3 position, quat rotation, vec4 color, int draw_order) void im_circle(float radius, int num_divisions, bool filled, vec3 position, quat rotation, vec4 color, int draw_order)
{ {
im_arc(radius, 0.f, 360.f, num_divisions, position, rotation, color, draw_order); im_arc(radius, 0.f, 360.f, num_divisions, filled, position, rotation, color, draw_order);
} }
void im_arc(float radius, float angle_start, float angle_end, int num_divisions, vec3 position, quat rotation, vec4 color, int draw_order) void im_arc(float radius, float angle_start, float angle_end, int num_divisions, bool filled, vec3 position, quat rotation, vec4 color, int draw_order)
{ {
im_begin(position, rotation, (vec3) { 1.f, 1.f, 1.f }, color, GDM_LINE_LOOP, draw_order); im_begin(position, rotation, (vec3) { 1.f, 1.f, 1.f }, color, filled ? GDM_TRIANGLE_FAN : GDM_LINE_LOOP, draw_order);
float arc_degrees = angle_end - angle_start; float arc_degrees = angle_end - angle_start;
float increment = arc_degrees / num_divisions; float increment = arc_degrees / num_divisions;
if(arc_degrees != 360) if(arc_degrees != 360)
im_pos(0.f, 0.f, 0.f); im_pos(0.f, 0.f, 0.f);
for(float i = angle_start; i <= angle_end; i+= increment) if(angle_start < angle_end)
{
for(float i = angle_start; i <= angle_end; i += increment)
im_pos(sinf(i * M_PI / 180.f) * radius, cosf(i * M_PI / 180.f) * radius, 0.f); im_pos(sinf(i * M_PI / 180.f) * radius, cosf(i * M_PI / 180.f) * radius, 0.f);
}
else
{
for(float i = angle_start; i >= angle_end; i += increment)
im_pos(sinf(i * M_PI / 180.f) * radius, cosf(i * M_PI / 180.f) * radius, 0.f);
}
im_end(); im_end();
} }
@ -205,6 +213,11 @@ void im_render(struct Camera* active_viewer)
if(IM_State.curr_geom + 1 > 1) if(IM_State.curr_geom + 1 > 1)
qsort(IM_State.geometries, IM_State.curr_geom + 1, sizeof(struct IM_Geom), &im_sort_func); qsort(IM_State.geometries, IM_State.curr_geom + 1, sizeof(struct IM_Geom), &im_sort_func);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
shader_bind(IM_State.im_shader); shader_bind(IM_State.im_shader);
{ {
static mat4 mvp, translation, rotation, scale; static mat4 mvp, translation, rotation, scale;

@ -3,6 +3,8 @@
#include "../common/linmath.h" #include "../common/linmath.h"
#include <stdbool.h>
struct IM_Vertex struct IM_Vertex
{ {
vec3 position; vec3 position;
@ -44,8 +46,8 @@ 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_order); void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec3 scale, vec4 color, int draw_order);
void im_circle(float radius, int num_divisions, vec3 position, quat rotation, vec4 color, int draw_order); void im_circle(float radius, int num_divisions, bool filled, vec3 position, quat rotation, vec4 color, int draw_order);
void im_arc(float radius, float angle_start, float angle_end, int num_divisions, vec3 position, quat rotation, vec4 color, int draw_order); void im_arc(float radius, float angle_start, float angle_end, int num_divisions, bool filled, vec3 position, quat rotation, vec4 color, 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,10 +1,7 @@
Todo: Todo:
- Impement im_filled_circle - Only show rotation gizmo for one axis at a time
- Draw rotation gizmo using filled circles to better reflect the underlying logic - Rotate mesh along mouse movement or show what the rotation is going to look like by using a wireframe version of mesh when rotating
- Match amount to be rotate with actual axes and the gizmo arc being drawn - Match amount to be rotate with actual axes and the gizmo arc being drawn
- Handle negative values in im_arc
- Rotate mode tool widget
- Complete rotate mode
- Handle all other axes combinations - Handle all other axes combinations
- 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
@ -257,4 +254,9 @@ Done:
* Toggle between relative and static grid i.e, grid that moves along with the selected object or grid that remains stationary at the origin * 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 circle drawing with immediate mode renderer
* Implement arc drawing with renderer * Implement arc drawing with renderer
* Impement im_filled_circle
* Draw rotation gizmo using filled circles to better reflect the underlying logic
* Handle negative values in im_arc
* Rotate mode tool widget
* Complete rotate mode

Loading…
Cancel
Save