Skip to content

Commit

Permalink
Merge pull request godotengine#25540 from JFonS/remove_gizmo_errors
Browse files Browse the repository at this point in the history
Fix gizmo errors on "Align with view"
  • Loading branch information
akien-mga authored Feb 1, 2019
2 parents 463123a + 2232d33 commit 58de384
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions editor/plugins/spatial_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2865,6 +2865,18 @@ void SpatialEditorViewport::update_transform_gizmo_view() {
Transform xform = spatial_editor->get_gizmo_transform();

Transform camera_xform = camera->get_transform();

if (xform.origin.distance_squared_to(camera_xform.origin) < 0.01) {
for (int i = 0; i < 3; i++) {
VisualServer::get_singleton()->instance_set_visible(move_gizmo_instance[i], false);
VisualServer::get_singleton()->instance_set_visible(move_plane_gizmo_instance[i], false);
VisualServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[i], false);
VisualServer::get_singleton()->instance_set_visible(scale_gizmo_instance[i], false);
VisualServer::get_singleton()->instance_set_visible(scale_plane_gizmo_instance[i], false);
}
return;
}

Vector3 camz = -camera_xform.get_basis().get_axis(2).normalized();
Vector3 camy = -camera_xform.get_basis().get_axis(1).normalized();
Plane p(camera_xform.origin, camz);
Expand Down
13 changes: 9 additions & 4 deletions editor/spatial_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,10 @@ bool EditorSpatialGizmo::intersect_ray(Camera *p_camera, const Point2 &p_point,

Transform t = spatial_node->get_global_transform();
t.orthonormalize();
t.set_look_at(t.origin, p_camera->get_camera_transform().origin, Vector3(0, 1, 0));
Vector3 camera_position = p_camera->get_camera_transform().origin;
if (camera_position.distance_squared_to(t.origin) > 0.01) {
t.set_look_at(t.origin, camera_position, Vector3(0, 1, 0));
}

float scale = t.origin.distance_to(p_camera->get_camera_transform().origin);

Expand All @@ -563,16 +566,18 @@ bool EditorSpatialGizmo::intersect_ray(Camera *p_camera, const Point2 &p_point,

Point2 center = p_camera->unproject_position(t.origin);

Transform oct = p_camera->get_camera_transform();
Transform orig_camera_transform = p_camera->get_camera_transform();

p_camera->look_at(t.origin, Vector3(0, 1, 0));
if (orig_camera_transform.origin.distance_squared_to(t.origin) > 0.01) {
p_camera->look_at(t.origin, Vector3(0, 1, 0));
}
Vector3 c0 = t.xform(Vector3(selectable_icon_size, selectable_icon_size, 0) * scale);
Vector3 c1 = t.xform(Vector3(-selectable_icon_size, -selectable_icon_size, 0) * scale);

Point2 p0 = p_camera->unproject_position(c0);
Point2 p1 = p_camera->unproject_position(c1);

p_camera->set_global_transform(oct);
p_camera->set_global_transform(orig_camera_transform);

Rect2 rect(p0, p1 - p0);

Expand Down

0 comments on commit 58de384

Please sign in to comment.