diff options
Diffstat (limited to 'editor.c')
| -rw-r--r-- | editor.c | 44 |
1 files changed, 27 insertions, 17 deletions
@@ -757,23 +757,23 @@ editor_focus_selection(void) { f32 radius = fmaxf( Vector3Distance(minimum, maximum) * 0.5f, 0.5f); - /* Leave space for panels on either side of the view. */ - f32 width = GetScreenWidth(); - f32 height = GetScreenHeight(); + /* Leave space for panels covering the displayed scene. */ + Rect viewport = app.scr_rec; f32 margin = 0; if (ed.panel[ED_PNL_LEFT].enabled) { Rect bounds = ed.panel[ED_PNL_LEFT].bounds; - margin = fmaxf(margin, bounds.x + bounds.width); + margin = fmaxf(margin,bounds.x + bounds.width - viewport.x); } if (ed.panel[ED_PNL_RIGHT].enabled) { Rect bounds = ed.panel[ED_PNL_RIGHT].bounds; - margin = fmaxf(margin, width - bounds.x); + margin = fmaxf(margin, viewport.x + viewport.width - bounds.x); } - f32 visible_width = fmaxf(width - 2.0f * margin, 1.0f); - f32 aspect = visible_width / height; + f32 visible_width = fmaxf(viewport.width - 2.0f * margin, 1.0f); + f32 aspect = visible_width / viewport.height; + f32 half_fov = main_cam.perspective_fov * DEG2RAD * 0.5f; f32 horizontal = atanf(tanf(half_fov) * aspect); f32 angle = fminf(half_fov, horizontal); @@ -922,7 +922,9 @@ case ED_INTERACT_NONE: } } - if (ed.focus != 0) { + if (ed.focus != 0 || + !CheckCollisionPointRec(GetMousePosition(), + app.scr_rec)) { break; } @@ -1107,7 +1109,11 @@ default: /* tools */ static void sel_ray(void) { - Ray ray = GetScreenToWorldRay(end_point, main_cam.cam); + if (!CheckCollisionPointRec(end_point, app.scr_rec)) { + return; + } + + Ray ray = app_screen_ray(end_point, main_cam.cam); Vec3 dir = Vector3Scale(ray.direction, 1000.0f); b3QueryFilter filter = { @@ -1154,7 +1160,7 @@ physics_pick(void) { return; } - Ray ray = GetScreenToWorldRay(GetMousePosition(), main_cam.cam); + Ray ray = app_screen_ray(GetMousePosition(), main_cam.cam); Vec3 dir = Vector3Scale(ray.direction, 1000.0f); b3Pos origin = { @@ -1212,7 +1218,7 @@ sel_area(void) { continue; } - Vec2 pos = GetWorldToScreen(world_pos, main_cam.cam); + Vec2 pos = app_world_to_screen(world_pos, main_cam.cam); if (CheckCollisionPointRec(pos, sel_rec)) { ent->ed.selected = true; } @@ -1301,7 +1307,7 @@ editor_select(void) { static bool ray_plane_hit(Vec3 plane_pos, Vec3 plane_dir, Vec3 *out) { - Ray ray = GetScreenToWorldRay(GetMousePosition(), main_cam.cam); + Ray ray = app_screen_ray(GetMousePosition(), main_cam.cam); f32 denom = Vector3DotProduct(ray.direction, plane_dir); if (fabsf(denom) < 0.0001f) { @@ -1481,7 +1487,11 @@ editor_move(void) { Vec3 delta = {0}; if (surface) { - Ray ray = GetScreenToWorldRay( + if (!CheckCollisionPointRec(GetMousePosition(), app.scr_rec)) { + return; + } + + Ray ray = app_screen_ray( GetMousePosition(), main_cam.cam); Vec3 direction = Vector3Scale(ray.direction, 1000.0f); @@ -1530,8 +1540,8 @@ editor_move(void) { return; } - Vec2 a = GetWorldToScreen(pivot, main_cam.cam); - Vec2 b = GetWorldToScreen( + Vec2 a = app_world_to_screen(pivot, main_cam.cam); + Vec2 b = app_world_to_screen( Vector3Add(pivot, axis), main_cam.cam); Vec2 screen_axis = Vector2Subtract(b, a); f32 length_squared = Vector2LengthSqr(screen_axis); @@ -5502,7 +5512,7 @@ gizmo_rotate(void) { tanf(main_cam.cam.fovy * DEG2RAD * 0.5f); } - f32 radius = view_height * 65.0f / GetScreenHeight(); + f32 radius = view_height * 65.0f / app.scr_rec.height; if (ed.rotate_group) { DrawSphereEx(pivot, radius * 0.04f, 4, 6, WHITE); @@ -5593,7 +5603,7 @@ gizmo_scale(void) { tanf(main_cam.cam.fovy * DEG2RAD * 0.5f); } - f32 pixel = view_height / GetScreenHeight(); + f32 pixel = view_height / app.scr_rec.height; if (!ed.scale_group || i == 0) { DrawSphereEx(pivot, pixel * 3.0f, 4, 6, WHITE); |
