Package org.jzy3d.plot3d.rendering.view
Class Camera
- java.lang.Object
-
- org.jzy3d.plot3d.rendering.view.AbstractViewportManager
-
- org.jzy3d.plot3d.rendering.view.Camera
-
public class Camera extends AbstractViewportManager
TheCamera
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 belowtarget
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
Nested Classes Modifier and Type Class Description static class
Camera.Ortho
The configuration used to call glOrtho
-
Field Summary
Fields Modifier and Type Field Description 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
The camera viewpointprotected float
far
The distance between the camera eye and the far clipping plane.protected float
near
The distance between the camera eye and the near clipping plane.protected Camera.Ortho
ortho
The configuration used to make orthogonal rendering.protected ProjectionMode
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 a#setRenderingSquare(float, float, float, float, float, float)
protected float
renderingSphereRadius
The rendering radius, used to automatically define with/height of scene and distance of clipping planes.protected BoundingBox2d
renderingSquare
protected Coord3d
scale
The scale used to display elementsprotected Coord3d
target
The camera targetprotected Coord3d
up
The camera up vectorprotected boolean
useSquaredDistance
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
apply_WindowsHiDPI_Workaround, lastViewPort, mode, ratioHeight, ratioWidth, screenBottom, screenGridDisplayed, screenHeight, screenLeft, screenSquaredDim, screenWidth, screenXOffset, screenYOffset
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
computeFieldOfView(double size, double distance)
Compute the field of View, in order to occupy the entire screen in PERSPECTIVE mode.void
doLookAt(IPainter painter)
void
doShoot(IPainter painter, CameraMode projection)
Apply camera position and orientation and performs projection of the visible volume either in perspective or orthogonal mode.protected void
failedProjection(String message)
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.Coord3d
getEye()
Returns the eye's position.float
getFar()
Return the position of the "far" clipping planefloat
getNear()
Return the position of the "near" clipping planeCamera.Ortho
getOrtho()
Return last values used to make orthogonal scene rendering.ProjectionMode
getProjectionMode()
Return the projection mode (for 3D or 2D charts), which was defined while callingsetRenderingSphereRadius(float)
for 3D charts, or#setRenderingSquare(BoundingBox2d, float, float)
for 2D charts.float
getRenderingSphereRadius()
Return the radius of the sphere that will be contained into the rendered 3D view.BoundingBox2d
getRenderingSquare()
Return the rendering (X,Y) square that will be contained into the rendered 2D view.Coord3d
getScale()
Returns the scale used by this camera to display elements.Coord3d
getTarget()
Returns the target's position that was set at the last call to lookAt().Coord3d
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
isUseSquaredDistance()
ArrayList<ArrayList<Coord3d>>
modelToScreen(IPainter painter, ArrayList<ArrayList<Coord3d>> polygons)
List<Coord3d>
modelToScreen(IPainter painter, List<Coord3d> points)
Coord3d
modelToScreen(IPainter painter, Coord3d point)
Transform a 3d point coordinate into its screen position.Coord3d[]
modelToScreen(IPainter painter, Coord3d[] points)
Coord3d[][]
modelToScreen(IPainter painter, Coord3d[][] points)
PolygonArray
modelToScreen(IPainter painter, PolygonArray polygon)
PolygonArray[][]
modelToScreen(IPainter painter, PolygonArray[][] polygons)
void
projectionOrtho(IPainter painter, ViewportConfiguration viewport)
Perform a orthogonal projection.protected void
projectionOrtho2D()
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
.Coord3d
screenToModel(IPainter painter, Coord3d screen)
Transform a 2d screen coordinate into a 3d coordinate.void
setEye(Coord3d eye)
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
setTarget(Coord3d target)
Set the position of the target at which this camera is centering.void
setUp(Coord3d up)
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
show(IPainter painter, Transform transform, Coord3d scaling)
boolean
side(Coord3d point)
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.String
toString()
Print out in console information concerning the camera.protected String
toString(Coord3d eye, Coord3d target, Coord3d up)
-
Methods inherited from class org.jzy3d.plot3d.rendering.view.AbstractViewportManager
applyViewport, getLastViewPort, getRectangle, getScreenBottom, getScreenHeight, getScreenLeft, getScreenWidth, getScreenXOffset, getScreenYOffset, getSliceWidth, getViewportMode, isScreenGridDisplayed, renderSubScreenGrid, setScreenGridDisplayed, setViewPort, setViewPort, setViewPort, setViewportMode
-
-
-
-
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
-
useSquaredDistance
protected boolean useSquaredDistance
Defines if camera distance is real, or only squared (squared distance avoid computing Math.sqrt() and is thus faster).
-
eye
protected Coord3d eye
The camera viewpoint
-
target
protected Coord3d target
The camera target
-
up
protected Coord3d up
The camera up vector
-
scale
protected Coord3d scale
The scale used to display elements
-
projectionMode
protected ProjectionMode 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 a#setRenderingSquare(float, float, float, float, float, float)
-
renderingSphereRadius
protected float renderingSphereRadius
The rendering radius, used to automatically define with/height of scene and distance of clipping planes.
-
near
protected float near
The distance between the camera eye and the near clipping plane.
-
far
protected float far
The distance between the camera eye and the far clipping plane.
-
renderingSquare
protected BoundingBox2d renderingSquare
-
ortho
protected Camera.Ortho ortho
The configuration used to make orthogonal rendering.- See Also:
glOrtho
-
-
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.
-
Camera
public Camera()
-
-
Method Detail
-
initWithTarget
public void initWithTarget(Coord3d initialTarget)
-
setEye
public void setEye(Coord3d eye)
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
public Coord3d getEye()
Returns the eye's position.
-
setTarget
public void setTarget(Coord3d target)
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
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 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
public Coord3d getUp()
Returns the top of the camera.
-
getScale
public Coord3d getScale()
Returns the scale used by this camera to display elements.
-
setPosition
public void setPosition(Coord3d eye, Coord3d target)
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
public 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.- 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
public ProjectionMode getProjectionMode()
Return the projection mode (for 3D or 2D charts), which was defined while callingsetRenderingSphereRadius(float)
for 3D charts, or#setRenderingSquare(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()
returnsProjectionMode.Projection3D
.
-
setNearFarClippingPlanesWithRadius
protected void setNearFarClippingPlanesWithRadius(float radius)
-
setRenderingSquare
public 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. After calling this method,getProjectionMode()
returnsProjectionMode.Projection2D
.
-
getRenderingSphereRadius
public float getRenderingSphereRadius()
Return the radius of the sphere that will be contained into the rendered 3D view.
-
getRenderingSquare
public BoundingBox2d 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 thatCamera.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 (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
public Camera.Ortho getOrtho()
Return last values used to make orthogonal scene rendering. Do not edit.
-
screenToModel
public Coord3d screenToModel(IPainter painter, 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 theCamera
.- Throws:
a
- RuntimeException if an error occured while trying to retrieve model coordinates
-
modelToScreen
public Coord3d modelToScreen(IPainter painter, Coord3d point)
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
- Throws:
a
- RuntimeException if an error occured while trying to retrieve model coordinates AND iffailOnException
is set to true (default is false). In casefailOnException
is false, a DEBUG log is sent to the#LOGGER
.
-
modelToScreen
public ArrayList<ArrayList<Coord3d>> modelToScreen(IPainter painter, ArrayList<ArrayList<Coord3d>> polygons)
-
modelToScreen
public PolygonArray modelToScreen(IPainter painter, PolygonArray polygon)
-
modelToScreen
public PolygonArray[][] modelToScreen(IPainter painter, PolygonArray[][] polygons)
-
failedProjection
protected void failedProjection(String message)
-
shoot
public void shoot(IPainter painter, 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:
painter
- TODOprojection
- the projection mode.- Throws:
a
- Runtime Exception if the projection mode is neither Camera.PERSPECTIVE nor Camera.ORTHOGONAL.
-
shoot
public void shoot(IPainter painter, CameraMode projection, boolean doPushMatrixBeforeShooting)
-
doShoot
public void doShoot(IPainter painter, CameraMode projection)
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
public void projectionPerspective(IPainter painter, ViewportConfiguration viewport)
Perform a perspective projection by processing the field of view based on therenderingSphereRadius
,target
andeye
.- Parameters:
painter
-viewport
-
-
doLookAt
public void doLookAt(IPainter painter)
-
projectionOrtho
public void projectionOrtho(IPainter painter, ViewportConfiguration viewport)
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
protected void projectionOrtho3D(ViewportConfiguration viewport)
-
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(Drawable drawable)
Return the distance between the camera eye and the given drawable's barycenter.
-
getDistance
public double getDistance(Drawable 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:- Squared distance (faster to compute since no Math.sqrt(...) at the end)
- Real distance
-
toString
public String toString()
Print out in console information concerning the camera.
-
-