Package org.jzy3d.plot3d.rendering.view
Class Camera
java.lang.Object
org.jzy3d.plot3d.rendering.view.AbstractViewportManager
org.jzy3d.plot3d.rendering.view.Camera
The
Schema source
All camera settings are in cartesian coordinates.
Camera
allows projecting a 3d scene to a 2d screen based on an orthogonal or
perspective projection.
The 3d world part displayed on the 2d screen is defined by the following parameters which are
illustrated on the image below
target
indicates the position of the point that the camera is currently centering on.eye
indicates the position of the lens of the camera.up
indicates the direction of the top of the camera.setRenderingSphereRadius(float)
allows defining the volume to capture with the camera. Alternatively, a 2D view will usesetRenderingSquare(BoundingBox2d)
to define the volume to capture with the camera. They are used to define the width of the field of view.near
defines the distance from which a 3d item is visible by camera.far
defines the distance up to which a 3d item is visible by camera.
Schema source
All camera settings are in cartesian coordinates.
- Author:
- Martin Pernollet
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The configuration used to call glOrtho -
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
Defines if camera distance is real, or only squared (squared distance avoid computing Math.sqrt() and is thus faster).static final Coord3d
The polar default view point, i.e.protected Coord3d
The camera viewpointprotected float
The distance between the camera eye and the far clipping plane.protected float
The distance between the camera eye and the near clipping plane.protected Camera.Ortho
The configuration used to make orthogonal rendering.protected boolean
protected ProjectionMode
Indicates if we are processing visible volume for 3D or 2D charts. 3D chart will lead to processing asetRenderingSphereRadius(float)
, while 2D chart will lead to processing ainvalid @link
#setRenderingSquare(float, float, float, float, float, float)
protected float
The rendering radius, used to automatically define with/height of scene and distance of clipping planes.protected BoundingBox2d
protected Coord3d
The scale used to display elementsprotected Coord3d
The camera targetprotected Coord3d
The camera up vectorprotected boolean
Defines if camera distance is real, or only squared (squared distance avoid computing Math.sqrt() and is thus faster).Fields inherited from class org.jzy3d.plot3d.rendering.view.AbstractViewportManager
applyWindowsHiDPIWorkaround, lastViewPort, mode, screenBottom, screenGridDisplayed, screenHeight, screenLeft, screenSquaredDim, screenWidth, screenXOffset, screenYOffset
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected double
computeFieldOfView
(double size, double distance) Compute the field of View, in order to occupy the entire screen in PERSPECTIVE mode.void
void
doShoot
(IPainter painter, CameraMode projection) Apply camera position and orientation and performs projection of the visible volume either in perspective or orthogonal mode.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.double
getDistance
(Drawable drawable) Return the distance between the camera eye and the given drawable's barycenter.double
getDistance
(Drawable drawable, Coord3d viewScale) Apply scaling before computing distance between the camera eye and the given drawable's barycenter.getEye()
Returns the eye's position.float
getFar()
Return the position of the "far" clipping planefloat
getNear()
Return the position of the "near" clipping planegetOrtho()
Return last values used to make orthogonal scene rendering.Return the projection mode (for 3D or 2D charts), which was defined while callingsetRenderingSphereRadius(float)
for 3D charts, orsetRenderingSquare(BoundingBox2d, float, float)
for 2D charts.float
Return the radius of the sphere that will be contained into the rendered 3D view.Return the rendering (X,Y) square that will be contained into the rendered 2D view.getScale()
Returns the scale used by this camera to display elements.Returns the target's position that was set at the last call to lookAt().getUp()
Returns the top of the camera.void
initWithTarget
(Coord3d initialTarget) 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
modelToScreen
(IPainter painter, Coord3d point) Transform a 3d point coordinate into its screen position.void
projectionOrtho
(IPainter painter, ViewportConfiguration viewport) Perform a orthogonal projection.protected void
protected void
projectionOrtho3D
(ViewportConfiguration viewport) void
projectionPerspective
(IPainter painter, ViewportConfiguration viewport) Perform a perspective projection by processing the field of view based on therenderingSphereRadius
,target
andeye
.screenToModel
(IPainter painter, Coord3d screen) Transform a 2d screen coordinate into a 3d coordinate.void
Set the position of this camera's lens.protected void
setNearFarClippingPlanesWithRadius
(float radius) void
setPosition
(Coord3d eye, Coord3d target) Set the camera's eye- and target-location.void
setPosition
(Coord3d eye, Coord3d target, Coord3d up, Coord3d scale) Atomically sets this camera's eye- and target-position, its up-direction and the scale with which data are displayed.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 visible by the camera (i.e. contained into the rendered view), for a 3D chart.void
setRenderingSquare
(BoundingBox2d renderingSquare) Set the boundaries of the model space that should be visible by the camera, for a 2D chart having only X and Y boundaries.void
setRenderingSquare
(BoundingBox2d renderingSquare, float zNear, float zFar) Set the boundaries of the model space that should be visible by the camera, for a 2D chart having only X and Y boundaries.void
Set the position of the target at which this camera is centering.void
Set the up-direction of this 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
shoot
(IPainter painter, CameraMode projection) Sets the projection and the mapping of the 3d model to 2d screen.void
shoot
(IPainter painter, CameraMode projection, boolean doPushMatrixBeforeShooting) void
boolean
Return true if the given (not scaled) point is on the left of the plane build by the eye->target and up-direction vector, else false.toString()
Print out in console information concerning the camera.protected String
Methods inherited from class org.jzy3d.plot3d.rendering.view.AbstractViewportManager
apply_WindowsHiDPI_Workaround, apply_WindowsHiDPI_Workaround, applyViewport, applyViewportRectangle, applyViewportSquared, getLastViewPort, getRectangle, getScreenBottom, getScreenHeight, getScreenLeft, getScreenWidth, getScreenXOffset, getScreenYOffset, getSliceWidth, getViewPort, getViewportMode, getWindowsHiDPIScale_Workaround, isApplyWindowsHiDPIWorkaround, isScreenGridDisplayed, renderSubScreenGrid, setApplyWindowsHiDPIWorkaround, setScreenGridDisplayed, setScreenXOffset, setScreenYOffset, setViewPort, setViewPort, setViewPort, setViewportMode
-
Field Details
-
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_MODEDefines 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:
-
useSquaredDistance
protected boolean useSquaredDistanceDefines if camera distance is real, or only squared (squared distance avoid computing Math.sqrt() and is thus faster). -
eye
The camera viewpoint -
target
The camera target -
up
The camera up vector -
scale
The scale used to display elements -
projectionMode
Indicates if we are processing visible volume for 3D or 2D charts. 3D chart will lead to processing asetRenderingSphereRadius(float)
, while 2D chart will lead to processing ainvalid @link
#setRenderingSquare(float, float, float, float, float, float)
-
renderingSphereRadius
protected float renderingSphereRadiusThe rendering radius, used to automatically define with/height of scene and distance of clipping planes. -
near
protected float nearThe distance between the camera eye and the near clipping plane. -
far
protected float farThe distance between the camera eye and the far clipping plane. -
renderingSquare
-
ortho
The configuration used to make orthogonal rendering.- See Also:
-
-
invalid @see
glOrtho
-
-
perspectiveProjectionUseFrustrum
protected boolean perspectiveProjectionUseFrustrum
-
-
Constructor Details
-
Camera
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. -
Camera
public Camera()
-
-
Method Details
-
initWithTarget
-
setEye
Set the position of this camera's lens.All other parameters of this camera remain unchanged. To change multiple parameters atomically use
setPosition(Coord3d, Coord3d, Coord3d, Coord3d)
.- Parameters:
eye
- the new scaled position of this camera's lens.
-
getEye
Returns the eye's position. -
setTarget
Set the position of the target at which this camera is centering.All other parameters of this camera remain unchanged. To change multiple parameters atomically use
setPosition(Coord3d, Coord3d, Coord3d, Coord3d)
.- Parameters:
target
- the new scaled position of this camera's target
-
getTarget
Returns the target's position that was set at the last call to lookAt(). -
setUp
Set the up-direction of this camera.All other parameters of this camera remain unchanged. To change multiple parameters atomically use
setPosition(Coord3d, Coord3d, Coord3d, Coord3d)
.- Parameters:
up
- the new up-direction of this camera
-
getUp
Returns the top of the camera. -
getScale
Returns the scale used by this camera to display elements. -
setPosition
Set the camera's eye- and target-location.All other parameters of this camera remain unchanged. To change more parameters atomically use
setPosition(Coord3d, Coord3d, Coord3d, Coord3d)
.- Parameters:
eye
-target
-
-
setPosition
Atomically sets this camera's eye- and target-position, its up-direction and the scale with which data are displayed.- Parameters:
eye
- the scaled location of the camera eye (previously multiplied with this camera's scale)target
- the scaled location at which this camera will look (previously multiplied with this camera's scale)up
- the direction of the up-side of this camera (not scaled)scale
- the scale used by this camera to display elements
-
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. -
getProjectionMode
Return the projection mode (for 3D or 2D charts), which was defined while callingsetRenderingSphereRadius(float)
for 3D charts, orsetRenderingSquare(BoundingBox2d, float, float)
for 2D charts. -
setRenderingSphereRadius
public void setRenderingSphereRadius(float radius) Set the radius of the sphere that will be visible by the camera (i.e. contained into the rendered view), for a 3D chart. The "far" and "near" clipping planes are modified according to the eye-target distance. After calling this method,getProjectionMode()
returnsinvalid @link
ProjectionMode.Projection3D
-
setRenderingSquare
Set the boundaries of the model space that should be visible by the camera, for a 2D chart having only X and Y boundaries. The values describe an area relative to the camera settings (eye, target, up), the actual visible region of space is then made of the rendering square centered at the eye/target axis. -
setRenderingSquare
Set the boundaries of the model space that should be visible by the camera, for a 2D chart having only X and Y boundaries. The values describe an area relative to the camera settings (eye, target, up), the actual visible region of space is then made of the rendering square centered at the eye/target axis. -
setNearFarClippingPlanesWithRadius
protected void setNearFarClippingPlanesWithRadius(float radius) -
getRenderingSphereRadius
public float getRenderingSphereRadius()Return the radius of the sphere that will be contained into the rendered 3D view. -
getRenderingSquare
Return the rendering (X,Y) square that will be contained into the rendered 2D view. -
setRenderingDepth
public void setRenderingDepth(float near, float far) Manually set the rendering depth (near and far clipping planes). Note thatinvalid @link
Camera.setRenderingSphereRadius
-
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
Return true if the given (not scaled) point is on the left of the plane build by the eye->target and up-direction vector, else false.- Parameters:
point
- not scaled point (its values correspond to a point in the scene)- Returns:
- true if the given point is 'on the left side' of this camera
-
getOrtho
Return last values used to make orthogonal scene rendering. Do not edit. -
screenToModel
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 theCamera
. A null coordinate can be returned if the projection could not be performed for some reasons. This may occur if projection or modelview matrices are not invertible or if these matrices where unavailable (hence resulting to zero matrices) while invoking this method. Zero matrices can be avoided by ensuring the GL context is current usingIPainter.acquireGL()
-
modelToScreen
Transform a 3d point coordinate into its screen position. This method requires the GL context to be current. If not called inside a rendering loop, that method may not apply correctly and output {0,0,0}. In that case and if the chart is based on JOGL (native), one may force the context to be current usingNativeDesktopPainter p = (NativeDesktopPainter)chart.getPainter(); p.getCurrentContext(chart.getCanvas()).makeCurrent(); // make context current Coord3d screen2dCoord = camera.modelToScreen(chart.getPainter(), world3dCoord); p.getCurrentContext(chart.getCanvas()).release(); // release context to let other use it
-
show
-
shoot
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:
painter
- TODOprojection
- the projection mode.- Throws:
a
- Runtime Exception if the projection mode is neither Camera.PERSPECTIVE nor Camera.ORTHOGONAL.
-
shoot
-
doShoot
Apply camera position and orientation and performs projection of the visible volume either in perspective or orthogonal mode. The orthogonal mode support 2D/3D. -
projectionPerspective
Perform a perspective projection by processing the field of view based on therenderingSphereRadius
,target
andeye
.- Parameters:
painter
-viewport
-
-
doLookAt
-
projectionOrtho
Perform a orthogonal projection. The viewable part of the 3d scene is defined by parameters {left, right, bottom, top, near, far} which are processed according to theViewportMode
and the values of the camera settings (renderingSphereRadius
,target
andeye
,near
andfar
clipping planes).
- Parameters:
painter
-viewport
-
-
projectionOrtho2D
protected void projectionOrtho2D() -
projectionOrtho3D
-
computeFieldOfView
protected double computeFieldOfView(double size, double distance) Compute the field of View, in order to occupy the entire screen in PERSPECTIVE mode. -
getDistance
Return the distance between the camera eye and the given drawable's barycenter. -
getDistance
Apply scaling before computing distance between the camera eye and the given drawable's barycenter. -
getDistance
Return the distance between the camera eye and the given coordinate. -
getDistance
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:- Squared distance (faster to compute since no Math.sqrt(...) at the end)
- Real distance
-
toString
Print out in console information concerning the camera. -
toString
-