public final class PerspectiveCamera extends Camera implements AutoCloseable
Also known as a pinhole camera.
The Camera
API is a low-level API. For simple map navigation use cases, it's recommended to use the higher-level API. The MapNavigator
API works in both 2D and 3D, on all map references. If you use the low-level Camera
API, keep in mind that the same camera manipulation implementation might not work for other types of cameras (OrthographicCamera
vs PerspectiveCamera
) or other (types of) map references (projected vs. geocentric).
A camera transforms points from the map reference
to the view (device independent pixel coordinates).
Besides the position, orientation and size properties that it inherits from Camera
, the perspective camera defines its projection using a field of view
: the angle, in degrees, that determines the vertical viewing angle of the camera. The horizontal field-of-view angle can be derived from the vertical field-of-view and the camera's aspect ratio.
Cameras in LuciadCPillar are immutable. You can manipulate the map's camera by creating a modified copy using the builder
. The new camera can then be set
on the map.
Currently, the PerspectiveCamera
is only used in combination with geocentric (3D) map references (aka 3D maps). For now, you cannot use this camera if the map has a projected (grid) reference.
To manipulate a perspective camera in a geocentric reference, consider using lookAt
or lookFrom
. This allows you to reason about the camera in terms of yaw (angle from north direction), pitch (angle wrt. horizon) and roll. You could also just manipulate the camera's eye position and forward/up directions directly, if that's a better fit for your use case.
Map
navigation constraints configured on MapNavigator
are not enforced when this camera is updated on the map. Constraints are only respected when using MapNavigator
.
Example:
// low-level manipulation of perspective camera: put camera looking over Europe, faced towards the north
var perspectiveCamera = (PerspectiveCamera) map.getCamera();
Camera.Look newCameraPosition = new Camera.Look(
new Coordinate(6214861.581912037, 710226.7751339739, 4927634.769711619),
new Coordinate(0.9588725076044676, -0.12713997961061635, -0.25376946180526144),
new Coordinate(-0.2469197372006221, -0.06727846255744102, 0.9666976010400992)
);
Camera newCamera = perspectiveCamera.asBuilder().look(newCameraPosition).build();
// ...
// Set the camera on the map, for example by using Map#getAnimationManager
map.setCamera(newCamera);
Modifier and Type | Class and Description |
---|---|
static class |
PerspectiveCamera.Builder
Factory object that can create new
PerspectiveCamera instances. |
Camera.Look, Camera.Look2D, Camera.LookAt, Camera.LookFrom
Modifier and Type | Method and Description |
---|---|
PerspectiveCamera.Builder |
asBuilder()
Returns a Builder that is initially configured to build cameras identical to this camera.
|
Camera.Look |
asLook()
Returns the position and orientation of the camera.
|
Camera.LookAt |
asLookAt(double distance)
Returns a
LookAt that matches the position and orientation of this camera. |
Camera.LookFrom |
asLookFrom()
Returns a
LookFrom that matches the position and orientation of this camera. |
void |
close() |
protected void |
finalize() |
Angle |
getFovY()
Returns the vertical field of view of the camera.
|
public void close()
close
in interface AutoCloseable
close
in class Camera
@NotNull public PerspectiveCamera.Builder asBuilder()
You can then change a subset of the camera properties using this builder to create a new camera.
@NotNull public Angle getFovY()
PerspectiveCamera.Builder#fovY
@NotNull public Camera.Look asLook()
@NotNull public Camera.LookAt asLookAt(double distance)
LookAt
that matches the position and orientation of this camera.LookAt
that matches the position and orientation of this camera.@NotNull public Camera.LookFrom asLookFrom()
LookFrom
that matches the position and orientation of this camera.LookFrom
that matches the position and orientation of this camera.