Class Camera
- java.lang.Object
-
- renderer.scene.Camera
-
public final class Camera extends Object
ThisCamera
data structure represents a camera located at the origin, looking down the negative z-axis, with a near clipping plane.This
Camera
has a configurable "view volume" that determines what part of space the camera "sees" when we use the camera to take a picture (that is, when we render aScene
).This
Camera
can "take a picture" two ways, using a perspective projection or a parallel (orthographic) projection. Each way of taking a picture has a different shape for its view volume. The data in this data structure determines the shape of each of the two view volumes.For the perspective projection, the view volume (in view coordinates!) is the infinitely long frustum that is formed by cutting at the near clipping plane,
z = -near
, the infinitely long pyramid with its apex at the origin and its cross section in the image plane,z = -1
, with edgesx = -1
,x = +1
,y = -1
, andy = +1
. The perspective view volume's shape is set by theprojPerspective()
method.For the orthographic projection, the view volume (in view coordinates!) is the semi-infinite rectangular cylinder parallel to the z-axis, with base in the near clipping plane,
z = -near
, and with edgesx = left
,x = right
,y = bottom
,y = top
(a semi-infinite parallelepiped). The orthographic view volume's shape is set by theprojOrtho()
method.When the graphics rendering
Pipeline
uses thisCamera
to render aScene
, the renderer only "sees" the geometry from the scene that is contained in this camera's view volume. (Notice that this means the orthographic camera can see geometry that is behind the camera. In fact, the perspective camera can also sees geometry that is behind the camera.) The renderer'sNearClip
andClip
pipeline stages are responsible for making sure that the scene's geometry that is outside of this camera's view volume is not visible.The plane
z = -1
(in view coordinates) is the camera's "image plane". The rectangle in the image plane with corners(left, bottom, -1)
and(right, top, -1)
is the camera's "view rectangle". The view rectangle is like the film in a real camera, it is where the camera's image appears when you take a picture. The contents of the camera's view rectangle (after it gets "normalized" to camera coordinates by the renderer'sView2Camera
stage) is what gets rasterized, by the renderer'sRasterize
pipeline stage, into aFrameBuffer
'sFrameBuffer.Viewport
.For both the perspective and the parallel projections, the camera's near plane is there to prevent the camera from seeing what is "behind" the near plane. For the perspective projection, the near plane also prevents the renderer from incorrectly rasterizing line segments that cross the camera plane,
z = 0
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Camera
changeNear(double near)
Create a newCamera
that is essentially the same as thisCamera
but with the given distance from the camera to the near clipping plane.static Camera
projOrtho()
This is a static factory method.static Camera
projOrtho(double fovy, double aspect)
This is a static factory method.static Camera
projOrtho(double left, double right, double bottom, double top)
This is a static factory method.static Camera
projPerspective()
This is a static factory method.static Camera
projPerspective(double fovy, double aspect)
This is a static factory method.static Camera
projPerspective(double left, double right, double bottom, double top)
This is a static factory method.static Camera
projPerspective(double left, double right, double bottom, double top, double focalLength)
This is a static factory method.String
toString()
For debugging.
-
-
-
Method Detail
-
projPerspective
public static Camera projPerspective()
This is a static factory method.Set up this
Camera
's view volume as a perspective projection of the normalized infinite view pyramid extending along the negative z-axis.- Returns:
- a new
Camera
object with the default perspective parameters
-
projPerspective
public static Camera projPerspective(double left, double right, double bottom, double top)
This is a static factory method.Set up this
Camera
's view volume as a perspective projection of an infinite view pyramid extending along the negative z-axis.- Parameters:
left
- left edge of view rectangle in the image planeright
- right edge of view rectangle in the image planebottom
- bottom edge of view rectangle in the image planetop
- top edge of view rectangle in the image plane- Returns:
- a new
Camera
object with the given parameters
-
projPerspective
public static Camera projPerspective(double left, double right, double bottom, double top, double focalLength)
This is a static factory method.Set up this
Camera
's view volume as a perspective projection of an infinite view pyramid extending along the negative z-axis.Use
focalLength
to determine the image plane. So theleft
,right
,bottom
,top
parameters are used in the planez = -focalLength
.The
focalLength
parameter can be used to zoom an asymmetric view volume, much like thefovy
parameter for the symmetric view volume, or the "near" parameter for the OpenGL gluPerspective() function.- Parameters:
left
- left edge of view rectangle in the image planeright
- right edge of view rectangle in the image planebottom
- bottom edge of view rectangle in the image planetop
- top edge of view rectangle in the image planefocalLength
- distance from the origin to the image plane- Returns:
- a new
Camera
object with the given parameters
-
projPerspective
public static Camera projPerspective(double fovy, double aspect)
This is a static factory method.Set up this
Camera
's view volume as a symmetric infinite view pyramid extending along the negative z-axis.Here, the view volume is determined by a vertical "field of view" angle and an aspect ratio for the view rectangle in the image plane.
- Parameters:
fovy
- angle in the y-direction subtended by the view rectangle in the image planeaspect
- aspect ratio of the view rectangle in the image plane- Returns:
- a new
Camera
object with the given parameters
-
projOrtho
public static Camera projOrtho()
This is a static factory method.Set up this
Camera
's view volume as a parallel (orthographic) projection of the normalized infinite view parallelepiped extending along the z-axis.- Returns:
- a new
Camera
object with the default orthographic parameters
-
projOrtho
public static Camera projOrtho(double left, double right, double bottom, double top)
This is a static factory method.Set up this
Camera
's view volume as a parallel (orthographic) projection of an infinite view parallelepiped extending along the z-axis.- Parameters:
left
- left edge of view rectangle in the xy-planeright
- right edge of view rectangle in the xy-planebottom
- bottom edge of view rectangle in the xy-planetop
- top edge of view rectangle in the xy-plane- Returns:
- a new
Camera
object with the given parameters
-
projOrtho
public static Camera projOrtho(double fovy, double aspect)
This is a static factory method.Set up this
Camera
's view volume as a symmetric infinite view parallelepiped extending along the z-axis.Here, the view volume is determined by a vertical "field-of-view" angle and an aspect ratio for the view rectangle in the image plane.
- Parameters:
fovy
- angle in the y-direction subtended by the view rectangle in the image planeaspect
- aspect ratio of the view rectangle in the image plane- Returns:
- a new
Camera
object with the given parameters
-
changeNear
public Camera changeNear(double near)
Create a newCamera
that is essentially the same as thisCamera
but with the given distance from the camera to the near clipping plane.When
near
is positive, the near clipping plane is in front of the camera. Whennear
is negative, the near clipping plane is behind the camera.- Parameters:
near
- distance from the newCamera
to its near clipping plane- Returns:
- a new
Camera
object with the given value for near
-
-