Fixed issue with picking not working when mouse cursor is inside rotation gizmo radius

dev
Shariq Shah 6 years ago
parent 1cd9b71ba7
commit 9ce41a0149
  1. 30
      src/game/editor.c
  2. 2
      todo.txt

@ -154,7 +154,7 @@ void editor_init(struct Editor* editor)
event_manager_subscribe(event_manager, EVT_KEY_PRESSED, &editor_on_key_press); event_manager_subscribe(event_manager, EVT_KEY_PRESSED, &editor_on_key_press);
event_manager_subscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release); event_manager_subscribe(event_manager, EVT_KEY_RELEASED, &editor_on_key_release);
editor->selected_entity_wireframe = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "Sphere.pamesh", MAT_UNSHADED); editor->selected_entity_wireframe = scene_static_mesh_create(game_state_get()->scene, "EDITOR_SELECTED_ENTITY_WIREFRAME", NULL, "sphere.pamesh", MAT_UNSHADED);
} }
void editor_init_camera(struct Editor* editor, struct Hashmap* cvars) void editor_init_camera(struct Editor* editor, struct Hashmap* cvars)
@ -731,6 +731,33 @@ void editor_on_mousebutton_press(const struct Event* event)
if(event->mousebutton.button == MSB_LEFT && editor->selected_entity) if(event->mousebutton.button == MSB_LEFT && editor->selected_entity)
{ {
if(editor->current_mode == EDITOR_MODE_ROTATE && editor->tool_rotate_allowed) if(editor->current_mode == EDITOR_MODE_ROTATE && editor->tool_rotate_allowed)
{
/* Check if there's an entity under cursor, if there is then select it,
otherwise disable picking and start rotating */
struct Scene* scene = game_state_get()->scene;
struct Camera* editor_camera = &scene->cameras[CAM_EDITOR];
int mouse_x = 0, mouse_y = 0;
platform_mouse_position_get(&mouse_x, &mouse_y);
struct Ray ray = camera_screen_coord_to_ray(editor_camera, mouse_x, mouse_y);
struct Raycast_Result ray_result;
scene_ray_intersect(scene, &ray, &ray_result);
if(ray_result.num_entities_intersected > 0)
{
//For now, just select the first entity that is intersected
struct Entity* intersected_entity = ray_result.entities_intersected[0];
if(intersected_entity == editor->selected_entity_wireframe)
{
if(ray_result.num_entities_intersected > 1)
{
intersected_entity = ray_result.entities_intersected[1];
if(intersected_entity)
editor_entity_select(editor, intersected_entity);
}
}
}
else
{ {
editor->picking_enabled = false; editor->picking_enabled = false;
editor->tool_rotate_rotation_started = true; editor->tool_rotate_rotation_started = true;
@ -744,6 +771,7 @@ void editor_on_mousebutton_press(const struct Event* event)
} }
} }
} }
}
/* Cancel rotation on right mouse press */ /* Cancel rotation on right mouse press */
if(event->mousebutton.button == MSB_RIGHT && editor->selected_entity && editor->current_mode == EDITOR_MODE_ROTATE) if(event->mousebutton.button == MSB_RIGHT && editor->selected_entity && editor->current_mode == EDITOR_MODE_ROTATE)

@ -267,4 +267,6 @@ Done:
* Rotate mesh along mouse movement or show what the rotation is going to look like by using a wireframe version of mesh when rotating * 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 all other axes combinations * Handle all other axes combinations
* Fixed issue with picking not working when the other entity is inside
rotation radius

Loading…
Cancel
Save