public class Window extends Eye implements Copyable
Eye
abstract class.
Attention: the Eye.frame()
Frame.magnitude()
is used to scale the view. The Window
magnitude is thus generally different from that of the scene. Use
Eye.eyeCoordinatesOf(Vec)
and Eye.worldCoordinatesOf(Vec)
(or any of the
powerful Frame transformations (
Frame.coordinatesOf(Vec)
,
Frame.transformOf(Vec)
, ...)) to convert to and from
the Eye Eye.frame()
coordinate system.
Eye.Visibility
anchorFlag, lastNonFrameUpdate, pupFlag, pupVec
Constructor and Description |
---|
Window(AbstractScene scn) |
Modifier and Type | Method and Description |
---|---|
Vec |
at()
2D Windows return the postion.
|
Eye.Visibility |
ballVisibility(Vec center,
float radius)
Returns
Eye.Visibility.VISIBLE ,
Eye.Visibility.INVISIBLE , or
Eye.Visibility.SEMIVISIBLE , depending whether the
sphere (of radius radius and center center ) is visible, invisible, or
semi-visible, respectively. |
Eye.Visibility |
boxVisibility(Vec p1,
Vec p2)
Returns
Eye.Visibility.VISIBLE ,
Eye.Visibility.INVISIBLE , or
Eye.Visibility.SEMIVISIBLE , depending whether the
axis aligned box (defined by corners p1 and p2 ) is visible,
invisible, or semi-visible, respectively. |
float[][] |
computeBoundaryEquations()
Convenience function that in 2D simply returns
computeFrustumPlanesCoefficients(new float [4][3]) and in 3D
computeFrustumPlanesCoefficients(new float [6][4]) . |
float[][] |
computeBoundaryEquations(float[][] coef)
Fills
coef with the 6 plane equations of the camera frustum and returns it. |
void |
computeProjection()
Computes the projection matrix associated with the Eye.
|
void |
computeView()
Computes the View matrix associated with the Eye's
Eye.position() and
Eye.orientation() . |
float |
distanceToAnchor()
Returns the Eye
Eye.position() to Eye.anchor() distance in Scene units. |
float |
distanceToBoundary(int index,
Vec pos)
Returns the signed distance between point
pos and plane index in
Scene units. |
float |
distanceToSceneCenter()
Returns the Eye
Eye.position() to Eye.sceneCenter() distance in Scene
units. |
void |
fitBall(Vec center,
float radius)
Moves the Eye so that the ball defined by
center and radius is
visible and fits the window. |
void |
fitBoundingBox(Vec min,
Vec max)
Moves the Eye so that the (world axis aligned) bounding box (
min ,
max ) is entirely visible, using Eye.fitBall(Vec, float) . |
void |
fitScreenRegion(Rect rectangle)
Moves the Eye so that the rectangular screen region defined by
rectangle
(pixel units, with origin in the upper left corner) fits the screen. |
void |
fromView(Mat mv,
boolean recompute)
Sets the Eye
Eye.position() and Eye.orientation() from an OpenGL-like View
matrix. |
Window |
get()
Returns a deep copy of the object.
|
void |
interpolateToZoomOnPixel(Point pixel)
Makes the Eye smoothly zoom on the
Camera.pointUnderPixel(Point) pixel and
returns the world coordinates of the
Camera.pointUnderPixel(Point) . |
boolean |
isPointVisible(float x,
float y)
Same as
return isPointVisible(new Vec(x, y)) . |
boolean |
isPointVisible(Vec point)
Returns
true if point is visible (i.e, lies within the Eye boundary)
and false otherwise. |
void |
lookAt(float x,
float y)
Same as
lookAt(new Vec(x,y)) . |
void |
lookAt(Vec target)
2D Windows simply call
frame().setPosition(target.x(), target.y()) . |
float |
sceneToPixelRatio(Vec position)
Returns the ratio of scene (units) to pixel at
position . |
void |
setAnchor(float x,
float y)
Same as
setAnchor(new Vec(x,y)) . |
boolean |
setAnchorFromPixel(Point pixel)
The
Eye.anchor() is set to the point located under pixel on screen. |
void |
setOrientation(float angle) |
void |
setOrientation(Rotation q)
Sets the Eye
Eye.orientation() , defined in the world coordinate system. |
void |
setPosition(float x,
float y)
Same as
setPosition(new Vec(x,y)) . |
void |
setSceneBoundingBox(Vec min,
Vec max)
Similar to
Eye.setSceneRadius(float) and Eye.setSceneCenter(Vec) , but the
scene limits are defined by a (world axis aligned) bounding box. |
boolean |
setSceneCenterFromPixel(Point pixel)
The
Eye.sceneCenter() is set to the point located under pixel on screen. |
void |
setUpVector(float x,
float y)
Same as
setUpVector(new Vec(x,y)) . |
void |
setUpVector(float x,
float y,
boolean noMove)
Same as
setUpVector(new Vec(x,y), boolean noMove) . |
void |
setUpVector(Vec up,
boolean noMove)
Rotates the Eye so that its
Eye.upVector() becomes up (defined in the
world coordinate system). |
addKeyFrameToPath, anchor, anyInterpolationStarted, areBoundaryEquationsEnabled, aspectRatio, centerScene, deletePath, enableBoundaryEquations, eyeCoordinatesOf, flip, flySpeed, frame, fromView, getBoundaryEquations, getBoundaryWidthHeight, getBoundaryWidthHeight, getOrthoWidthHeight, getOrthoWidthHeight, getProjection, getProjection, getProjection, getProjection, getView, getView, getView, getView, getViewport, getViewport, interpolateTo, interpolateTo, interpolateToFitScene, interpolateToZoomOnPixel, interpolateToZoomOnRegion, keyFrameInterpolator, keyFrameInterpolatorArray, keyFrameInterpolatorList, keyFrameInterpolatorMap, lastNonFrameUpdate, lastUpdate, orientation, pixelToSceneRatio, playPath, position, project, project, projectedCoordinatesOf, projectedCoordinatesOf, projectedCoordinatesOf, projectedCoordinatesOf, rescalingOrthoFactor, resetPath, rightVector, rotationSensitivity, scalingSensitivity, scene, sceneCenter, sceneRadius, screenHeight, screenWidth, setAnchor, setAnchorFromPixel, setAspectRatio, setFlySpeed, setFrame, setKeyFrameInterpolator, setPosition, setProjection, setProjection, setProjection, setRotationSensitivity, setScalingSensitivity, setSceneCenter, setSceneCenterFromPixel, setSceneRadius, setScreenWidthAndHeight, setSpinningSensitivity, setTranslationSensitivity, setUpVector, showEntireScene, spinningSensitivity, stopInterpolations, translationSensitivity, unproject, unproject, unprojectedCoordinatesOf, unprojectedCoordinatesOf, unprojectedCoordinatesOf, unprojectedCoordinatesOf, updateBoundaryEquations, upVector, viewDirection, worldCoordinatesOf
public Window(AbstractScene scn)
public Window get()
Copyable
Typical implementation should simple look like: return new Object(this)
.
public void computeView()
Eye
Eye.position()
and
Eye.orientation()
.
This matrix converts from the world coordinates system to the Eye coordinates system,
so that coordinates can then be projected on screen using the projection matrix (see
Eye.computeProjection()
).
Use Eye.getView()
to retrieve this matrix.
Note: You must call this method if your Eye is not associated with a Scene and
is used for offscreen computations (using projectedCoordinatesOf()
for
instance).
computeView
in class Eye
public void computeProjection()
Eye
If Eye is a 3D PERSPECTIVE Camera, defines a projection matrix using the
Camera.fieldOfView()
, Eye.aspectRatio()
,
Camera.zNear()
and
Camera.zFar()
parameters. If Eye is a 3D ORTHOGRAPHIC
Camera, the frustum's width and height are set using
Eye.getBoundaryWidthHeight()
. Both types use
Camera.zNear()
and
Camera.zFar()
to place clipping planes. These values
are determined from sceneRadius() and sceneCenter() so that they best fit the scene
size.
Use Eye.getProjection()
to retrieve this matrix.
Note: You must call this method if your Eye is not associated with a Scene and
is used for offscreen computations (using projectedCoordinatesOf()
for
instance).
computeProjection
in class Eye
Eye.setProjection(Mat)
public void fromView(Mat mv, boolean recompute)
Eye
Eye.position()
and Eye.orientation()
from an OpenGL-like View
matrix.
After this method has been called, Eye.getView()
returns a matrix equivalent to
mv
. Only the Eye.position()
and Eye.orientation()
of the Eye are
modified.
public void setUpVector(Vec up, boolean noMove)
Eye
Eye.upVector()
becomes up
(defined in the
world coordinate system).
The Eye is rotated around an axis orthogonal to up
and to the current
Eye.upVector()
direction.
Use this method in order to define the Eye horizontal plane.
When noMove
is set to false
, the orientation modification is
compensated by a translation, so that the Eye.anchor()
stays projected at the
same position on screen. This is especially useful when the Eye is an observer of the
scene (default action binding).
When noMove
is true, the Eye Eye.position()
is left unchanged, which is
an intuitive behavior when the Eye is in first person mode.
setUpVector
in class Eye
Eye.lookAt(Vec)
,
Eye.setOrientation(Rotation)
public void setUpVector(float x, float y)
setUpVector(new Vec(x,y))
.Eye.setUpVector(Vec)
public void setUpVector(float x, float y, boolean noMove)
setUpVector(new Vec(x,y), boolean noMove)
.setUpVector(Vec, boolean)
public void setPosition(float x, float y)
setPosition(new Vec(x,y))
.Eye.setPosition(Vec)
public boolean setSceneCenterFromPixel(Point pixel)
Eye
Eye.sceneCenter()
is set to the point located under pixel
on screen.
2D windows always returns true.
3D Cameras returns true
if a point was found under pixel
and
false
if none was found (in this case no Eye.sceneCenter()
is set).
setSceneCenterFromPixel
in class Eye
public void fitBoundingBox(Vec min, Vec max)
Eye
min
,
max
) is entirely visible, using Eye.fitBall(Vec, float)
.fitBoundingBox
in class Eye
public void fitBall(Vec center, float radius)
Eye
center
and radius
is
visible and fits the window.
In 3D the Camera is simply translated along its Eye.viewDirection()
so that the
sphere fits the screen. Its Eye.orientation()
and its
Camera.fieldOfView()
are unchanged. You should
therefore orientate the Camera before you call this method.
fitBall
in class Eye
Eye.lookAt(Vec)
,
Eye.setOrientation(Rotation)
,
Eye.setUpVector(Vec, boolean)
public void setSceneBoundingBox(Vec min, Vec max)
Eye
Eye.setSceneRadius(float)
and Eye.setSceneCenter(Vec)
, but the
scene limits are defined by a (world axis aligned) bounding box.setSceneBoundingBox
in class Eye
public void fitScreenRegion(Rect rectangle)
Eye
rectangle
(pixel units, with origin in the upper left corner) fits the screen.
in 3D the Camera is translated (its Eye.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 Eye.viewDirection()
and passing through the Eye.sceneCenter()
) that
is used to define the 3D rectangle that is eventually fitted.
fitScreenRegion
in class Eye
public void setOrientation(Rotation q)
Eye
Eye.orientation()
, defined in the world coordinate system.setOrientation
in class Eye
public void setOrientation(float angle)
public float[][] computeBoundaryEquations()
Eye
computeFrustumPlanesCoefficients(new float [4][3])
and in 3D
computeFrustumPlanesCoefficients(new float [6][4])
.
Attention: You should not call this method explicitly, unless you need the
frustum equations to be updated only occasionally (rare). Use
AbstractScene.enableBoundaryEquations()
which
automatically update the frustum equations every frame instead.
computeBoundaryEquations
in class Eye
Eye.computeBoundaryEquations(float[][])
public float[][] computeBoundaryEquations(float[][] coef)
Eye
coef
with the 6 plane equations of the camera frustum and returns it.
In 2D the four 4-component vectors of coef
respectively correspond to the
left, right, top and bottom Window boundary lines. Each vector holds a plane equation
of the form:
a*x + b*y + c = 0
where a
, b
and c
are the 3
components of each vector, in that order.
In 3D the six 4-component vectors of coef
respectively correspond to the
left, right, near, far, top and bottom Camera frustum planes. Each vector holds a
plane equation of the form:
a*x + b*y + c*z + d = 0
where a
, b
, c
and d
are the 4 components of each
vector, in that order.
This format is compatible with the gl.glClipPlane()
function. One camera
frustum plane can hence be applied in an other viewer to visualize the culling
results:
// Retrieve place equations
float [][] coef =
mainViewer.camera().getFrustumPlanesCoefficients();
// These two additional clipping planes (which must have been enabled)
// will reproduce the mainViewer's near and far clipping.
gl.glClipPlane(GL.GL_CLIP_PLANE0, coef[2]);
gl.glClipPlane(GL.GL_CLIP_PLANE1, coef[3]);
Attention: You should not call this method explicitly, unless you need the
frustum equations to be updated only occasionally (rare). Use
AbstractScene.enableBoundaryEquations()
which
automatically update the frustum equations every frame instead.
computeBoundaryEquations
in class Eye
Eye.computeBoundaryEquations()
public float distanceToBoundary(int index, Vec pos)
Eye
pos
and plane index
in
Scene units. The distance is negative if the point lies in the planes's boundary
halfspace, and positive otherwise.
index
is a value between 0
and 5
which respectively
correspond to the left, right, near, far, top and bottom Eye boundary planes.
Attention: The eye boundary plane equations should be updated before calling
this method. You may compute them explicitly (by calling
Eye.computeBoundaryEquations()
) or enable them to be automatic updated in your
Scene setup (with
AbstractScene.enableBoundaryEquations()
).
public Eye.Visibility boxVisibility(Vec p1, Vec p2)
Eye
Eye.Visibility.VISIBLE
,
Eye.Visibility.INVISIBLE
, or
Eye.Visibility.SEMIVISIBLE
, depending whether the
axis aligned box (defined by corners p1
and p2
) is visible,
invisible, or semi-visible, respectively.
Attention: The Eye boundary plane equations should be updated before calling
this method. You may compute them explicitly (by calling
Eye.computeBoundaryEquations()
) or enable them to be automatic updated in your
Scene setup (with
AbstractScene.enableBoundaryEquations()
).
public Eye.Visibility ballVisibility(Vec center, float radius)
Eye
Eye.Visibility.VISIBLE
,
Eye.Visibility.INVISIBLE
, or
Eye.Visibility.SEMIVISIBLE
, depending whether the
sphere (of radius radius
and center center
) is visible, invisible, or
semi-visible, respectively.
Attention: The Eye boundary plane equations should be updated before calling
this method. You may compute them explicitly (by calling
Eye.computeBoundaryEquations()
) or enable them to be automatic updated in your
Scene setup (with
AbstractScene.enableBoundaryEquations()
).
public boolean isPointVisible(Vec point)
Eye
true
if point
is visible (i.e, lies within the Eye boundary)
and false
otherwise.
Attention: The Eye boundary plane equations should be updated before calling
this method. You may compute them explicitly (by calling
Eye.computeBoundaryEquations()
) or enable them to be automatic updated in your
Scene setup (with
AbstractScene.enableBoundaryEquations()
).
public boolean isPointVisible(float x, float y)
return isPointVisible(new Vec(x, y))
.isPointVisible(Vec)
public float sceneToPixelRatio(Vec position)
Eye
position
.
A line of n * sceneToPixelRatio()
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 Eye.sceneCenter()
and
always directed along the screen vertical direction:
beginShape(LINES);
vertex(sceneCenter().x, sceneCenter().y, sceneCenter().z);
Vec v = Vec.add(sceneCenter(), Vec.mult(upVector(), 20 * sceneToPixelRatio(sceneCenter())));
vertex(v.x, v.y, v.z);
endShape();
sceneToPixelRatio
in class Eye
public void lookAt(Vec target)
Eye
frame().setPosition(target.x(), target.y())
. 3D
Cameras set Eye.orientation()
, so that it looks at point target
defined
in the world coordinate system (The Camera Eye.position()
is not modified.
Simply Camera.setViewDirection(Vec)
).lookAt
in class Eye
Eye.at()
,
Eye.setUpVector(Vec)
,
Eye.setOrientation(Rotation)
,
Eye.showEntireScene()
,
Eye.fitBall(Vec, float)
,
Eye.fitBoundingBox(Vec, Vec)
public void lookAt(float x, float y)
lookAt(new Vec(x,y))
.lookAt(Vec)
public void setAnchor(float x, float y)
setAnchor(new Vec(x,y))
.AbstractScene.setAnchor(Vec)
public boolean setAnchorFromPixel(Point pixel)
Eye
Eye.anchor()
is set to the point located under pixel
on screen.
2D windows always returns true.
3D Cameras returns true
if a point was found under pixel
and
false
if none was found (in this case no Eye.anchor()
is set).
setAnchorFromPixel
in class Eye
public void interpolateToZoomOnPixel(Point pixel)
Eye
Camera.pointUnderPixel(Point)
pixel
and
returns the world coordinates of the
Camera.pointUnderPixel(Point)
.
In 3D nothing happens if no
Camera.pointUnderPixel(Point)
is found. Otherwise a
KeyFrameInterpolator is created that animates the Camera on a one second path that
brings the Camera closer to the point under pixel
.
interpolateToZoomOnPixel
in class Eye
Eye.interpolateToFitScene()
public float distanceToSceneCenter()
Eye
Eye.position()
to Eye.sceneCenter()
distance in Scene
units.
3D Cameras return the projected Eye Eye.position()
to Eye.sceneCenter()
distance along the Camera Z axis and use it in
Camera.zNear()
and
Camera.zFar()
to optimize the Z range.
distanceToSceneCenter
in class Eye
public float distanceToAnchor()
Eye
Eye.position()
to Eye.anchor()
distance in Scene units.
3D Cameras return the projected Eye Eye.position()
to Eye.anchor()
distance
along the Camera Z axis and use it in Eye.getBoundaryWidthHeight(float[])
so
that when the Camera is translated forward then its frustum is narrowed, making the
object appear bigger on screen, as intuitively expected.
distanceToAnchor
in class Eye
public Vec at()
Eye
Eye.viewDirection()
). Useful for setting the Processing camera() which uses a
similar approach of that found in gluLookAt.at
in class Eye
Eye.lookAt(Vec)
Processing Library proscene by Jean Pierre Charalambos. (c) 2014-2017 National University of Colombia