org.jzy3d.plot3d.rendering.view
Class Camera

java.lang.Object
  extended by org.jzy3d.plot3d.rendering.view.Camera

public class Camera
extends Object

A Camera allow to define on the view and target points in a cartesian coordinate system. The Camera provides the following services:

Author:
Martin Pernollet

Field Summary
static boolean DEFAULT_CAMERA_DISTANCE_MODE
          Defines if camera distance is real, or only squared (squared distance avoid computing Math.sqrt() and is thus faster).
static Coord3d DEFAULT_VIEW
          The polar default view point, i.e.
protected  Coord3d eye
           
protected  float far
           
protected  ViewportConfiguration lastViewPort
           
protected  ViewportMode mode
           
protected  float near
           
protected  float radius
           
protected  float ratioHeight
           
protected  float ratioWidth
           
protected  int screenBottom
           
protected  boolean screenGridDisplayed
           
protected  int screenHeight
           
protected  int screenLeft
           
protected  int screenSquaredDim
           
protected  int screenWidth
           
protected  int screenXOffset
           
protected  int screenYOffset
           
protected  Coord3d target
           
protected  Coord3d up
           
protected  boolean useSquaredDistance
           
 
Constructor Summary
Camera(Coord3d target)
          Set up a Camera looking at target, with a viewpoint standing at target+(0,0,100).
 
Method Summary
protected  ViewportConfiguration applyViewport(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu)
          Build and return a ViewportConfiguration.
protected  double computeFieldOfView(double size, double distance)
          Compute the field of View, in order to occupy the entire screen in PERSPECTIVE mode.
 void doShoot(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, CameraMode projection)
           
protected  void failedProjection(String message)
           
 double getDistance(AbstractDrawable drawable)
          Return the distance between the camera eye and the given drawable's barycenter.
 double getDistance(AbstractDrawable drawable, Coord3d viewScale)
          Apply scaling before computing distance between the camera eye and the given drawable's barycenter.
 double getDistance(Coord3d coord)
          Return the distance between the camera eye and the given coordinate.
 double getDistance(Coord3d coord, Coord3d viewScale)
          Apply scaling before computing distance between the camera eye and the given coordinate.
 Coord3d getEye()
          Returns the eye's position.
 float getFar()
          Return the position of the "far" clipping plane
 ViewportConfiguration getLastViewPort()
           
 ViewportMode getMode()
           
protected  double[] getModelViewAsDouble(javax.media.opengl.GL gl)
           
protected  float[] getModelViewAsFloat(javax.media.opengl.GL gl)
           
 float getNear()
          Return the position of the "near" clipping plane
protected  double[] getProjectionAsDouble(javax.media.opengl.GL gl)
           
protected  float[] getProjectionAsFloat(javax.media.opengl.GL gl)
           
 Rectangle getRectangle()
          Returns the (x,y) offset that was applied to make this AbstractViewportManager stand in the appropriate canvas part. and the actual width and height of the viewport.
 float getRenderingSphereRadius()
          Return the radius of the sphere that will be contained into the rendered view.
 Coord3d getTarget()
          Returns the target's position that was set at the last call to lookAt().
 Coord3d getUp()
          Returns the top of the camera.
protected  int[] getViewPortAsInt(javax.media.opengl.GL gl)
           
 boolean isTiltUp()
          Returns true if the camera is 'looking up', in other word if the eye's Z value is inferior to the target's Z value.
 boolean isUseSquaredDistance()
           
 ArrayList<ArrayList<Coord3d>> modelToScreen(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, ArrayList<ArrayList<Coord3d>> polygons)
           
 Coord3d modelToScreen(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, Coord3d point)
          Transform a 3d point coordinate into its screen position.
 Coord3d[] modelToScreen(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, Coord3d[] points)
           
 Coord3d[][] modelToScreen(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, Coord3d[][] points)
           
 Grid modelToScreen(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, Grid grid)
           
 List<Coord3d> modelToScreen(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, List<Coord3d> points)
           
 PolygonArray modelToScreen(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, PolygonArray polygon)
           
 PolygonArray[][] modelToScreen(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, PolygonArray[][] polygons)
           
 Coord3d screenToModel(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, Coord3d screen)
          Transform a 2d screen coordinate into a 3d coordinate.
 void setEye(Coord3d eye)
          Set the eye's position.
 void setRenderingDepth(float near, float far)
          Manually set the rendering depth (near and far clipping planes).
 void setRenderingSphereRadius(float radius)
          Set the radius of the sphere that will be contained into the rendered view.
 void setScreenGridDisplayed(boolean status)
          Set the status of the screen grid.
 void setTarget(Coord3d target)
          Set the target point of the camera.
 void setUp(Coord3d up)
          Set the top of the camera.
 void setUseSquaredDistance(boolean useSquaredDistance)
          Defines what getDistance(...) will return, either: Squared distance (faster to compute since no Math.sqrt(...) at the end) Real distance Default value is set to true, meaning it use the faster squared distance.
 void setViewPort(int width, int height)
          Set the view port (size of the renderer).
 void setViewPort(int width, int height, float left, float right)
          Set the view port (size of the renderer).
 void setViewPort(ViewportConfiguration viewport)
           
 void setViewportMode(ViewportMode mode)
           
 void shoot(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, CameraMode projection)
          Sets the projection and the mapping of the 3d model to 2d screen.
 void shoot(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, CameraMode projection, boolean doPushMatrixBeforeShooting)
           
 void show(javax.media.opengl.GL gl, Transform transform, Coord3d scaling)
           
 boolean side(Coord3d point)
          Return true if the given point is on the left of the vector eye->target.
 String toString()
          Print out in console information concerning the camera.
protected  String toString(Coord3d eye, Coord3d target, Coord3d up)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_VIEW

public static final Coord3d DEFAULT_VIEW
The polar default view point, i.e. Coord3d(Math.PI/3,Math.PI/5,500).


DEFAULT_CAMERA_DISTANCE_MODE

public static final boolean DEFAULT_CAMERA_DISTANCE_MODE
Defines if camera distance is real, or only squared (squared distance avoid computing Math.sqrt() and is thus faster). Second mode requires value true

See Also:
Constant Field Values

eye

protected Coord3d eye

target

protected Coord3d target

up

protected Coord3d up

radius

protected float radius

near

protected float near

far

protected float far

useSquaredDistance

protected boolean useSquaredDistance

lastViewPort

protected ViewportConfiguration lastViewPort

screenLeft

protected int screenLeft

screenBottom

protected int screenBottom

screenXOffset

protected int screenXOffset

screenYOffset

protected int screenYOffset

screenWidth

protected int screenWidth

screenHeight

protected int screenHeight

screenSquaredDim

protected int screenSquaredDim

screenGridDisplayed

protected boolean screenGridDisplayed

mode

protected ViewportMode mode

ratioWidth

protected float ratioWidth

ratioHeight

protected float ratioHeight
Constructor Detail

Camera

public Camera(Coord3d target)
Set up a Camera looking at target, with a viewpoint standing at target+(0,0,100). The top of the camera is set up toward the positive Z direction.

Method Detail

setEye

public void setEye(Coord3d eye)
Set the eye's position.


getEye

public Coord3d getEye()
Returns the eye's position.


setTarget

public void setTarget(Coord3d target)
Set the target point of the camera.


getTarget

public Coord3d getTarget()
Returns the target's position that was set at the last call to lookAt().


setUp

public void setUp(Coord3d up)
Set the top of the camera.


getUp

public Coord3d getUp()
Returns the top of the camera.


isTiltUp

public boolean isTiltUp()
Returns true if the camera is 'looking up', in other word if the eye's Z value is inferior to the target's Z value.


setRenderingSphereRadius

public void setRenderingSphereRadius(float radius)
Set the radius of the sphere that will be contained into the rendered view. As a side effect, the "far" clipping plane is modified according to the eye-target distance, and the position of the "near" clipping plane.


getRenderingSphereRadius

public float getRenderingSphereRadius()
Return the radius of the sphere that will be contained into the rendered view.


setRenderingDepth

public void setRenderingDepth(float near,
                              float far)
Manually set the rendering depth (near and far clipping planes). Note that Camera.setRenderingSphereRadius modified the "far" clipping plane.


getNear

public float getNear()
Return the position of the "near" clipping plane


getFar

public float getFar()
Return the position of the "far" clipping plane


side

public boolean side(Coord3d point)
Return true if the given point is on the left of the vector eye->target.


screenToModel

public Coord3d screenToModel(javax.media.opengl.GL gl,
                             javax.media.opengl.glu.GLU glu,
                             Coord3d screen)
Transform a 2d screen coordinate into a 3d coordinate. The z component of the screen coordinate indicates a depth value between the near and far clipping plane of the Camera.

Throws:
a - RuntimeException if an error occured while trying to retrieve model coordinates

modelToScreen

public Coord3d modelToScreen(javax.media.opengl.GL gl,
                             javax.media.opengl.glu.GLU glu,
                             Coord3d point)
Transform a 3d point coordinate into its screen position.

Throws:
a - RuntimeException if an error occured while trying to retrieve model coordinates

modelToScreen

public Coord3d[] modelToScreen(javax.media.opengl.GL gl,
                               javax.media.opengl.glu.GLU glu,
                               Coord3d[] points)

modelToScreen

public Coord3d[][] modelToScreen(javax.media.opengl.GL gl,
                                 javax.media.opengl.glu.GLU glu,
                                 Coord3d[][] points)

modelToScreen

public List<Coord3d> modelToScreen(javax.media.opengl.GL gl,
                                   javax.media.opengl.glu.GLU glu,
                                   List<Coord3d> points)

modelToScreen

public ArrayList<ArrayList<Coord3d>> modelToScreen(javax.media.opengl.GL gl,
                                                   javax.media.opengl.glu.GLU glu,
                                                   ArrayList<ArrayList<Coord3d>> polygons)

modelToScreen

public PolygonArray modelToScreen(javax.media.opengl.GL gl,
                                  javax.media.opengl.glu.GLU glu,
                                  PolygonArray polygon)

modelToScreen

public Grid modelToScreen(javax.media.opengl.GL gl,
                          javax.media.opengl.glu.GLU glu,
                          Grid grid)

modelToScreen

public PolygonArray[][] modelToScreen(javax.media.opengl.GL gl,
                                      javax.media.opengl.glu.GLU glu,
                                      PolygonArray[][] polygons)

failedProjection

protected void failedProjection(String message)

getViewPortAsInt

protected int[] getViewPortAsInt(javax.media.opengl.GL gl)

getProjectionAsDouble

protected double[] getProjectionAsDouble(javax.media.opengl.GL gl)

getProjectionAsFloat

protected float[] getProjectionAsFloat(javax.media.opengl.GL gl)

getModelViewAsDouble

protected double[] getModelViewAsDouble(javax.media.opengl.GL gl)

getModelViewAsFloat

protected float[] getModelViewAsFloat(javax.media.opengl.GL gl)

show

public void show(javax.media.opengl.GL gl,
                 Transform transform,
                 Coord3d scaling)

shoot

public void shoot(javax.media.opengl.GL gl,
                  javax.media.opengl.glu.GLU glu,
                  CameraMode projection)
Sets the projection and the mapping of the 3d model to 2d screen. The projection must be either Camera.PERSPECTIVE or Camera.ORTHOGONAL.
shoot() finally calls the GL function glLookAt, according to the stored eye, target, up and scale values.
Note that the Camera set by itselft the MatrixMode to model view at the end of a shoot().

Parameters:
gl - GL2 context.
glu - GLU context.
projection - the projection mode.
Throws:
a - Runtime Exception if the projection mode is neither Camera.PERSPECTIVE nor Camera.ORTHOGONAL.

shoot

public void shoot(javax.media.opengl.GL gl,
                  javax.media.opengl.glu.GLU glu,
                  CameraMode projection,
                  boolean doPushMatrixBeforeShooting)

doShoot

public void doShoot(javax.media.opengl.GL gl,
                    javax.media.opengl.glu.GLU glu,
                    CameraMode projection)

computeFieldOfView

protected double computeFieldOfView(double size,
                                    double distance)
Compute the field of View, in order to occupy the entire screen in PERSPECTIVE mode.


getDistance

public double getDistance(AbstractDrawable drawable)
Return the distance between the camera eye and the given drawable's barycenter.


getDistance

public double getDistance(AbstractDrawable drawable,
                          Coord3d viewScale)
Apply scaling before computing distance between the camera eye and the given drawable's barycenter.


getDistance

public double getDistance(Coord3d coord)
Return the distance between the camera eye and the given coordinate.


getDistance

public double getDistance(Coord3d coord,
                          Coord3d viewScale)
Apply scaling before computing distance between the camera eye and the given coordinate.


isUseSquaredDistance

public boolean isUseSquaredDistance()

setUseSquaredDistance

public void setUseSquaredDistance(boolean useSquaredDistance)
Defines what getDistance(...) will return, either: Default value is set to true, meaning it use the faster squared distance.


toString

public String toString()
Print out in console information concerning the camera.

Overrides:
toString in class Object

toString

protected String toString(Coord3d eye,
                          Coord3d target,
                          Coord3d up)

setViewPort

public void setViewPort(int width,
                        int height)
Set the view port (size of the renderer).

Parameters:
width - the width of the target window.
height - the height of the target window.

getMode

public ViewportMode getMode()

setViewportMode

public void setViewportMode(ViewportMode mode)

setViewPort

public void setViewPort(int width,
                        int height,
                        float left,
                        float right)
Set the view port (size of the renderer).

Parameters:
width - the width of the target window.
height - the height of the target window.
left - the width's ratio where this subscreen starts in the target window.
right - the width's ratio where this subscreen stops in the target window.
Throws:
an - IllegalArgumentException if right is not greater than left.

setViewPort

public void setViewPort(ViewportConfiguration viewport)

getLastViewPort

public ViewportConfiguration getLastViewPort()

applyViewport

protected ViewportConfiguration applyViewport(javax.media.opengl.GL gl,
                                              javax.media.opengl.glu.GLU glu)
Build and return a ViewportConfiguration. Uses gl to

Parameters:
gl -
glu -

getRectangle

public Rectangle getRectangle()
Returns the (x,y) offset that was applied to make this AbstractViewportManager stand in the appropriate canvas part. and the actual width and height of the viewport. Only relevant after a call to applyViewPort.


setScreenGridDisplayed

public void setScreenGridDisplayed(boolean status)
Set the status of the screen grid.

Parameters:
status - the grid is displayed if status is set to true


Copyright © 2013. All rights reserved.