de.jreality.util
Class CameraUtility

java.lang.Object
  extended by de.jreality.util.CameraUtility

public class CameraUtility
extends Object

A collection of static methods related to specifying camera transformations of various kinds.

Author:
Charles Gunn

Field Summary
static Matrix cameraOrientation
           
static Matrix inverseCameraOrientation
           
static int LEFT_EYE
           
static int MIDDLE_EYE
           
static int RIGHT_EYE
           
 
Method Summary
static void encompass(SceneGraphPath avatarPath, SceneGraphPath scene, SceneGraphPath cameraPath)
           
static void encompass(SceneGraphPath avatarPath, SceneGraphPath scene, SceneGraphPath cameraPath, double margin, int metric)
          A method for encompassing the scene.
static void encompass(Viewer viewer)
           
static void encompass(Viewer viewer, SceneGraphComponent sgc, boolean setStereoParameters)
          Encompass the world displayed by a viewer and possibly set derived parameters in the camera.
static double getAspectRatio(Viewer v)
          Determine the aspect ratio of the output window of a viewer.
static Camera getCamera(Viewer v)
          Determine the camera for this viewer.
static SceneGraphComponent getCameraNode(Viewer v)
          Determine the SceneGraphComponent which contains the camera for this viewer.
static double[] getCameraToNDC(Camera cam, double aspectRatio)
           
static double[] getCameraToNDC(Camera cam, double aspectRatio, int which)
          Calculate a 4x4 projection matrix for this camera.
static double[] getCameraToNDC(Camera cam, double aspectRatio, int which, int metric)
           
static double[] getCameraToNDC(Viewer v)
          Calculate the camera to NDC (normalized device coordinates) transformation for a given viewer.
static double[] getEyePosition(Camera cam, int which)
          A method required for calculating cam2NDC for a CAVE-like environment.
static double[] getNDCToCamera(Camera cam, double aspectRatio)
           
static double[] getNDCToCamera(Viewer v)
           
static double[][] getNearViewport(Viewer v)
           
static Rectangle2D getOffAxisViewPort(Camera cam, Rectangle2D viewPort, double[] eyePosition)
          A method required for calculating cam2NDC transformation for an off-axis camera.
static Rectangle2D getViewport(Camera cam, double aspectRatio)
          Determine the viewport of the given camera: the intersection of the viewing frustum with the z=1 plane.
static void loadPreferences(Camera cam)
           
static void savePreferences(Camera cam)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cameraOrientation

public static Matrix cameraOrientation

inverseCameraOrientation

public static Matrix inverseCameraOrientation

MIDDLE_EYE

public static final int MIDDLE_EYE
See Also:
Constant Field Values

LEFT_EYE

public static final int LEFT_EYE
See Also:
Constant Field Values

RIGHT_EYE

public static final int RIGHT_EYE
See Also:
Constant Field Values
Method Detail

getCamera

public static Camera getCamera(Viewer v)
Determine the camera for this viewer.

Parameters:
v -
Returns:

getCameraNode

public static SceneGraphComponent getCameraNode(Viewer v)
Determine the SceneGraphComponent which contains the camera for this viewer.

Parameters:
v -
Returns:

encompass

public static void encompass(Viewer viewer)
Parameters:
camera -
viewer -

encompass

public static void encompass(Viewer viewer,
                             SceneGraphComponent sgc,
                             boolean setStereoParameters)
Encompass the world displayed by a viewer and possibly set derived parameters in the camera.

Parameters:
viewer -
sgc -
setStereoParameters -

getAspectRatio

public static double getAspectRatio(Viewer v)
Determine the aspect ratio of the output window of a viewer.

Parameters:
v -
Returns:

getCameraToNDC

public static double[] getCameraToNDC(Viewer v)
Calculate the camera to NDC (normalized device coordinates) transformation for a given viewer.

Parameters:
v -
Returns:

getCameraToNDC

public static double[] getCameraToNDC(Camera cam,
                                      double aspectRatio)
Parameters:
cam -
aspectRatio -
Returns:

getCameraToNDC

public static double[] getCameraToNDC(Camera cam,
                                      double aspectRatio,
                                      int which)
Calculate a 4x4 projection matrix for this camera. If which is MIDDLE_EYE, calculate a normal "monocular" camera. If which is LEFT_EYE or RIGHT_EYE,, calculate the projection matrix corresponding to the given eye of a stere-ocular camera. The stereo case can be derived from the monocular case as follows.

Define V to be the intersection of the viewing frustum with the plane z = focus (See #setFocus(double)). Second, define the positions Pl = (d,0,0,0) and Pr = (-d,0,0,0) where d = eyeSeparation/2.0 (See #setEyeSeparationMeters(double)). Then the position of the left eye in camera coordinates is O.Pl (where O is the camera's orientation matrix (See #setOrientationMatrix(double[])), or the identity matrix if none has been set) and similarly for the right eye. Then the viewing frustum for the left eye is the unique viewing frustum determined by the position at the left (right) eye and the rectangle V; similarly for the right eye.

In plain English, the monocular, left, and right views all show the same picture if the world lies in the z = focus plane. This plane is in fact the focal plane in this sense.

Note that the orientationMatrix is only non-trivial in the case of virtual environments such as the PORTAL or CAVE. * @deprecated

Parameters:
which -
Returns:

getCameraToNDC

public static double[] getCameraToNDC(Camera cam,
                                      double aspectRatio,
                                      int which,
                                      int metric)

getEyePosition

public static double[] getEyePosition(Camera cam,
                                      int which)
A method required for calculating cam2NDC for a CAVE-like environment.

Parameters:
cam -
which -
Returns:

getOffAxisViewPort

public static Rectangle2D getOffAxisViewPort(Camera cam,
                                             Rectangle2D viewPort,
                                             double[] eyePosition)
A method required for calculating cam2NDC transformation for an off-axis camera. NOTE: a stereo camera is an off-axis camera.

Parameters:
cam -
viewPort -
eyePosition -
Returns:

getViewport

public static Rectangle2D getViewport(Camera cam,
                                      double aspectRatio)
Determine the viewport of the given camera: the intersection of the viewing frustum with the z=1 plane.

Parameters:
cam -
aspectRatio -
Returns:

getNearViewport

public static double[][] getNearViewport(Viewer v)

getNDCToCamera

public static double[] getNDCToCamera(Viewer v)

getNDCToCamera

public static double[] getNDCToCamera(Camera cam,
                                      double aspectRatio)

encompass

public static void encompass(SceneGraphPath avatarPath,
                             SceneGraphPath scene,
                             SceneGraphPath cameraPath)

encompass

public static void encompass(SceneGraphPath avatarPath,
                             SceneGraphPath scene,
                             SceneGraphPath cameraPath,
                             double margin,
                             int metric)
A method for encompassing the scene.

Parameters:
avatarPath -
scene -
cameraPath -
margin -
metric -

loadPreferences

public static void loadPreferences(Camera cam)

savePreferences

public static void savePreferences(Camera cam)