Class Camera
- java.lang.Object
-
- renderer.scene.Camera
-
public final class Camera extends Object
ThisCameradata structure represents a camera that can be translated around within world coordinates.This
Camerahas aviewVectorwhich associates to thisCameraa location in the world coordinate system. ACameraobject is moved within world coordinates by changing itsviewVector.A
Camera'stranslate(double,double,double)method is used to move theCamerain world coordinates exactly as thePosition.translate(double, double, double)method is used to move aModelin world coordinates.The renderer uses the camera's
viewVectorin itsWorld2Viewpipeline stage. In that stage, the renderer subtracts the camera'sviewVectorfrom every vertex of every model in the scene to convert each vertex from world coordinates to the camera's view coordinate system. The reason for using subtraction is that when the camera moves forward by 5 units in the z-direction, every vertex in the scene will appear 5 units closer to the camera. So every vertex in the scene needs a translation by -5 in the z-direction. Similarly, if the camera moves up 5 units in the y-direction, every vertex in the scene will appear to the camera to be 5 units lower. So every vertex in the scene needs a translation by -5 in the y-direction.This
Camerahas a configurable "view volume" that determines what part of world space the camera "sees" when we use the camera to take a picture (that is, when we render aScene).This
Cameracan "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
Pipelineuses thisCamerato 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'sNearClipandClippipeline 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'sView2Camerastage) is what gets rasterized, by the renderer'sRasterizepipeline 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 CamerachangeNear(double near)Create a newCamerathat is essentially the same as thisCamerabut with the given distance from the camera to the near clipping plane.MatrixgetNormalizeMatrix()Get a reference to thisCamera's normalizationMatrix.VectorgetViewVector()Get a reference to thisCamera's viewVector.static CameraprojOrtho()This is a static factory method.static CameraprojOrtho(double fovy, double aspect)This is a static factory method.static CameraprojOrtho(double left, double right, double bottom, double top)This is a static factory method.static CameraprojPerspective()This is a static factory method.static CameraprojPerspective(double fovy, double aspect)This is a static factory method.static CameraprojPerspective(double left, double right, double bottom, double top)This is a static factory method.static CameraprojPerspective(double left, double right, double bottom, double top, double focalLength)This is a static factory method.StringtoString()For debugging.Cameratranslate(double x, double y, double z)Create a newCamerathat is essentially the same as thisCamerabut with the given location.
-
-
-
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
Cameraobject 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
Cameraobject 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
focalLengthto determine the image plane. So theleft,right,bottom,topparameters are used in the planez = -focalLength.The
focalLengthparameter can be used to zoom an asymmetric view volume, much like thefovyparameter 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
Cameraobject 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
Cameraobject 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
Cameraobject 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
Cameraobject 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
Cameraobject with the given parameters
-
changeNear
public Camera changeNear(double near)
Create a newCamerathat is essentially the same as thisCamerabut with the given distance from the camera to the near clipping plane.When
nearis positive, the near clipping plane is in front of the camera. Whennearis negative, the near clipping plane is behind the camera.- Parameters:
near- distance from the newCamerato its near clipping plane- Returns:
- a new
Cameraobject with the given value for near
-
translate
public Camera translate(double x, double y, double z)
Create a newCamerathat is essentially the same as thisCamerabut with the given location.- Parameters:
x- translated location, in the x-direction, for the newCameray- translated location, in the y-direction, for the newCameraz- translated location, in the z-direction, for the newCamera- Returns:
- a new
Cameraobject with the given translated location
-
getViewVector
public Vector getViewVector()
Get a reference to thisCamera's viewVector.- Returns:
- a reference to this
Camera'sVectorobject
-
getNormalizeMatrix
public Matrix getNormalizeMatrix()
Get a reference to thisCamera's normalizationMatrix.- Returns:
- a reference to this
Camera's normalizingMatrixobject
-
-