org.opensourcephysics.drawing3d.utils
Class Camera

java.lang.Object
  extended by org.opensourcephysics.drawing3d.utils.Camera

public class Camera
extends java.lang.Object

Title: Camera

Description: This class provides access to the position of the camera, its focus point and its distance to the projection screen that are used to view the 3D scenes. The camera can also be rotated around the line of sight (i.e. the line which conects the camera with the focus point).

The camera position can be set using either the desired X,Y,Z coordinates or spherical coordinates around the focus point. This makes it easy to rotate the scene both horizontally and vertically (around the focus).

Panning can be achieved by moving the focus point to one side.

Zooming is done increasing (positive zoom) or decreasing the distance between the camera and the projection screen.

The projection screen is always normal to the line of sight and has its origin at the intersection of this line with the screen itself.

The camera provides fives different modes of projecting points in space to the screen. Two modes are truly three-dimensional. The other three are planar modes.

Version:
August 2009
Author:
Francisco Esquembre, Carlos Jara (CJB)

Field Summary
static int CHANGE_ANGLES
           
static int CHANGE_ANY
           
static int CHANGE_FOCUS
           
static int CHANGE_MAPPING
           
static int CHANGE_MODE
           
static int CHANGE_POSITION
           
static int CHANGE_ROTATION
           
static int CHANGE_SCREEN
           
static int MODE_NO_PERSPECTIVE
           
static int MODE_PERSPECTIVE
           
static int MODE_PERSPECTIVE_OFF
           
static int MODE_PERSPECTIVE_ON
           
static int MODE_PLANAR_XY
           
static int MODE_PLANAR_XZ
           
static int MODE_PLANAR_YZ
           
 
Constructor Summary
Camera(DrawingPanel3D aPanel)
           
 
Method Summary
 void adjust()
          Adjust is a soft reset.
 void copyFrom(Camera camera)
          Copies its configuration from another camera
 double getAltitude()
          Get the elevation (VERTICAL_AXIS) angle of the camera position in spherical coordinates with respect to the focus point.
 double getAzimuth()
          Get the horizontal angle of the camera position in spherical coordinates with respect to the focus point.
 double getCosAlpha()
           
 double getCosBeta()
           
 double getDistanceToFocus()
           
 double getDistanceToScreen()
          Returns the distance from the camera to the projecting screen.
 double getFocusX()
          Returns the focus X coordinate
 double getFocusY()
          Returns the focus Y coordinate
 double getFocusZ()
          Returns the focus Z coordinate
 int getProjectionMode()
          Gets the projecting mode of the camera.
 double[] getQuatMapping()
           
 double getRotation()
          Returns the angle that the camera is rotated along the line of sight.
 double getSinAlpha()
           
 double getSinBeta()
           
 double getX()
          Returns the camera X coordinate
 double getY()
          Returns the camera Y coordinate
 double getZ()
          Returns the camera Z coordinate
 double[] inverseMapping(double[] point)
          Reverses the mapping on the given point
 boolean is3dMode()
          Whether the projection mode is three-dimensional
 double[] map(double[] point)
          Maps coordinates to axes for the given point
 double[] projectPosition(double[] p)
           
 double[] projectSize(double[] p, double[] size)
          Computes the projection of a size at a given point.
 void reset()
          Resets the camera to the default.
 void setAltitude(double angle)
          Set the elevation (VERTICAL_AXIS) angle of the camera position in spherical coordinates with respect to the focus point.
 void setAzimuth(double angle)
          Set the azimuthal (horizontal) angle of the camera position in spherical coordinates with respect to the focus point.
 void setAzimuthAndAltitude(double azimuth, double altitude)
          Set the angles of the camera position in spherical coordinates with respect to the focus point.
 void setDistanceToScreen(double distance)
          Sets the distance from the camera to the projecting screen.
 void setFocusXYZ(double[] point)
          Sets the focus of the camera.
 void setFocusXYZ(double x, double y, double z)
          Sets the focus point of the camera.
 void setMapping(int mappingType)
          Sets the correspondance between axes and coordinates.
 void setProjectionMode(int mode)
          Sets one of the projecting modes.
 void setRotation(double angle)
          Sets the angle that the camera is rotated along the line of sight.
 void setXYZ(double[] point)
          Sets the position of the camera.
 void setXYZ(double x, double y, double z)
          Sets the position of the camera.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_PLANAR_XY

public static final int MODE_PLANAR_XY
See Also:
Constant Field Values

MODE_PLANAR_XZ

public static final int MODE_PLANAR_XZ
See Also:
Constant Field Values

MODE_PLANAR_YZ

public static final int MODE_PLANAR_YZ
See Also:
Constant Field Values

MODE_PERSPECTIVE_OFF

public static final int MODE_PERSPECTIVE_OFF
See Also:
Constant Field Values

MODE_PERSPECTIVE_ON

public static final int MODE_PERSPECTIVE_ON
See Also:
Constant Field Values

MODE_NO_PERSPECTIVE

public static final int MODE_NO_PERSPECTIVE
See Also:
Constant Field Values

MODE_PERSPECTIVE

public static final int MODE_PERSPECTIVE
See Also:
Constant Field Values

CHANGE_ANY

public static final int CHANGE_ANY
See Also:
Constant Field Values

CHANGE_MODE

public static final int CHANGE_MODE
See Also:
Constant Field Values

CHANGE_POSITION

public static final int CHANGE_POSITION
See Also:
Constant Field Values

CHANGE_FOCUS

public static final int CHANGE_FOCUS
See Also:
Constant Field Values

CHANGE_ROTATION

public static final int CHANGE_ROTATION
See Also:
Constant Field Values

CHANGE_SCREEN

public static final int CHANGE_SCREEN
See Also:
Constant Field Values

CHANGE_ANGLES

public static final int CHANGE_ANGLES
See Also:
Constant Field Values

CHANGE_MAPPING

public static final int CHANGE_MAPPING
See Also:
Constant Field Values
Constructor Detail

Camera

public Camera(DrawingPanel3D aPanel)
Method Detail

setProjectionMode

public void setProjectionMode(int mode)
Sets one of the projecting modes. Possible values are:

Changing the mode does not reset the camera.

Parameters:
mode - int

getProjectionMode

public final int getProjectionMode()
Gets the projecting mode of the camera.

Returns:
int #see #setProjectionMode(int)

reset

public void reset()
Resets the camera to the default. The camera is placed along the X direction, at a reasonable distance from the center of the panel, which becomes the focus, and is not rotated. The screen is also placed at a reasonable distance so that to view the whole scene.


adjust

public void adjust()
Adjust is a soft reset. It respects the azimuth and altitude, but recomputes the rest so that the scene is not too close to the eye. This method is typically called when the extrema of the scene change


setMapping

public void setMapping(int mappingType)
Sets the correspondance between axes and coordinates.

Parameters:
mappingType - An integer specified by the static constants in the Mapping class
See Also:
Mapping

map

public double[] map(double[] point)
Maps coordinates to axes for the given point

Parameters:
point -
Returns:
double[]

inverseMapping

public double[] inverseMapping(double[] point)
Reverses the mapping on the given point

Parameters:
point -
Returns:
double[]

getQuatMapping

public double[] getQuatMapping()

setXYZ

public void setXYZ(double x,
                   double y,
                   double z)
Sets the position of the camera.

Parameters:
x - double
y - double
z - double

setXYZ

public void setXYZ(double[] point)
Sets the position of the camera.

Parameters:
point - double[]

getX

public final double getX()
Returns the camera X coordinate

Returns:
double the X coordinate of the camera position

getY

public final double getY()
Returns the camera Y coordinate

Returns:
double the Y coordinate of the camera position

getZ

public final double getZ()
Returns the camera Z coordinate

Returns:
double the Z coordinate of the camera position

setFocusXYZ

public void setFocusXYZ(double x,
                        double y,
                        double z)
Sets the focus point of the camera. That it, the point in space at which the camera is pointing.

Parameters:
x - double
y - double
z - double

setFocusXYZ

public void setFocusXYZ(double[] point)
Sets the focus of the camera.

Parameters:
point - double[]

getFocusX

public final double getFocusX()
Returns the focus X coordinate

Returns:
double the X coordinate of the focus position

getFocusY

public final double getFocusY()
Returns the focus Y coordinate

Returns:
double the Y coordinate of the focus position

getFocusZ

public final double getFocusZ()
Returns the focus Z coordinate

Returns:
double the Z coordinate of the focus position

getDistanceToFocus

public final double getDistanceToFocus()

setRotation

public void setRotation(double angle)
Sets the angle that the camera is rotated along the line of sight. Default is 0.

Parameters:
angle - double The angle in radians

getRotation

public final double getRotation()
Returns the angle that the camera is rotated along the line of sight.

Returns:
double

setDistanceToScreen

public void setDistanceToScreen(double distance)
Sets the distance from the camera to the projecting screen.

Parameters:
distance - double

getDistanceToScreen

public final double getDistanceToScreen()
Returns the distance from the camera to the projecting screen.

Returns:
double

setAzimuth

public void setAzimuth(double angle)
Set the azimuthal (horizontal) angle of the camera position in spherical coordinates with respect to the focus point. A value of 0 places the camera in the XZ plane.

Parameters:
angle - the desired angle in radians

getAzimuth

public final double getAzimuth()
Get the horizontal angle of the camera position in spherical coordinates with respect to the focus point. A value of 0 means the camera is in the XZ plane.

Returns:
double

setAltitude

public void setAltitude(double angle)
Set the elevation (VERTICAL_AXIS) angle of the camera position in spherical coordinates with respect to the focus point. A value of 0 places the camera is in the XY plane.

Parameters:
angle - the desired angle in radians in the range [-Math.PI/2,Math.PI/2]

getAltitude

public final double getAltitude()
Get the elevation (VERTICAL_AXIS) angle of the camera position in spherical coordinates with respect to the focus point. A value of 0 means the camera is in the XY plane.

Returns:
double

setAzimuthAndAltitude

public void setAzimuthAndAltitude(double azimuth,
                                  double altitude)
Set the angles of the camera position in spherical coordinates with respect to the focus point.

Parameters:
azimuth - the desired azimuthal angle in radians
altitude - the desired altitude angle in radians in the range [-Math.PI/2,Math.PI/2]

copyFrom

public void copyFrom(Camera camera)
Copies its configuration from another camera

Parameters:
camera -

getCosAlpha

public final double getCosAlpha()

getSinAlpha

public final double getSinAlpha()

getCosBeta

public final double getCosBeta()

getSinBeta

public final double getSinBeta()

is3dMode

public boolean is3dMode()
Whether the projection mode is three-dimensional

Returns:
boolean

projectPosition

public double[] projectPosition(double[] p)

projectSize

public double[] projectSize(double[] p,
                            double[] size)
Computes the projection of a size at a given point. For internal use of DrawingPanel3D only