Fixed look_at_rotation bug for 3 camera positions (#220)

Summary:
To address the issue https://github.com/facebookresearch/pytorch3d/issues/219 of Invalid rotation matrix when number of camera position is equal to 3
Pull Request resolved: https://github.com/facebookresearch/pytorch3d/pull/220

Reviewed By: bottler

Differential Revision: D21877606

Pulled By: nikhilaravi

fbshipit-source-id: f95ae44497cae33f2f0cff1b1718d866cf79bda1
This commit is contained in:
guanming001@e.ntu.edu.sg 2020-06-04 04:03:37 -07:00 committed by Facebook GitHub Bot
parent 5444c53cee
commit 4b78e95eeb

View File

@ -916,8 +916,8 @@ def look_at_rotation(
msg = "Expected arg %s to have shape (N, 3); got %r" msg = "Expected arg %s to have shape (N, 3); got %r"
raise ValueError(msg % (n, t.shape)) raise ValueError(msg % (n, t.shape))
z_axis = F.normalize(at - camera_position, eps=1e-5) z_axis = F.normalize(at - camera_position, eps=1e-5)
x_axis = F.normalize(torch.cross(up, z_axis), eps=1e-5) x_axis = F.normalize(torch.cross(up, z_axis, dim=1), eps=1e-5)
y_axis = F.normalize(torch.cross(z_axis, x_axis), eps=1e-5) y_axis = F.normalize(torch.cross(z_axis, x_axis, dim=1), eps=1e-5)
R = torch.cat((x_axis[:, None, :], y_axis[:, None, :], z_axis[:, None, :]), dim=1) R = torch.cat((x_axis[:, None, :], y_axis[:, None, :], z_axis[:, None, :]), dim=1)
return R.transpose(1, 2) return R.transpose(1, 2)