Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## proscene
Class PSCamera

    java.lang.Object
      proscene.PSCamera

All Implemented Interfaces:
  java.lang.Cloneable

    public class PSCamera

extends java.lang.Object
implements java.lang.Cloneable

A perspective or orthographic camera.

A PSCamera defines some intrinsic parameters (`fieldOfView()`, `position()`, `viewDirection()`, `upVector()`...) and useful positioning tools that ease its placement (`showEntireScene()`, `fitSphere(PVector, float)`, `lookAt(PVector)`...). It exports its associated projection and modelview matrices and can interactively be modified using the mouse.

Nested Class Summary
`static class` | `PSCamera.Type` Enumerates the two possible types of Camera.

Constructor Summary
`PSCamera()` Default constructor.

Method Summary
`float` | `aspectRatio()` Returns the PSCamera aspect ratio defined by `screenWidth()` / `screenHeight()`.
`processing.core.PVector` | `at()` Returns a point defined in the world coordinate system where the camera is pointing at (just in front of `viewDirection()`).
`processing.core.PVector` | `cameraCoordinatesOf(processing.core.PVector src)` Returns the PSCamera frame coordinates of a point `src` defined in world coordinates.
`void` | `centerScene()` Moves the PSCamera so that its `sceneCenter()` is projected on the center of the window.
`PSCamera` | `clone()` Implementation of the clone method.
`void` | `computeModelViewMatrix()` Computes the modelView matrix associated with the Camera's `position()` and `orientation()`.
`void` | `computeProjectionMatrix()` Computes the projection matrix associated with the PSCamera.
`void` | `convertClickToLine(java.awt.Point pixelInput, processing.core.PVector orig, processing.core.PVector dir)` Gives the coefficients of a 3D half-line passing through the PSCamera eye and pixel (x,y).
`float` | `distanceToSceneCenter()` Returns the distance from the Camera center to `sceneCenter()`, projected along the Camera Z axis.
`float` | `fieldOfView()` Returns the vertical field of view of the PSCamera (in radians).
`void` | `fitBoundingBox(processing.core.PVector min, processing.core.PVector max)` Moves the PSCamera so that the (world axis aligned) bounding box (`min`, `max`) is entirely visible, using `fitSphere(PVector, float)`.
`void` | `fitScreenRegion(java.awt.Rectangle rectangle)` Moves the PSCamera so that the rectangular screen region defined by `rectangle` (pixel units, with origin in the upper left corner) fits the screen.
`void` | `fitSphere(processing.core.PVector center, float radius)` Moves the PSCamera so that the sphere defined by `center`, `radius`) is visible and fits the window.
`float` | `flySpeed()` Returns the fly speed of the PSCamera.
`float` | `focusDistance()` Returns the focus distance used by stereo display, expressed in processing units.
`PSInteractiveCameraFrame` | `frame()` Returns the PSInteractiveCameraFrame attached to the PSCamera.
`processing.core.PMatrix3D` | `getModelViewMatrix()` Convenience function that simply returns `return getModelViewMatrix(new PMatrix3D())`
`processing.core.PMatrix3D` | `getModelViewMatrix(processing.core.PMatrix3D m)` Fills `m` with the Camera modelView matrix values and returns it.
`float[]` | `getOrthoWidthHeight()` Convenience function that simply returns `getOrthoWidthHeight(new float[2])`.
`float[]` | `getOrthoWidthHeight(float[] target)` Fills in `target` with the `halfWidth` and `halfHeight` of the PSCamera orthographic frustum and returns it.
`processing.core.PMatrix3D` | `getProjectionMatrix()` Convenience function that simply returns `return return getProjectionMatrix(new PMatrix3D())`
`processing.core.PMatrix3D` | `getProjectionMatrix(processing.core.PMatrix3D m)` Fills `m` with the PSCamera projection matrix values and returns it.
`int[]` | `getViewport()` Convenience function that simply calls `return` `getViewport(int[])`.
`int[]` | `getViewport(int[] viewport)` Fills `viewport` with the PSCamera viewport and returns it.
`float` | `horizontalFieldOfView()` Returns the horizontal field of view of the PSCamera (in radians).
`float` | `IODistance()` Returns the user's inter-ocular distance (in meters).
`void` | `lookAt(processing.core.PVector target)` Sets the PSCamera `orientation()`, so that it looks at point `target` (defined in the world coordinate system).
`PSQuaternion` | `orientation()` Returns the PSCamera orientation, defined in the world coordinate system.
`float` | `physicalDistanceToScreen()` Returns the physical distance between the user's eyes and the screen (in meters).
`float` | `physicalScreenWidth()` Returns the physical screen width, in meters.
`float` | `pixelPSRatio(processing.core.PVector position)` Returns the ratio between pixel and processing scene units at `position`.
`processing.core.PVector` | `position()` Returns the PSCamera position (the eye), defined in the world coordinate system.
`processing.core.PVector` | `projectedCoordinatesOf(processing.core.PVector src)` Convenience function that simply returns `return projectedCoordinatesOf(src, null)`
`processing.core.PVector` | `projectedCoordinatesOf(processing.core.PVector src, PSFrame frame)` Returns the screen projected coordinates of a point `src` defined in the `frame` coordinate system.
`processing.core.PVector` | `revolveAroundPoint()` The point the PSCamera revolves around its `PSInteractiveCameraFrame.revolveAroundPoint()`.
`processing.core.PVector` | `rightVector()` Returns the normalized right vector of the PSCamera, defined in the world coordinate system.
`processing.core.PVector` | `sceneCenter()` Returns the position of the scene center, defined in the world coordinate system.
`float` | `sceneRadius()` Returns the radius of the scene observed by the Camera.
`int` | `screenHeight()` Returns the height (in pixels) of the PSCamera screen.
`int` | `screenWidth()` Returns the width (in pixels) of the PSCamera screen.
`void` | `setAspectRatio(float aspect)` Defines the PSCamera `aspectRatio()`.
`void` | `setCoordinateSystemLeftHanded()` Wrapper function that simply calls `frame().setCoordinateSystemConvention(CoordinateSystemConvention.LEFT_HANDED)`
`void` | `setCoordinateSystemRightHanded()` Wrapper function that simply calls `frame().setCoordinateSystemConvention(CoordinateSystemConvention.RIGHT_HANDED)`
`void` | `setFieldOfView(float fov)` Sets the vertical `fieldOfView()` of the PSCamera (in radians).
`void` | `setFlySpeed(float speed)` Sets the PSCamera `flySpeed()`.
`void` | `setFocusDistance(float distance)` Sets the focusDistance(), in processing scene units.
`void` | `setFOVToFitScene()` Changes the PSCamera `fieldOfView()` so that the entire scene (defined by `PScene.sceneCenter()` and `PScene.sceneRadius()` is visible from the PSCamera `position()`.
`void` | `setFrame(PSInteractiveCameraFrame icf)` Sets the PSCamera `frame()`.
`void` | `setHorizontalFieldOfView(float hfov)` Sets the `horizontalFieldOfView()` of the PSCamera (in radians).
`void` | `setIODistance(float distance)` Sets the `IODistance()`.
`void` | `setModelViewMatrix(processing.core.PMatrix3D modelview)` Sets the modelview matrix associated with the PSCamera directly from a PCamera.
`void` | `setOrientation(float theta, float phi)` Sets the `orientation()` of the PSCamera using polar coordinates.
`void` | `setOrientation(PSQuaternion q)` Sets the PSCamera `orientation()`, defined in the world coordinate system.
`void` | `setPhysicalDistanceToScreen(float distance)` Sets the `physicalDistanceToScreen()`.
`void` | `setPhysicalScreenWidth(float width)` Sets the physical screen (monitor or projected wall) width (in meters).
`void` | `setPosition(processing.core.PVector pos)` Sets the PSCamera `position()` (the eye), defined in the world coordinate system.
`void` | `setProjectionMatrix(processing.core.PMatrix3D proj)` Sets the projection matrix associated with the PSCamera directly from a PCamera.
`void` | `setRevolveAroundPoint(processing.core.PVector rap)` Changes the `revolveAroundPoint()` to `rap` (defined in the world coordinate system).
`void` | `setSceneBoundingBox(processing.core.PVector min, processing.core.PVector max)` Similar to `setSceneRadius(float)` and `setSceneCenter(PVector)`, but the scene limits are defined by a (world axis aligned) bounding box.
`void` | `setSceneCenter(processing.core.PVector center)` Sets the `sceneCenter()`.
`void` | `setSceneRadius(float radius)` Sets the `sceneRadius()` value.
`void` | `setScreenWidthAndHeight(int width, int height)` Sets PSCamera `screenWidth()` and `screenHeight()` (expressed in pixels).
`void` | `setType(PSCamera.Type type)` Defines the PSCamera `type()`.
`void` | `setUpVector(processing.core.PVector up)` Convenience function that simply calls `setUpVector(up, true)`.
`void` | `setUpVector(processing.core.PVector up, boolean noMove)` Rotates the PSCamera so that its `upVector()` becomes `up` (defined in the world coordinate system).
`void` | `setViewDirection(processing.core.PVector direction)` Rotates the PSCamera so that its `viewDirection()` is `direction` (defined in the world coordinate system).
`void` | `setZClippingCoefficient(float coef)` Sets the `zClippingCoefficient()` value.
`void` | `setZNearCoefficient(float coef)` Sets the `zNearCoefficient()` value.
`void` | `showEntireScene()` Moves the PSCamera so that the entire scene is visible.
`PSCamera.Type` | `type()` Returns the PSCamera.Type of the PSCamera.
`processing.core.PVector` | `upVector()` Returns the normalized up vector of the PSCamera, defined in the world coordinate system.
`processing.core.PVector` | `viewDirection()` Returns the normalized view direction of the PSCamera, defined in the world coordinate system.
`processing.core.PVector` | `worldCoordinatesOf(processing.core.PVector src)` Returns the world coordinates of the point whose position `src` is defined in the PSCamera coordinate system.
`float` | `zClippingCoefficient()` Returns the coefficient used to position the near and far clipping planes.
`float` | `zFar()` Returns the far clipping plane distance used by the Camera projection matrix.
`float` | `zNear()` Returns the near clipping plane distance used by the PSCamera projection matrix.
`float` | `zNearCoefficient()` Returns the coefficient which is used to set `zNear()` when the PSCamera is inside the sphere defined by `sceneCenter()` and `zClippingCoefficient()` * `sceneRadius()`.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PSCamera

    public PSCamera()

  Default constructor.

  `sceneCenter()` is set to (0,0,0) and `sceneRadius()` is set to 1.0. `type()` PSCamera.PERSPECTIVE, with a `PI/4` `fieldOfView()`.

  See `IODistance()`, `physicalDistanceToScreen()`, `physicalScreenWidth()` and `focusDistance()` documentations for default stereo parameter values.

Method Detail

### clone

    public PSCamera clone()

  Implementation of the clone method.

  Calls `PSFrame.clone()` and makes a deep copy of the remaining object attributes except for `prevConstraint` (which is shallow copied).

  Overrides:
    `clone` in class `java.lang.Object`
  See Also:
    `PSFrame.clone()`

### position

    public final processing.core.PVector position()

  Returns the PSCamera position (the eye), defined in the world coordinate system.

  Use `setPosition(PVector)` to set the Camera position. Other convenient methods are showEntireScene() or fitSphere(). Actually returns `PSFrame.position()`.

  This position corresponds to the projection center of a PSCamera.PERSPECTIVE camera. It is not located in the image plane, which is at a zNear() distance ahead.

### setPosition

    public void setPosition(processing.core.PVector pos)

  Sets the PSCamera `position()` (the eye), defined in the world coordinate system.

### upVector

    public processing.core.PVector upVector()

  Returns the normalized up vector of the PSCamera, defined in the world coordinate system.

  Set using `setUpVector(PVector)` or `setOrientation(PSQuaternion)`. It is orthogonal to `viewDirection()` and to `rightVector()`.

  It corresponds to the Y axis of the associated `frame()` (actually returns `PSFrame.inverseTransformOf(PVector)`)

### setUpVector

    public void setUpVector(processing.core.PVector up)

  Convenience function that simply calls `setUpVector(up, true)`.

  See Also:
    `setUpVector(PVector, boolean)`

### setUpVector

    public void setUpVector(processing.core.PVector up,
                            boolean noMove)

  Rotates the PSCamera so that its `upVector()` becomes `up` (defined in the world coordinate system).

  The PSCamera is rotated around an axis orthogonal to `up` and to the current `upVector()` direction.

  Use this method in order to define the PSCamera horizontal plane.

  When `noMove` is set to `false`, the orientation modification is compensated by a translation, so that the `revolveAroundPoint()` stays projected at the same position on screen. This is especially useful when the PSCamera is an observer of the scene (default mouse binding).

  When `noMove` is true, the PSCamera `position()` is left unchanged, which is an intuitive behavior when the PSCamera is in a walkthrough fly mode. See also setViewDirection(), lookAt() and setOrientation().

### viewDirection

    public processing.core.PVector viewDirection()

  Returns the normalized view direction of the PSCamera, defined in the world coordinate system.

  Change this value using `setViewDirection(PVector)`, `lookAt(PVector)` or `setOrientation(PSQuaternion)`. It is orthogonal to `upVector()` and to `rightVector()`.

  This corresponds to the negative Z axis of the `frame()` ( `frame().inverseTransformOf(new PVector(0.0f, 0.0f, -1.0f))` ).

### setViewDirection

    public void setViewDirection(processing.core.PVector direction)

  Rotates the PSCamera so that its `viewDirection()` is `direction` (defined in the world coordinate system).

  The PSCamera `position()` is not modified. The PSCamera is rotated so that the horizon (defined by its `upVector()`) is preserved.

  See Also:
    `lookAt(PVector)`, `setUpVector(PVector)`

### rightVector

    public processing.core.PVector rightVector()

  Returns the normalized right vector of the PSCamera, defined in the world coordinate system.

  This vector lies in the PSCamera horizontal plane, directed along the X axis (orthogonal to `upVector()` and to `viewDirection()`. Set using `setUpVector(PVector)`, `lookAt(PVector)` or `setOrientation(PSQuaternion)`.

  Simply returns `frame().inverseTransformOf(new PVector(1.0f, 0.0f, 0.0f))`.

### orientation

    public PSQuaternion orientation()

  Returns the PSCamera orientation, defined in the world coordinate system.

  Actually returns `frame().orientation()`. Use `setOrientation(PSQuaternion)`, `setUpVector(PVector)` or `lookAt(PVector)` to set the PSCamera orientation.

### setOrientation

    public void setOrientation(float theta,
                               float phi)

  Sets the `orientation()` of the PSCamera using polar coordinates.

  `theta` rotates the PSCamera around its Y axis, and then `phi` rotates it around its X axis.

  The polar coordinates are defined in the world coordinates system: `theta = phi = 0` means that the PSCamera is directed towards the world Z axis. Both angles are expressed in radians.

  The `position()` of the PSCamera is unchanged, you may want to call `showEntireScene()` after this method to move the PSCamera.

  See Also:
    `setUpVector(PVector)`

### setOrientation

    public void setOrientation(PSQuaternion q)

  Sets the PSCamera `orientation()`, defined in the world coordinate system.

### setCoordinateSystemLeftHanded

    public void setCoordinateSystemLeftHanded()

  Wrapper function that simply calls `frame().setCoordinateSystemConvention(CoordinateSystemConvention.LEFT_HANDED)`

### setCoordinateSystemRightHanded

    public void setCoordinateSystemRightHanded()

  Wrapper function that simply calls `frame().setCoordinateSystemConvention(CoordinateSystemConvention.RIGHT_HANDED)`

### type

    public final PSCamera.Type type()

  Returns the PSCamera.Type of the PSCamera.

  Set by `setType(Type)`.

  A `PSCamera.Type.PERSPECTIVE` PSCamera uses a classical projection mainly defined by its `fieldOfView()`.

  With a `PSCamera.Type.ORTHOGRAPHIC` `type()`, the `fieldOfView()` is meaningless and the width and height of the PSCamera frustum are inferred from the distance to the `revolveAroundPoint()` using `getOrthoWidthHeight()`.

  Both types use `zNear()` and `zFar()` (to define their clipping planes) and `aspectRatio()` (for frustum shape).

### setType

    public final void setType(PSCamera.Type type)

  Defines the PSCamera `type()`.

  Changing the PSCamera Type alters the viewport and the objects' size can be changed. This method guarantees that the two frustum match in a plane normal to `viewDirection()`, passing through the Revolve Around Point (RAP).

### fieldOfView

    public float fieldOfView()

  Returns the vertical field of view of the PSCamera (in radians).

  Value is set using `setFieldOfView(float)`. Default value is pi/4 radians. This value is meaningless if the PSCamera `type()` is `PSCamera.Type.ORTHOGRAPHIC`.

  The field of view corresponds the one used in `gluPerspective` (see manual). It sets the Y (vertical) aperture of the PSCamera. The X (horizontal) angle is inferred from the window aspect ratio (see `aspectRatio()` and `horizontalFieldOfView()`).

  Use `setFOVToFitScene()` to adapt the `fieldOfView()` to a given scene.

### setFieldOfView

    public void setFieldOfView(float fov)

  Sets the vertical `fieldOfView()` of the PSCamera (in radians).

  Note that `focusDistance()` is set to `sceneRadius()` / tan( `fieldOfView()`/2) by this method.

### setFOVToFitScene

    public void setFOVToFitScene()

  Changes the PSCamera `fieldOfView()` so that the entire scene (defined by `PScene.sceneCenter()` and `PScene.sceneRadius()` is visible from the PSCamera `position()`.

  The `position()` and `orientation()` of the PSCamera are not modified and you first have to orientate the PSCamera in order to actually see the scene (see `lookAt(PVector)`, `showEntireScene()` or `fitSphere(PVector, float)`).

  This method is especially useful for shadow maps computation. Use the PSCamera positioning tools (`setPosition(PVector)`, `lookAt(PVector)`) to position a PSCamera at the light position. Then use this method to define the `fieldOfView()` so that the shadow map resolution is optimally used:

  `// The light camera needs size hints in order to optimize its fieldOfView`
  `lightCamera.setSceneRadius(sceneRadius());`
  `lightCamera.setSceneCenter(sceneCenter());`
  `// Place the light camera`
  `lightCamera.setPosition(lightFrame.position());`
  `lightCamera.lookAt(sceneCenter());`
  `lightCamera.setFOVToFitScene();`

  Attention: The `fieldOfView()` is clamped to M_PI/2.0. This happens when the PSCamera is at a distance lower than sqrt(2.0) * sceneRadius() from the sceneCenter(). It optimizes the shadow map resolution, although it may miss some parts of the scene.

### getOrthoWidthHeight

    public float[] getOrthoWidthHeight()

  Convenience function that simply returns `getOrthoWidthHeight(new float[2])`.

### getOrthoWidthHeight

    public float[] getOrthoWidthHeight(float[] target)

  Fills in `target` with the `halfWidth` and `halfHeight` of the PSCamera orthographic frustum and returns it.

  While `target[0]` holds `halfWidth`, `target[1]` holds `halfHeight`.

  These values are only valid and used when the PSCamera is of `type()` ORTHOGRAPHIC and they are expressed in processing scene units.

  These values are proportional to the PSCamera (z projected) distance to the `revolveAroundPoint()`. When zooming on the object, the PSCamera is translated forward \e and its frustum is narrowed, making the object appear bigger on screen, as intuitively expected.

  Overload this method to change this behavior if desired.

### horizontalFieldOfView

    public float horizontalFieldOfView()

  Returns the horizontal field of view of the PSCamera (in radians).

  Value is set using `setHorizontalFieldOfView(float)` or `setFieldOfView(float)`. These values are always linked by: `horizontalFieldOfView() = 2.0 * atan ( tan(fieldOfView()/2.0) * aspectRatio() )`.

### setHorizontalFieldOfView

    public void setHorizontalFieldOfView(float hfov)

  Sets the `horizontalFieldOfView()` of the PSCamera (in radians).

  `horizontalFieldOfView()` and `fieldOfView()` are linked by the `aspectRatio()`. This method actually calls `setFieldOfView(( 2.0 * atan (tan(hfov / 2.0) / aspectRatio()) ))` so that a call to `horizontalFieldOfView()` returns the expected value.

### aspectRatio

    public float aspectRatio()

  Returns the PSCamera aspect ratio defined by `screenWidth()` / `screenHeight()`.

  When the PSCamera is attached to a PSCene, these values and hence the aspectRatio() are automatically fitted to the viewer's window aspect ratio using setScreenWidthAndHeight().

### setAspectRatio

    public void setAspectRatio(float aspect)

  Defines the PSCamera `aspectRatio()`.

  This value is actually inferred from the `screenWidth()` / `screenHeight()` ratio. You should use `setScreenWidthAndHeight(int, int)` instead.

  This method might however be convenient when the PSCamera is not associated with a PScene. It actually sets the `screenHeight()` to 100 and the `screenWidth()` accordingly. See also `setFOVToFitScene()`.

### setScreenWidthAndHeight

    public void setScreenWidthAndHeight(int width,
                                        int height)

  Sets PSCamera `screenWidth()` and `screenHeight()` (expressed in pixels).

  You should not call this method when the PSCamera is associated with a PScene, since the latter automatically updates these values when it is resized (hence overwriting your values).

  Non-positive dimension are silently replaced by a 1 pixel value to ensure frustrum coherence.

  If your PSCamera is used without a PScene (offscreen rendering, shadow maps), use `setAspectRatio(float)` instead to define the projection matrix.

### screenWidth

    public final int screenWidth()

  Returns the width (in pixels) of the PSCamera screen.

  Set using `setScreenWidthAndHeight(int, int)`. This value is automatically fitted to the PScene's window dimensions when the PSCamera is attached to a PScene.

### screenHeight

    public final int screenHeight()

  Returns the height (in pixels) of the PSCamera screen.

  Set using `setScreenWidthAndHeight(int, int)`. This value is automatically fitted to the PScene's window dimensions when the PSCamera is attached to a PScene.

### getViewport

    public int[] getViewport()

  Convenience function that simply calls `return` `getViewport(int[])`.

### getViewport

    public int[] getViewport(int[] viewport)

  Fills `viewport` with the PSCamera viewport and returns it. If viewport is null (or not the correct size), a new array will be created.

  This method is mainly used in conjunction with `gluProject`, which requires such a viewport. Returned values are (0, `screenHeight()`, `screenWidth()`, -`screenHeight()`), so that the origin is located in the upper left corner of the window.

### zNear

    public float zNear()

  Returns the near clipping plane distance used by the PSCamera projection matrix.

  The clipping planes' positions depend on the `sceneRadius()` and `sceneCenter()` rather than being fixed small-enough and large-enough values. A good scene dimension approximation will hence result in an optimal precision of the z-buffer.

  The near clipping plane is positioned at a distance equal to `zClippingCoefficient()` * `sceneRadius()` in front of the `sceneCenter()`: `distanceToSceneCenter() - zClippingCoefficient() * sceneRadius()`

  In order to prevent negative or too small `zNear()` values (which would degrade the z precision), `zNearCoefficient()` is used when the PSCamera is inside the `sceneRadius()` sphere:

  `zMin = zNearCoefficient() * zClippingCoefficient() * sceneRadius();`
  `zNear = zMin;`
  `// With an ORTHOGRAPHIC type, the value is simply clamped to 0.0`

  See also the `zFar()`, `zClippingCoefficient()` and `zNearCoefficient()` documentations.

  If you need a completely different zNear computation, overload the `zNear()` and `zFar()` methods in a new class that publicly inherits from Camera and use `PScene.setCamera(PSCamera)`.

  Attention: The value is always positive although the clipping plane is positioned at a negative z value in the Camera coordinate system. This follows the `gluPerspective` standard.

### zFar

    public float zFar()

  Returns the far clipping plane distance used by the Camera projection matrix.

  The far clipping plane is positioned at a distance equal to `zClippingCoefficient() * sceneRadius()` behind the `sceneCenter()`:

  `zFar = distanceToSceneCenter() + zClippingCoefficient()*sceneRadius();`

  See Also:
    `zNear()`

### zNearCoefficient

    public float zNearCoefficient()

  Returns the coefficient which is used to set `zNear()` when the PSCamera is inside the sphere defined by `sceneCenter()` and `zClippingCoefficient()` * `sceneRadius()`.

  In that case, the `zNear()` value is set to `zNearCoefficient() * zClippingCoefficient() * sceneRadius()`. See the `zNear()` documentation for details.

  Default value is 0.005, which is appropriate for most applications. In case you need a high dynamic ZBuffer precision, you can increase this value (~0.1). A lower value will prevent clipping of very close objects at the expense of a worst Z precision.

  Only meaningful when PSCamera type is PERSPECTIVE.

### setZNearCoefficient

    public void setZNearCoefficient(float coef)

  Sets the `zNearCoefficient()` value.

### zClippingCoefficient

    public float zClippingCoefficient()

  Returns the coefficient used to position the near and far clipping planes.

  The near (resp. far) clipping plane is positioned at a distance equal to `zClippingCoefficient() * sceneRadius()` in front of (resp. behind) the `sceneCenter()`. This guarantees an optimal use of the z-buffer range and minimizes aliasing. See the `zNear()` and `zFar()` documentations.

  Default value is square root of 3.0 (so that a cube of size `sceneRadius()` is not clipped).

  However, since the `sceneRadius()` is used for other purposes (see showEntireScene(), flySpeed(), ...) and you may want to change this value to define more precisely the location of the clipping planes. See also `zNearCoefficient()`.

### setZClippingCoefficient

    public void setZClippingCoefficient(float coef)

  Sets the `zClippingCoefficient()` value.

### pixelPSRatio

    public float pixelPSRatio(processing.core.PVector position)

  Returns the ratio between pixel and processing scene units at `position`.

  A line of `n * pixelPSRatio()` processing scene units, located at `position` in the world coordinates system, will be projected with a length of `n` pixels on screen.

  Use this method to scale objects so that they have a constant pixel size on screen. The following code will draw a 20 pixel line, starting at `sceneCenter()` and always directed along the screen vertical direction:

  `beginShape(LINES);`
  `vertex(sceneCenter().x, sceneCenter().y, sceneCenter().z);`
  `PVector v = PVector.add(sceneCenter(), PVector.mult(upVector(), 20 * pixelPSRatio(sceneCenter())));`
  `vertex(v.x, v.y, v.z);`
  `endShape();`

### sceneRadius

    public float sceneRadius()

  Returns the radius of the scene observed by the Camera.

  You need to provide such an approximation of the scene dimensions so that the Camera can adapt its `zNear()` and `zFar()` values. See the `sceneCenter()` documentation.

  Note that PScene.sceneRadius() (resp. PScene.setSceneRadius()) simply call this method on its associated PSCamera.

  See Also:
    `setSceneBoundingBox(PVector, PVector)`

### setSceneRadius

    public void setSceneRadius(float radius)

  Sets the `sceneRadius()` value. Negative values are ignored.

  Attention: This methods also sets `focusDistance()` to `sceneRadius() / tan(fieldOfView()/2)` and `flySpeed()` to 1% of `sceneRadius()`.

### sceneCenter

    public processing.core.PVector sceneCenter()

  Returns the position of the scene center, defined in the world coordinate system.

  The scene observed by the PSCamera should be roughly centered on this position, and included in a `sceneRadius()` sphere. This approximate description of the scene permits a `zNear()` and `zFar()` clipping planes definition, and allows convenient positioning methods such as `showEntireScene()`.

  Note that `PScene.sceneCenter()` (resp. proscene.PScene`setSceneCenter(PVector)`) simply call this method (resp. `setSceneCenter(PVector)`) on its associated `PScene.camera()`. Default value is (0,0,0) (world origin). Use `setSceneCenter(PVector)` to change it.

  See Also:
    `setSceneBoundingBox(PVector, PVector)`

### setSceneCenter

    public void setSceneCenter(processing.core.PVector center)

  Sets the `sceneCenter()`.

  Attention: This method also sets the `revolveAroundPoint()` to `sceneCenter()`.

### distanceToSceneCenter

    public float distanceToSceneCenter()

  Returns the distance from the Camera center to `sceneCenter()`, projected along the Camera Z axis.

  Used by `zNear()` and `zFar()` to optimize the Z range.

### setSceneBoundingBox

    public void setSceneBoundingBox(processing.core.PVector min,
                                    processing.core.PVector max)

  Similar to `setSceneRadius(float)` and `setSceneCenter(PVector)`, but the scene limits are defined by a (world axis aligned) bounding box.

### revolveAroundPoint

    public final processing.core.PVector revolveAroundPoint()

  The point the PSCamera revolves around its `PSInteractiveCameraFrame.revolveAroundPoint()`.

  Default value is the `sceneCenter()`.

  Attention: `setSceneCenter(PVector)` changes this value.

### setRevolveAroundPoint

    public void setRevolveAroundPoint(processing.core.PVector rap)

  Changes the `revolveAroundPoint()` to `rap` (defined in the world coordinate system).

### frame

    public PSInteractiveCameraFrame frame()

  Returns the PSInteractiveCameraFrame attached to the PSCamera.

  This PSInteractiveCameraFrame defines its `position()` and `orientation()` and can translate mouse events into PSCamera displacement. Set using `setFrame(PSInteractiveCameraFrame)`.

### setFrame

    public final void setFrame(PSInteractiveCameraFrame icf)

  Sets the PSCamera `frame()`.

  If you want to move the PSCamera, use `setPosition(PVector)` and `setOrientation(PSQuaternion)` or one of the PSCamera positioning methods (`lookAt(PVector)`, `fitSphere(PVector, float)`, `showEntireScene()`...) instead.

  This method is actually mainly useful if you derive the PSInteractiveCameraFrame class and want to use an instance of your new class to move the PSCamera.

  A `null` `icf` reference will silently be ignored.

### getProjectionMatrix

    public processing.core.PMatrix3D getProjectionMatrix()

  Convenience function that simply returns `return return getProjectionMatrix(new PMatrix3D())`

  See Also:
    `getProjectionMatrix(PMatrix3D)`

### getProjectionMatrix

    public processing.core.PMatrix3D getProjectionMatrix(processing.core.PMatrix3D m)

  Fills `m` with the PSCamera projection matrix values and returns it. If `m` is `null` a new PMatrix3D will be created.

  Calls `computeProjectionMatrix()` to define the PSCamera projection matrix.

  See Also:
    `getModelViewMatrix()`

### computeProjectionMatrix

    public void computeProjectionMatrix()

  Computes the projection matrix associated with the PSCamera.

  If `type()` is PERSPECTIVE, defines a GL_PROJECTION matrix similar to what would `perspective()` do using the `fieldOfView()`, window `aspectRatio()`, `zNear()` and `zFar()` parameters.

  If `type()` is ORTHOGRAPHIC, the projection matrix is as what `ortho()` would do. Frustum's width and height are set using `getOrthoWidthHeight()`.

  Both types use `zNear()` and `zFar()` to place clipping planes. These values are determined from sceneRadius() and sceneCenter() so that they best fit the scene size.

  Use `getProjectionMatrix()` to retrieve this matrix.

  Note: You must call this method if your PSCamera is not associated with a PScene and is used for offscreen computations (using `projectedCoordinatesOf()` for instance).

  See Also:
    `setProjectionMatrix(PMatrix3D)`

### setProjectionMatrix

    public void setProjectionMatrix(processing.core.PMatrix3D proj)

  Sets the projection matrix associated with the PSCamera directly from a PCamera.

  See Also:
    `computeProjectionMatrix()`

### getModelViewMatrix

    public processing.core.PMatrix3D getModelViewMatrix()

  Convenience function that simply returns `return getModelViewMatrix(new PMatrix3D())`

### getModelViewMatrix

    public processing.core.PMatrix3D getModelViewMatrix(processing.core.PMatrix3D m)

  Fills `m` with the Camera modelView matrix values and returns it. If `m` is `null` a new PMatrix3D will be created.

  First calls `computeModelViewMatrix()` to define the PSCamera modelView matrix.

  See Also:
    `getProjectionMatrix(PMatrix3D)`

### computeModelViewMatrix

    public void computeModelViewMatrix()

  Computes the modelView matrix associated with the Camera's `position()` and `orientation()`.

  This matrix converts from the world coordinates system to the PSCamera coordinates system, so that coordinates can then be projected on screen using the projection matrix (see `computeProjectionMatrix()`).

  Use `getModelViewMatrix()` to retrieve this matrix.

  Note: You must call this method if your PSCamera is not associated with a PScene and is used for offscreen computations (using `projectedCoordinatesOf()` for instance).

### setModelViewMatrix

    public void setModelViewMatrix(processing.core.PMatrix3D modelview)

  Sets the modelview matrix associated with the PSCamera directly from a PCamera.

  See Also:
    `computeModelViewMatrix()`

### cameraCoordinatesOf

    public final processing.core.PVector cameraCoordinatesOf(processing.core.PVector src)

  Returns the PSCamera frame coordinates of a point `src` defined in world coordinates.

  `worldCoordinatesOf(PVector)` performs the inverse transformation.

  Note that the point coordinates are simply converted in a different coordinate system. They are not projected on screen. Use `projectedCoordinatesOf(PVector, PSFrame)` for that.

### worldCoordinatesOf

    public processing.core.PVector worldCoordinatesOf(processing.core.PVector src)

  Returns the world coordinates of the point whose position `src` is defined in the PSCamera coordinate system.

  `cameraCoordinatesOf(PVector)` performs the inverse transformation.

### convertClickToLine

    public void convertClickToLine(java.awt.Point pixelInput,
                                   processing.core.PVector orig,
                                   processing.core.PVector dir)

  Gives the coefficients of a 3D half-line passing through the PSCamera eye and pixel (x,y).

  The origin of the half line (eye position) is stored in `orig`, while `dir` contains the properly oriented and normalized direction of the half line.

  `x` and `y` are expressed in Processing format (origin in the upper left corner). Use `screenHeight()` - y to convert to processing scene units.

  This method is useful for analytical intersection in a selection method.

### projectedCoordinatesOf

    public final processing.core.PVector projectedCoordinatesOf(processing.core.PVector src)

  Convenience function that simply returns `return projectedCoordinatesOf(src, null)`

### projectedCoordinatesOf

    public final processing.core.PVector projectedCoordinatesOf(processing.core.PVector src,
                                                                PSFrame frame)

  Returns the screen projected coordinates of a point `src` defined in the `frame` coordinate system.

  When `frame` is `null`, `src` is expressed in the world coordinate system. See `projectedCoordinatesOf(PVector)`.

  The x and y coordinates of the returned PVector are expressed in pixel, (0,0) being the upper left corner of the window. The z coordinate ranges between 0.0 (near plane) and 1.0 (excluded, far plane). See the `gluProject` man page for details. Attention: This method only uses the intrinsic PSCamera parameters (see `getModelViewMatrix()`, `getProjectionMatrix()` and `getViewport()`) and is completely independent of the processing matrices. You can hence define a virtual PSCamera and use this method to compute projections out of a classical rendering context.

### flySpeed

    public float flySpeed()

  Returns the fly speed of the PSCamera.

  Simply returns `frame().flySpeed()`. See the `PSInteractiveCameraFrame.flySpeed()` documentation. This value is only meaningful when the MouseAction bindings is PScene.MOVE_FORWARD or is PScene.MOVE_BACKWARD.

  Set to 0.5% of the `sceneRadius()` by `setSceneRadius(float)`.

  See Also:
    `setFlySpeed(float)`

### setFlySpeed

    public void setFlySpeed(float speed)

  Sets the PSCamera `flySpeed()`.

  Attention: This value is modified by `setSceneRadius(float)`.

### lookAt

    public void lookAt(processing.core.PVector target)

  Sets the PSCamera `orientation()`, so that it looks at point `target` (defined in the world coordinate system).

  The Camera `position()` is not modified. Simply `setViewDirection(PVector)`.

  See Also:
    `at()`, `setUpVector(PVector)`, `setOrientation(PSQuaternion)`, `showEntireScene()`, `fitSphere(PVector, float)`, `fitBoundingBox(PVector, PVector)`

### at

    public processing.core.PVector at()

  Returns a point defined in the world coordinate system where the camera is pointing at (just in front of `viewDirection()`). Useful for setting the Processing camera() which uses a similar approach of that found in gluLookAt.

  See Also:
    `lookAt(PVector)`

### fitSphere

    public void fitSphere(processing.core.PVector center,
                          float radius)

  Moves the PSCamera so that the sphere defined by `center`, `radius`) is visible and fits the window.

  The PSCamera is simply translated along its `viewDirection()` so that the sphere fits the screen. Its `orientation()` and its `fieldOfView()` are unchanged.

  You should therefore orientate the PSCamera before you call this method.

  See Also:
    `lookAt(PVector)`, `setOrientation(PSQuaternion)`, `setUpVector(PVector, boolean)`

### fitBoundingBox

    public void fitBoundingBox(processing.core.PVector min,
                               processing.core.PVector max)

  Moves the PSCamera so that the (world axis aligned) bounding box (`min`, `max`) is entirely visible, using `fitSphere(PVector, float)`.

### fitScreenRegion

    public void fitScreenRegion(java.awt.Rectangle rectangle)

  Moves the PSCamera so that the rectangular screen region defined by `rectangle` (pixel units, with origin in the upper left corner) fits the screen.

  The PSCamera is translated (its orientation() is unchanged) so that `rectangle` is entirely visible. Since the pixel coordinates only define a frustum in 3D, it's the intersection of this frustum with a plane (orthogonal to the viewDirection() and passing through the sceneCenter()) that is used to define the 3D rectangle that is eventually fitted.

### showEntireScene

    public void showEntireScene()

  Moves the PSCamera so that the entire scene is visible.

  Simply calls `fitSphere(PVector, float)` on a sphere defined by `sceneCenter()` and `sceneRadius()`.

  You will typically use this method in `PScene.init()` after you defined a new `sceneRadius()`.

### centerScene

    public void centerScene()

  Moves the PSCamera so that its `sceneCenter()` is projected on the center of the window. The `orientation()` and `fieldOfView()` are unchanged.

  Simply projects the current position on a line passing through `sceneCenter()`.

  See Also:
    `showEntireScene()`

### IODistance

    public float IODistance()

  Returns the user's inter-ocular distance (in meters). Default value is 0.062m, which fits most people.

  See Also:
    `setIODistance(float)`

### setIODistance

    public void setIODistance(float distance)

  Sets the `IODistance()`.

### physicalDistanceToScreen

    public float physicalDistanceToScreen()

  Returns the physical distance between the user's eyes and the screen (in meters).

  Default value is 0.5m.

  Value is set using `setPhysicalDistanceToScreen(float)`.

  physicalDistanceToScreen() and `focusDistance()` represent the same distance. The first one is expressed in physical real world units, while the latter is expressed in processing virtual world units. Use their ratio to convert distances between these worlds.

### setPhysicalDistanceToScreen

    public void setPhysicalDistanceToScreen(float distance)

  Sets the `physicalDistanceToScreen()`.

### physicalScreenWidth

    public float physicalScreenWidth()

  Returns the physical screen width, in meters. Default value is 0.4m (average monitor).

  Used for stereo display only. Set using `setPhysicalScreenWidth(float)`.

  See `physicalDistanceToScreen()` for reality center automatic configuration.

### setPhysicalScreenWidth

    public void setPhysicalScreenWidth(float width)

  Sets the physical screen (monitor or projected wall) width (in meters).

### focusDistance

    public float focusDistance()

  Returns the focus distance used by stereo display, expressed in processing units.

  This is the distance in the virtual world between the Camera and the plane where the horizontal stereo parallax is null (the stereo left and right images are superimposed).

  This distance is the virtual world equivalent of the real-world `physicalDistanceToScreen()`.

  attention: This value is modified by PScene.setSceneRadius(), setSceneRadius() and `setFieldOfView(float)`. When one of these values is modified, `focusDistance()` is set to `sceneRadius()` / tan(`fieldOfView()`/2), which provides good results.

### setFocusDistance

    public void setFocusDistance(float distance)

  Sets the focusDistance(), in processing scene units.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

processing library glgraphics by Andres Colubri. (c) 2008