Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use transform matrix when getting/setting camera position #476

Merged
merged 5 commits into from
Nov 29, 2019

Conversation

banesullivan
Copy link
Member

When scaling a scene (.set_scale), the camera coordinates are transformed to a new projected space. This PR makes sure that when you set the position of the camera using data coordinates, the camera will properly handle those coordinates in the camera's projected space.

One place where many folks noticed this issue is when setting the camera location or focal point which is handled by the orbit_on_path method. The path given corresponds to the data coordinates and not the camera's projected coordinates so if the scene is scaled, the camera could be in a totally wrong location.

Here is a code snippet to demonstrate:

import pyvista as pv
from pyvista import examples

mesh = examples.download_lidar()
z_scale = 2.0

p = pv.Plotter(notebook=False)
p.add_mesh(mesh, render_points_as_spheres=True)

p.set_scale(1, 1, z_scale)
p.show_axes()

p.show(auto_close=False)
path = p.generate_orbital_path(n_points=36, shift=mesh.length)
p.open_gif("~/Desktop/orbit.gif")
p.orbit_on_path(path, write_frames=True)
p.close()

Master Branch

The camera's position is totally away from the mesh because the coordinates were not properly transformed.

orbit

This Branch

Ah, much better.

new-orbit

@banesullivan banesullivan self-assigned this Nov 27, 2019
@banesullivan banesullivan added this to the 0.23.0 milestone Nov 27, 2019
@akaszynski
Copy link
Member

Ah, much better.

Nice @banesullivan.

Copy link
Member

@akaszynski akaszynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Thanks @banesullivan!

@akaszynski akaszynski merged commit 4d26be1 into master Nov 29, 2019
@banesullivan banesullivan deleted the patch/scaled-camera branch December 11, 2019 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants