JavaView® v2.00.008

jv.viewer
Class PvCamera

java.lang.Object
  |
  +--jv.object.PsObject
        |
        +--jv.viewer.PvCamera
All Implemented Interfaces:
java.lang.Cloneable, PsUpdateIf, PvCameraIf, java.io.Serializable

public final class PvCamera
extends PsObject
implements PvCameraIf

Camera for PvDisplay. Four different projection types. Handled by PvDisplay.

If camera info panel is showing, then it is updated when geometry is rotated. On slow machines just switch the visible panel to stop the panel update.

Version:
27.03.00, 2.02 revised (ep) implements PvCameraIf.
21.06.99, 2.01 revised (kp) Clipping activated.
00.00.98, 2.00 revised (kp) Revised.
00.00.97, 1.00 created (kp)
Author:
Konrad Polthier
See Also:
PvDisplay, Serialized Form

Field Summary
protected  boolean m_bEnableClip
          Enable or disable clipping in z-direction.
protected  PvDisplay m_display
          Parent display of this camera.
protected  PuDouble m_farClip
          Distance of far clip plane.
protected  double m_fieldOfView
           
protected  double m_fit
           
protected  PdMatrix m_incrView
           
protected  PdMatrix m_incrViewInv
           
protected  int m_mode
          Control mode i.e. scale, translate, rotate, pick
protected  PuDouble m_nearClip
          Distance of near clip plane.
protected  double m_nHeight
          Size of associated display window is initialized with non-zero values to avoid problems
protected  double m_nWidth
           
protected  PdVector m_pick
           
protected  PdMatrix m_proj
          Transformation matrices and inverses.
protected  PdMatrix m_projInv
           
protected  int m_projMode
          Projection mode, i.e. perspective, x-y, ...
protected  double m_roll
           
protected  PdVector m_rotAxis
           
protected  double m_scaleTotal
           
protected  double m_scaleValue
           
 PdMatrix m_trans
           
 PdMatrix m_transInv
           
protected  PdVector m_vec
           
protected  PdVector m_vecAlt
           
 PdMatrix m_view
           
 PdMatrix m_viewInv
           
protected  PdVector m_worldPick
           
protected  double m_xTransValue
           
protected  double m_yTransValue
           
 
Fields inherited from class jv.object.PsObject
HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_MATERIAL_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_SELECTED, IS_USED, m_infoPanel, m_name, m_panelList, m_parent, m_tag, m_updateList, NUM_TAGS
 
Constructor Summary
PvCamera(PvDisplay display, int projMode)
           
 
Method Summary
 void fit(double diameter)
          Fit object with given diameter into current display window.
 PdVector[] getBounds()
          Get transformed bounding box used in clipping.
 double getDist()
          Get distance of camera position from point of interest in world coordinates.
 PdVector getInterest()
          Get position at which camera is directed, i.e. the point of interest.
protected  int getMode()
          Get the transformation mode, for a list of possible type see PvDisplay#M_MODE_SCALE.
 PdVector getPosition()
          Get position of camera in world coordinates.
 int getProjectionMode()
          Get projection mode of the camera, for example, perspective, xy-projection etc.
 double getRoll()
          Get angle which camera is rotated around viewing direction against default position.
 double getScale()
          Get zoom factor of camera.
 PdVector getUpVector()
          Get up vector as second row of viewing matrix divided by scaling factor.
 PdVector getViewDir()
          Get normalized viewing direction as the vector pointing from the camera to its interest.
 void init()
          Initializes and resets current camera.
protected  void mouseAnimate()
          Iteratively apply incremental transformation matrices during auto-rotate.
protected  void mouseAnimateGeometry()
          Iteratively apply incremental transformation matrices during auto-rotate.
protected  void mouseDragged(int x, int y)
          Calculate transformation matrices based on incremental mouse movements.
protected  void mousePressed(int x, int y)
          Reset some values used in increment calculations when mouse is pressed.
protected  void resizeImage(double aWidth, double aHeight)
          Assign dimension of viewing canvas to allow normalization of pixel coordinates.
 void setDist(double newDist)
          Set distance of camera position from point of interest in world coordinates.
 void setInterest(PdVector pos)
          Set location at which camera is directed, i.e. the point of interest.
protected  void setMode(int aMode)
          Set the transformation mode, for a list of possible type see PvDisplay#M_MODE_SCALE.
 void setPosition(PdVector pos)
          Set position of camera in world coordinates.
 void setRoll(double roll)
          Set angle which camera is rotated around viewing direction against default position.
 void setScale(double newScale)
          Set zoom factor of camera.
 void setUpVector(PdVector up)
          Set normalized up vector of camera in world coordinates.
 void setViewDir(PdVector pos)
          Set viewing direction as the vector pointing from the camera to its interest.
 boolean update(java.lang.Object event)
          event == this : geometry has changed by itself without widget event, therefore somewhere in a superclass the infoPanel must be updated. call: super.update(event, e.g. this) event == null : geometry has change by widget event which has been handled call: super.update(null) event == else : we must handle the event here or pass it to superclass.
 
Methods inherited from class jv.object.PsObject
addInspector, addUpdateListener, clearTag, clone, clone, clone, copy, getFather, getInfoPanel, getInspector, getName, getNumObjects, hasInspector, hasTag, hasUpdateListener, instanceOf, instanceOf, removeInspector, removeUpdateListener, setName, setParent, setTag, toString, updatePanels
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_roll

protected double m_roll

m_fieldOfView

protected double m_fieldOfView

m_nearClip

protected PuDouble m_nearClip
Distance of near clip plane.

m_farClip

protected PuDouble m_farClip
Distance of far clip plane.

m_bEnableClip

protected boolean m_bEnableClip
Enable or disable clipping in z-direction.

m_proj

protected PdMatrix m_proj
Transformation matrices and inverses.

m_projInv

protected PdMatrix m_projInv

m_view

public PdMatrix m_view

m_viewInv

public PdMatrix m_viewInv

m_incrView

protected PdMatrix m_incrView

m_incrViewInv

protected PdMatrix m_incrViewInv

m_trans

public PdMatrix m_trans

m_transInv

public PdMatrix m_transInv

m_mode

protected int m_mode
Control mode i.e. scale, translate, rotate, pick

m_projMode

protected int m_projMode
Projection mode, i.e. perspective, x-y, ...

m_nHeight

protected double m_nHeight
Size of associated display window is initialized with non-zero values to avoid problems

m_nWidth

protected double m_nWidth

m_fit

protected double m_fit

m_scaleTotal

protected double m_scaleTotal

m_scaleValue

protected double m_scaleValue

m_xTransValue

protected double m_xTransValue

m_yTransValue

protected double m_yTransValue

m_vecAlt

protected PdVector m_vecAlt

m_vec

protected PdVector m_vec

m_rotAxis

protected PdVector m_rotAxis

m_pick

protected PdVector m_pick

m_worldPick

protected PdVector m_worldPick

m_display

protected PvDisplay m_display
Parent display of this camera.
Constructor Detail

PvCamera

public PvCamera(PvDisplay display,
                int projMode)
Method Detail

init

public void init()
Initializes and resets current camera.
Overrides:
init in class PsObject

update

public boolean update(java.lang.Object event)
event == this : geometry has changed by itself without widget event, therefore somewhere in a superclass the infoPanel must be updated. call: super.update(event, e.g. this) event == null : geometry has change by widget event which has been handled call: super.update(null) event == else : we must handle the event here or pass it to superclass. If no superclass can handle this event, then error. call: super.update(event)
Overrides:
update in class PsObject
Following copied from class: jv.object.PsObject
See Also:
PsObject.setParent(PsUpdateIf), PsObject.getFather(), PsObject.addUpdateListener(PsUpdateIf)

getProjectionMode

public int getProjectionMode()
Get projection mode of the camera, for example, perspective, xy-projection etc. For a list of possible type see PvDisplayIf#CAMERA_ORTHO_XY.
Specified by:
getProjectionMode in interface PvCameraIf
Returns:
current projection mode
See Also:
PvDisplayIf

getMode

protected int getMode()
Get the transformation mode, for a list of possible type see PvDisplay#M_MODE_SCALE. Method is invoked by PvDisplay.
Returns:
current transformation mode

setMode

protected void setMode(int aMode)
Set the transformation mode, for a list of possible type see PvDisplay#M_MODE_SCALE. Method is invoked by PvDisplay.
Parameters:
current - transformation mode

getViewDir

public PdVector getViewDir()
Get normalized viewing direction as the vector pointing from the camera to its interest.

Internally the viewing direction is the negative of third row of the viewing matrix divided by the scaling factor.

viewDir = -view[2][.] / getScale()
.
Specified by:
getViewDir in interface PvCameraIf
Returns:
normalized viewing direction in world coordinates

setViewDir

public void setViewDir(PdVector pos)
Set viewing direction as the vector pointing from the camera to its interest. Length of vector is irrelevant.
Specified by:
setViewDir in interface PvCameraIf
Parameters:
viewing - direction in world coordinates

getDist

public double getDist()
Get distance of camera position from point of interest in world coordinates. Distance is inverse to scaling factor of viewing matrix.
Specified by:
getDist in interface PvCameraIf
Returns:
distance of camera to interest in world coordinates.
See Also:
getScale()

setDist

public void setDist(double newDist)
Set distance of camera position from point of interest in world coordinates. Scale view matrix with factor=newDist/currDist.
Specified by:
setDist in interface PvCameraIf
Parameters:
distance - of camera to interest in world coordinates.
See Also:
setScale(double)

getScale

public double getScale()
Get zoom factor of camera.
Specified by:
getScale in interface PvCameraIf
Returns:
zoom factor of camera.
See Also:
getDist()

setScale

public void setScale(double newScale)
Set zoom factor of camera.
Specified by:
setScale in interface PvCameraIf
Parameters:
zoom - factor of camera.
See Also:
setDist(double)

getRoll

public double getRoll()
Get angle which camera is rotated around viewing direction against default position. The default position depends on the projection mode of the camera.

Mathematically, the roll is the angle between the two planes p1=(viewDir, defaultUpVector) and p2=(viewDir, upVector). The defaultUpVector depends on the projection mode, in xy-projection mode we have defaultUpVector=(0,1,0) since camera looks down the negative z-axis and the positive y-axis is showing upward.

Specified by:
getRoll in interface PvCameraIf
Returns:
angle in (-pi,pi)
See Also:
setRoll(double)

setRoll

public void setRoll(double roll)
Set angle which camera is rotated around viewing direction against default position. The default position depends on the projection mode of the camera.
Specified by:
setRoll in interface PvCameraIf
Parameters:
angle - in (-pi,pi)
See Also:
getRoll()

getInterest

public PdVector getInterest()
Get position at which camera is directed, i.e. the point of interest. Interest is implicitly stores as the 4th column of the inverse viewing matrix.
interest = viewInv[.][3]
Specified by:
getInterest in interface PvCameraIf
Returns:
3d-coordinates of interest in world coordinates.

setInterest

public void setInterest(PdVector pos)
Set location at which camera is directed, i.e. the point of interest. This method does not change the viewing direction, that means, implicitly the camera position is moved parallel in order to keep the same viewing direction.

This behaviour results from the steering inside the camera panel where a user may change the interest, viewing direction and distance. User who want to set camera position and interest are advised either to first set the interest and then the position, or to set the viewing direction and the interest.

Specified by:
setInterest in interface PvCameraIf
Parameters:
pos - 3d-coordinates of interest in world coordinates.

getPosition

public PdVector getPosition()
Get position of camera in world coordinates. The camera position is implicitly stored and computed from
position = interest - dist*viewDir
.
Specified by:
getPosition in interface PvCameraIf
Returns:
3d-position of camera in world coordinates.

setPosition

public void setPosition(PdVector pos)
Set position of camera in world coordinates. The camera position is implicitly stored by equation
position = interest - dist*viewDir
.
Specified by:
setPosition in interface PvCameraIf
Parameters:
pos - 3d-position of camera in world coordinates.

getUpVector

public PdVector getUpVector()
Get up vector as second row of viewing matrix divided by scaling factor.
upDir = -view[1][.] / getScale()
.
Specified by:
getUpVector in interface PvCameraIf
Returns:
normalized up vector of camera in world coordinates.

setUpVector

public void setUpVector(PdVector up)
Set normalized up vector of camera in world coordinates.
Specified by:
setUpVector in interface PvCameraIf
Parameters:
normalized - up vector of camera in world coordinates.

fit

public void fit(double diameter)
Fit object with given diameter into current display window. Compute scaling factor such that diameter (in world coordinates) corresponds to width of image

resizeImage

protected void resizeImage(double aWidth,
                           double aHeight)
Assign dimension of viewing canvas to allow normalization of pixel coordinates.

mousePressed

protected void mousePressed(int x,
                            int y)
Reset some values used in increment calculations when mouse is pressed. Mouse functions are called from DisplayIf window, not from system.

mouseDragged

protected void mouseDragged(int x,
                            int y)
Calculate transformation matrices based on incremental mouse movements. Mouse functions are called from DisplayIf window, not from system.

The trackball computation uses the increment in the mouse movement in the canvas to calculate the axis of rotation and the angle about to rotate. The axis is obtained as crossproduct of the following to vectors: First, m_vec is the vector obtained by projecting the current mouse position to the sphere by inverse stereographic projection PdVector.invStereoProj(). Second, the vector of the previous mouse position is still stored in m_vecAlt. The angle to rotate is just the angle between both vectors.

Then the increment of transformation matrix is just the matrix which rotates around m_vec x m_vecAlt with above angle. The code for computing this transformation matrix is PuReflect.makeRotation().


mouseAnimate

protected void mouseAnimate()
Iteratively apply incremental transformation matrices during auto-rotate.

mouseAnimateGeometry

protected void mouseAnimateGeometry()
Iteratively apply incremental transformation matrices during auto-rotate.

getBounds

public PdVector[] getBounds()
Get transformed bounding box used in clipping.

JavaView® v2.00.008

The software JavaView® is copyright protected. All Rights Reserved.