Class Graph
- java.lang.Object
-
- nub.core.Graph
-
- Direct Known Subclasses:
Scene
public class Graph extends Object
A 2D or 3D scene-graph providing a (default)eye()
node, input and timing handling to a raster or ray-tracing renderer.1. Types and dimensions
The way the projection matrix is computed (seeprojection()
), defines the type of the graph as:Graph.Type.PERSPECTIVE
,Graph.Type.ORTHOGRAPHIC
for 3d graphs andGraph.Type.TWO_D
for a 2d graph.To set up scene dimensions call
setBoundingBall(Vector, float)
. The resulting ball is then used to:- optimally compute the
zNear()
andzFar()
clipping planes ;
- implement
eye()
motion interactions in methods such asturn(float, float, float)
,spin(int, int, int, int)
orshift(float, float, float)
; and, - to interpolate the
eye()
when callingfit(float)
, among others
setZNear(Supplier)
andsetZFar(Supplier)
to customized the z-near and z-far computations.To only affect eye motions interactions and interpolations (while leaving the current z-near and z-far computations unaffected) call
setCenter(Vector)
andsetRadius(float)
.2. Scene-graph handling
A graph forms a tree ofNode
s whose visual representations may berender()
. To render a subtree callrender(Node)
. Note that rendering routines should be called within your main-event loop.The node collection belonging to the graph may be retrieved with
nodes()
. Nub provides other useful routines to handle the hierarchy, such asNode.setReference(Node)
,Node.detach()
,Node.attach()
,branch(Node)
, andclearTree()
.The eye
AnyNode
(belonging or not to the graph hierarchy) may be set as theeye()
(seesetEye(Node)
). Several functions handle the eye, such aslookAt(Vector)
,at()
,setViewDirection(Vector)
,setUpVector(Vector)
,upVector()
,fitFOV()
,fov()
,fit()
,lookAround(float, float)
,cad(float, float)
, andmoveForward(float)
.2.1. Transformations
The graph acts as interface between screen space (a box ofwidth()
*height()
* 1 dimensions), from where user gesture data is gathered, and thenodes
. To transform points from/to screen space to/from node space uselocation(Vector, Node)
andscreenLocation(Vector, Node)
. To transform vectors from/to screen space to/from node space usedisplacement(Vector, Node)
andscreenDisplacement(Vector, Node)
.3. Picking and interaction
Picking a node to interact with it is a two-step process:- Tag the node using an arbitrary name (which may be
null
) either withtag(String, Node)
) or ray-casting:updateTag(String, int, int, Node[])
,updateTag(String, int, int)
ortag(String, int, int)
. WhileupdateTag(String, int, int, Node[])
andupdateTag(String, int, int)
update the tagged node synchronously (i.e., they return the tagged node immediately),tag(String, int, int)
updates it asynchronously (i.e., it optimally updates the tagged node during the next call to therender()
orrender(Node)
algorithms); and, - Interact with your tagged nodes by calling any of the following methods:
align(String)
,focus(String)
,shift(String, float, float, float, float)
,turn(String, float, float, float, float)
,zoom(String, float, float)
, orspin(String, int, int, int, int, float)
).
- Refer to
Node.bullsEyeSize()
(andNode.setBullsEyeSize(float)
) for the different ray-casting node picking policies. - To check if a given node would be picked with a ray casted at a given screen position,
call
tracks(Node, int, int)
. - To interact with the node that is referred with the
null
tag, call any of the following methods:align()
,focus()
,shift(float, float, float, float)
,turn(float, float, float, float)
,zoom(float, float)
andspin(int, int, int, int, float)
). - To directly interact with a given node, call any of the following methods:
align(Node)
,focus(Node)
,shift(Node, float, float, float, float)
,turn(Node, float, float, float, float)
,zoom(Node, float, float)
andspin(Node, int, int, int, int, float)
). - To either interact with the node referred with a given tag or the eye, when that tag is not in use,
call any of the following methods:
align(Node)
,focus(String)
,shift(String, float, float, float, float)
,turn(String, float, float, float, float)
,zoom(String, float, float)
andspin(String, int, int, int, int, float)
. - Set
Graph.inertia
in [0..1] (0 no inertia & 1 no friction) to change the default inertia value globally, instead of setting it on a per method call basis. Note that it is initially set to 0.8. - Customize node behaviors by overridden
Node.interact(Object...)
and then invoke them by either calling:interact(Object...)
,interact(String, Object...)
orinteract(Node, Object...)
.
4. Visibility and culling techniques
Geometry may be culled against the viewing volume by callingisPointVisible(Vector)
,ballVisibility(Vector, float)
orboxVisibility(Vector, Vector)
.5. Matrix handling
The graph performs matrix handling through a matrix-handler. Refer to theMatrixHandler
documentation for details.To define your geometry on the screen coordinate system (such as when drawing 2d controls on top of a 3d graph) issue your drawing code between
beginHUD()
andendHUD()
. These methods areMatrixHandler
wrapper functions with the same signatures provided for convenience.- See Also:
MatrixHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Graph.Type
Enumerates the graph types.static class
Graph.Visibility
Enumerates the different visibility states an object may have respect to the bounding volume.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBehavior(Node node, BiConsumer<Graph,Node> behavior)
Adds a custom node behavior to be executed for this scenerender()
algorithm.void
addBehavior(Node node, Consumer<Node> behavior)
Same assetBehavior(node, (g, n) -> behavior.accept(n))
.void
align()
Same asalign((String)null)
.void
align(String tag)
Same asif (tag == null || node(tag) != null) align(node(tag))
.void
align(Node node)
Aligns the node (use null for the world) with theeye()
.float
aspectRatio()
Vector
at()
2D eyes return the position.Graph.Visibility
ballVisibility(Vector center, float radius)
ReturnsGraph.Visibility.VISIBLE
,Graph.Visibility.INVISIBLE
, orGraph.Visibility.SEMIVISIBLE
, depending whether the ball (of radiusradius
and centercenter
) is visible, invisible, or semi-visible, respectively.float
ballZFar()
The far clipping plane is positioned at a distance equal tozClippingCoefficient() * radius()
behind thecenter()
:float
ballZNear()
void
beginHUD()
Begin Heads Up Display (HUD) so that drawing can be done using 2D screen coordinates.float[][]
bounds()
Returns the bounds plane equations.Graph.Visibility
boxVisibility(Vector corner1, Vector corner2)
ReturnsGraph.Visibility.VISIBLE
,Graph.Visibility.INVISIBLE
, orGraph.Visibility.SEMIVISIBLE
, depending whether the axis aligned box (defined by cornersp1
andp2
) is visible, invisible, or semi-visible, respectively.static List<Node>
branch(Node node)
Collectsnode
and all its descendant nodes.void
cad(float roll, float pitch)
Same asrotateCAD(roll, pitch, new Vector(0, 1, 0), Graph.inertia)
.void
cad(float roll, float pitch, Vector upVector)
Same asrotateCAD(roll, pitch, upVector, Graph.inertia)
.void
cad(float roll, float pitch, Vector upVector, float inertia)
Defines an axis which the eye rotates around.static Float
castToFloat(Object o)
Casto
to aFloat
.static Integer
castToInt(Object o)
Casto
to anInteger
.Vector
center()
Center of the ball (defined in world coordinates) used in eye motions interaction (e.g.,shift(float, float, float)
,spin(int, int, int, int)
,turn(float, float, float)
) and interpolation routines (e.g.,fit()
).void
clearTags()
Removes all tags so thatnode(String)
returnsnull
.static void
clearTree()
Same asfor(Node node : _leadingNodes()) detach(node)
.void
closeContext()
Ends the rendering process (seerender(Node)
).Object
context()
Returns the main renderer context.void
disableTagging(Node node)
Disables tagging the node.Vector
displacement(Vector vector)
Same asreturn displacement(vector, null)
.Vector
displacement(Vector vector, Node node)
Convertsvector
displacement given in screen space to thenode
coordinate system.float
distanceToBound(int index, Vector position)
Returns the signed distance between pointposition
and planeindex
in world units.void
draw()
Paint method which is called just after your main event loop.void
endHUD()
Ends Heads Up Display (HUD).Node
eye()
Returns the associated eye.void
fit()
void
fit(float duration)
void
fit(int x, int y, int width, int height)
Moves the eye so that the rectangular screen region defined byx, y, width, height
(pixel units, with origin in the upper left corner) fits the screen.void
fit(int x, int y, int width, int height, float duration)
Smoothly moves the eye duringduration
milliseconds so that the rectangular screen region defined byrectangle
(pixel units, with origin in the upper left corner) fits the screen.void
fit(Node node)
Convenience function that simply callsfit(node, 0)
.void
fit(Node node, float duration)
Smoothly interpolates the eye on a interpolator path so that it goes tonode
.void
fit(Vector corner1, Vector corner2)
Moves the eye so that the world axis aligned box defined bycorner1
andcorner2
is entirely visible.void
fit(Vector corner1, Vector corner2, float duration)
Smoothly moves the eye duringduration
milliseconds so that the world axis aligned box defined bycorner1
andcorner2
is entirely visible.void
fitFOV()
void
fitFOV(float duration)
Rescales thefov()
duration
milliseconds so that the ball defined bycenter
andradius
is visible and fits the window.void
focus()
Same asfocus((String)null)
.void
focus(String tag)
Same asif (tag == null || node(tag) != null) focus(node(tag))
.void
focus(Node node)
Focuses the node (use null for the world) with theeye()
.float
fov()
Retrieves the scene field-of-view in radians.boolean
hasFocus(int pixelX, int pixelY)
Returns whether or not the scene has focus or not under the given pixel.boolean
hasTag(String tag, Node node)
boolean
hasTag(Node node)
Same asreturn hasTag(null, node)
.int
height()
Returns height of the screen window.float
hfov()
Same asreturn type() == Type.PERSPECTIVE ? radians(eye().magnitude() * aspectRatio()) : eye().magnitude()
.void
interact(Object... gesture)
Same asinteract((String)null, gesture)
.void
interact(String tag, Object... gesture)
Same asif (tag == null || node(tag) != null) interact(node(tag), gesture)
.void
interact(Node node, Object... gesture)
Call thenode
(or theeye()
ifnode
is null) interact gesture parser function set either withNode.setInteraction(Consumer)
orNode.setInteraction(BiConsumer)
.boolean
is2D()
boolean
is3D()
boolean
isConeBackFacing(Vector vertex, ArrayList<Vector> normals)
Returnstrue
if the given cone is back-facing the eye andfalse
otherwise.boolean
isConeBackFacing(Vector vertex, Vector[] normals)
Returnstrue
if the given cone is back-facing the eye andfalse
otherwise.boolean
isConeBackFacing(Vector vertex, Vector axis, float angle)
Returnstrue
if the given cone is back-facing the eye andfalse
otherwise.boolean
isConeFrontFacing(Vector vertex, ArrayList<Vector> normals)
Same asreturn !isConeBackFacing(vertex, normals)
.boolean
isConeFrontFacing(Vector vertex, Vector[] normals)
Same as!isConeBackFacing(vertex, normals)
.boolean
isConeFrontFacing(Vector vertex, Vector axis, float angle)
Same asreturn !isConeBackFacing(vertex, axis, angle)
.boolean
isEye(Node node)
Checks whether or not the given node is theeye()
.boolean
isFaceBackFacing(Vector vertex, Vector normal)
Returnstrue
if the given face is back-facing the camera.boolean
isFaceBackFacing(Vector a, Vector b, Vector c)
Returnstrue
if the given face is back-facing the eye.boolean
isFaceFrontFacing(Vector vertex, Vector normal)
Same asreturn !isFaceBackFacing(vertex, normal)
.boolean
isFaceFrontFacing(Vector a, Vector b, Vector c)
Same asreturn !isFaceBackFacing(a, b, c)
.static boolean
isNumInstance(Object o)
boolean
isOffscreen()
Returnstrue
if this scene is off-screen andfalse
otherwise.boolean
isPointVisible(float x, float y, float z)
Same asreturn isPointVisible(new Vector(x, y, z))
.boolean
isPointVisible(Vector point)
Returnstrue
ifpoint
is visible (i.e, lies within the eye bounds) andfalse
otherwise.boolean
isTagged(Node node)
Returnstrue
if the node is currently being tagged andfalse
otherwise.boolean
isTagValid()
Same asisTagValid(null)
.boolean
isTagValid(String tag)
Returnstrue
if some node is tagged withtag
(which may be {code null}) andfalse
otherwise.long
lastUpdate()
Max betweenNode.lastUpdate()
and_lastNonEyeUpdate()
.Vector
location(Vector pixel)
Convenience function that simply returnslocation(pixel, null)
.Vector
location(Vector pixel, Node node)
Returns thenode
coordinates ofpixel
.void
lookAround(float deltaX, float deltaY)
Same aslookAround(deltaX, deltaY, Graph.inertia)
.void
lookAround(float deltaX, float deltaY, float inertia)
Look around (without translating the eye) according to angular displacementsdeltaX
anddeltaY
expressed in radians.void
lookAt(Vector target)
2D eyes simply callnode().setPosition(target.x(), target.y())
.void
moveForward(float delta)
Same asmoveForward(delta, Graph.inertia)
.void
moveForward(float delta, float inertia)
Same astranslateEye(0, 0, delta / (zNear() - zFar()))
.Vector
ndcToScreenDisplacement(Vector vector)
Convertsvector
displacement from normalized device coordinates (NDC) to screen space.Vector
ndcToScreenLocation(Vector vector)
Convertsvector
location from normalized device coordinates (NDC) to screen space.Node
node()
Same asreturn node(null)
.Node
node(String tag)
Returns the node tagged withtag
(which may benull
) which is usually set by ray casting (seeupdateTag(String, int, int)
).static List<Node>
nodes()
Returns a list of all the nodes that are reachable by therender()
algorithm.void
openContext()
Begins the rendering process (seerender(Node)
).void
pixelToLine(int pixelX, int pixelY, Vector origin, Vector direction)
Gives the coefficients of a 3D half-line passing through the eye position and pixel (pixelX,pixelY).float
pixelToSceneRatio(Vector position)
Returns the pixel to scene (units) ratio atposition
.void
pre()
Paint method which is called just before your main event loop starts.Matrix
projection()
Returns the cached projection matrix computed atopenContext()
.Matrix
projectionView()
Returns the projection times view cached matrix computed atopenContext()
}.Matrix
projectionViewInverse()
Returns the projection times view inverse matrix.float
radius()
Radius of the ball (defined in world coordinates) used in eye motions interaction (e.g.,shift(float, float, float)
,spin(int, int, int, int)
,turn(float, float, float)
) and interpolation routines (e.g.,fit()
).void
randomize(Node node)
Same asnode.randomize(center(), radius(), is3D())
.Node
randomNode()
Same asreturn Node.random(this)
.void
removeTag()
Same asremoveTag(null)
.void
removeTag(String tag)
void
render()
void
render(Node subtree)
CallsopenContext()
, then renders the nodesubtree
(or the whole tree whensubtree
isnull
) onto thecontext()
from theeye()
viewpoint, and callscloseContext()
.void
resetBehavior(Node node)
Resets the node custom behavior which is set withaddBehavior(Node, BiConsumer)
.Vector
rightVector()
Returns the normalized right vector of the eye, defined in the world coordinate system.float
sceneToPixelRatio(Vector position)
Returns the ratio of scene (units) to pixel atposition
.Vector
screenDisplacement(Vector vector)
Same asreturn screenDisplacement(vector, null)
.Vector
screenDisplacement(Vector vector, Node node)
Converts thenode
vector
displacement to screen space.Vector
screenLocation(Node node)
Converts thenode
origin location to screen space.Vector
screenLocation(Vector vector)
Convertsvector
location from world to screen space.Vector
screenLocation(Vector vector, Node node)
Convertsvector
location fromnode
to screen.Vector
screenToNDCDisplacement(Vector vector)
Convertsvector
displacement from screen space to normalized device coordinates (NDC).Vector
screenToNDCLocation(Vector vector)
Convertsvector
location from screen space to normalized device coordinates (NDC).void
setBoundingBall(Vector center, float radius)
void
setCenter(Vector center)
Setscenter()
.void
setEye(Node eye)
Replaces the currenteye()
witheye
.void
setFOV(float fov)
Sets theeye()
Node.worldMagnitude()
, according tofov
(field-of-view) which is expressed in radians.void
setHeight(int height)
Sets the graphheight()
in pixels.void
setHFOV(float hfov)
void
setRadius(float radius)
Setsradius()
.void
setType(Graph.Type type)
Defines the graph_type
according to the projection of the scene.void
setUpVector(Vector up)
Convenience function that simply callssetUpVector(up, true)
.void
setUpVector(Vector up, boolean noMove)
Rotates the eye so that itsupVector()
becomesup
(defined in the world coordinate system).void
setViewDirection(Vector direction)
Rotates the eye so that itsviewDirection()
isdirection
(defined in the world coordinate system).void
setWidth(int width)
Sets the graphwidth()
in pixels.void
setZFar(Supplier<Float> zFar)
Sets thezFar()
computation routine.void
setZNear(Supplier<Float> zNear)
Sets thezNear()
computation routine.void
shift(float dx, float dy, float dz)
Same asshift(dx, dy, dz, Graph.inertia)
.void
shift(float dx, float dy, float dz, float inertia)
Same asshift((String)null, dx, dy, dz, inertia)
.void
shift(String tag, float dx, float dy, float dz)
Same asshift(tag, dx, dy, dz, Graph.inertia)
.void
shift(String tag, float dx, float dy, float dz, float inertia)
Same asif (tag == null || node(tag) != null) shift(node(tag), dx, dy, dz, inertia)
.void
shift(Node node, float dx, float dy, float dz)
Same asshift(node, dx, dy, dz, Graph.inertia)
.void
shift(Node node, float dx, float dy, float dz, float inertia)
void
spin(int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
Same asspin(pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia)
.void
spin(int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
Same asspin((String)null, pixel1X, pixel1Y, pixel2X, pixel2Y, inertia)
.void
spin(String tag, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
Same asspin(tag, pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia)
.void
spin(String tag, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
Same asif (tag == null || node(tag) != null) spin(node(tag), pixel1X, pixel1Y, pixel2X, pixel2Y, inertia)
.void
spin(Node node, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
Same asspin(node, pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia)
.void
spin(Node node, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
Rotates thenode
(use null for the world) using an arcball interface, from points(pixel1X, pixel1Y)
to(pixel2X, pixel2Y)
pixel positions.void
tag(int pixelX, int pixelY)
Same astag(null, pixelX, pixelY)
.void
tag(String tag, int pixelX, int pixelY)
Same asupdateTag(String, int, int)
but doesn't return immediately the tagged node.void
tag(String tag, Node node)
void
tag(Node node)
Same astag(null, node)
.void
togglePerspective()
Shifts the graph_type
betweenGraph.Type.PERSPECTIVE
andGraph.Type.ORTHOGRAPHIC
while trying to keep thefov()
.boolean
tracks(Node node, int pixelX, int pixelY)
Casts a ray at pixel position(pixelX, pixelY)
and returnstrue
if the ray picks thenode
andfalse
otherwise.void
turn(float roll, float pitch, float yaw)
Same asturn(roll, pitch, yaw, Graph.inertia)
.void
turn(float roll, float pitch, float yaw, float inertia)
Same asturn((String)null, roll, pitch, yaw, inertia)
.void
turn(String tag, float roll, float pitch, float yaw)
Same asturn(tag, roll, pitch, yaw, Graph.inertia)
.void
turn(String tag, float roll, float pitch, float yaw, float inertia)
Same asif (tag == null || node(tag) != null) turn(node(tag), roll, pitch, yaw, inertia)
.void
turn(Node node, float roll, float pitch, float yaw)
Same asturn(node, roll, pitch, yaw, Graph.inertia)
.void
turn(Node node, float roll, float pitch, float yaw, float inertia)
Rotates thenode
(use null for the world) around the x-y-z screen axes according toroll
,pitch
andyaw
radians, resp., and according toinertia
which should be in[0..1]
, 0 no inertia & 1 no friction.Graph.Type
type()
Returns the graph type.void
untag(Node node)
Removes all tags pointing to thenode
.Node
updateTag(int pixelX, int pixelY)
Same asreturn updateTag(null, null, pixelX, pixelY)
.Node
updateTag(int pixelX, int pixelY, List<Node> nodeList)
Same asreturn track(null, pixelX, pixelY, nodeList)
.Node
updateTag(int pixelX, int pixelY, Node[] nodeArray)
Same asreturn track(null, pixelX, pixelY, nodeArray)
.Node
updateTag(String tag, int pixelX, int pixelY)
Tags (withtag
which may benull
) the node innodes()
picked with ray-casting at pixelpixelX, pixelY
and returns it (seenode(String)
).Node
updateTag(String tag, int pixelX, int pixelY, List<Node> nodeList)
Same asupdateTag(String, int, int, Node[])
but using a node list instead of an array.Node
updateTag(String tag, int pixelX, int pixelY, Node[] nodeArray)
Tags (withtag
which may benull
) the node innodeArray
picked with ray-casting at pixelpixelX, pixelY
and returns it (seenode(String)
).Node
updateTag(Node subtree, int pixelX, int pixelY)
Same asreturn return updateTag(subtree, null, pixelX, pixelY)
.Node
updateTag(Node subtree, String tag, int pixelX, int pixelY)
Tags (withtag
which may benull
) the node in thesubtree
(or the whole tree whensubtree
isnull
) picked with ray-casting at pixelpixelX, pixelY
and returns it (seenode(String)
).Vector
upVector()
Returns the normalized up vector of the eye, defined in the world coordinate system.Matrix
view()
Returns the cached view matrix computed at_bind()
.Vector
viewDirection()
Returns the normalized view direction of the eye, defined in the world coordinate system.int
width()
Returns width of the screen window.float
zFar()
Returns the far clipping plane distance used to compute theprojection()
matrix.Supplier<Float>
zFarSupplier()
Retrieves the currentzFar()
computation routine.float
zNear()
Returns the near clipping plane distance used to compute theprojection()
matrix.Supplier<Float>
zNearSupplier()
Retrieves the currentzNear()
computation routine.void
zoom(float delta)
Same aszoom(delta, Graph.inertia)
.void
zoom(float delta, float inertia)
Same aszoom((String)null, delta, inertia)
.void
zoom(String tag, float delta)
Same aszoom(tag, delta, Graph.inertia)
.void
zoom(String tag, float delta, float inertia)
Same asif (tag == null || node(tag) != null) zoom(node(tag), delta, inertia)
.void
zoom(Node node, float delta)
Same aszoom(node, delta, Graph.inertia)
.void
zoom(Node node, float delta, float inertia)
Scales thenode
(use null for the world) according todelta
andinertia
which should be in[0..1]
, 0 no inertia & 1 no friction.
-
-
-
Field Detail
-
random
public static Random random
-
inertia
public static float inertia
-
leftHanded
public static boolean leftHanded
-
picking
public boolean picking
-
_seeded
public static boolean _seeded
-
-
Constructor Detail
-
Graph
public Graph(Object context, int width, int height, Node eye)
Same asthis(context, width, height, eye, Type.PERSPECTIVE)
.- See Also:
Graph(Object, int, int, Node, Type)
-
Graph
public Graph(Object context, int width, int height)
Same asthis(context, width, height, Type.PERSPECTIVE)
.- See Also:
Graph(Object, int, int, Type)
-
-
Method Detail
-
isNumInstance
public static boolean isNumInstance(Object o)
-
randomNode
public Node randomNode()
Same asreturn Node.random(this)
. Creates a random node.- See Also:
Node.random(Graph)
,randomize(Node)
-
randomize
public void randomize(Node node)
Same asnode.randomize(center(), radius(), is3D())
.- See Also:
Node.randomize(Vector, float, boolean)
-
aspectRatio
public float aspectRatio()
-
width
public int width()
Returns width of the screen window.
-
height
public int height()
Returns height of the screen window.
-
setWidth
public void setWidth(int width)
Sets the graphwidth()
in pixels.
-
setHeight
public void setHeight(int height)
Sets the graphheight()
in pixels.
-
type
public Graph.Type type()
Returns the graph type. Set bysetType(Type)
.- See Also:
setType(Type)
-
setType
public void setType(Graph.Type type)
Defines the graph_type
according to the projection of the scene. EitherGraph.Type.PERSPECTIVE
,Graph.Type.ORTHOGRAPHIC
,Graph.Type.TWO_D
orGraph.Type.CUSTOM
.Graph.Type.PERSPECTIVE
andGraph.Type.ORTHOGRAPHIC
use the classical projection matrices and the nodeNode.worldMagnitude()
. Both usezNear()
andzFar()
(to define their clipping planes) andwidth()
andheight()
for frustum shape.A
Graph.Type.TWO_D
behaves likeGraph.Type.ORTHOGRAPHIC
, but instantiated graph nodes will be constrained so that they will remain at the x-y plane.- See Also:
Node.worldMagnitude()
-
togglePerspective
public void togglePerspective()
Shifts the graph_type
betweenGraph.Type.PERSPECTIVE
andGraph.Type.ORTHOGRAPHIC
while trying to keep thefov()
. Only meaningful if graphis3D()
.- See Also:
setType(Type)
,setFOV(float)
,fov()
,hfov()
,setHFOV(float)
-
setFOV
public void setFOV(float fov)
Sets theeye()
Node.worldMagnitude()
, according tofov
(field-of-view) which is expressed in radians. Meaningless if the graphis2D()
. If the graph_type
isGraph.Type.ORTHOGRAPHIC
it will match the perspective projection obtained usingfov
of an image centered at the world XY plane from the eye current position.Computed as as
Math.tan(fov/2)
if the graph type isGraph.Type.PERSPECTIVE
and asMath.tan(fov / 2) * 2 * Math.abs(Vector.scalarProjection(Vector.subtract(eye().position(), center()), eye().zAxis())) / width()
if the graph_type
isGraph.Type.ORTHOGRAPHIC
.- See Also:
fov()
,hfov()
,setHFOV(float)
,setType(Type)
-
fov
public float fov()
Retrieves the scene field-of-view in radians. Meaningless if the sceneis2D()
. SeesetFOV(float)
for details. The value is related to theeye()
Node.worldMagnitude()
as follows:- It returns
2 * Math.atan(eye().magnitude())
, when the graphtype()
isGraph.Type.PERSPECTIVE
. - It returns
2 * Math.atan(eye().magnitude() * width() / (2 * Math.abs(Vector.scalarProjection(Vector.subtract(eye().position(), center()), eye().zAxis()))))
, if the graph_type
isGraph.Type.ORTHOGRAPHIC
.
setFOV(float)
orsetHFOV(float)
.- See Also:
Node.worldMagnitude()
,setType(Type)
,setHFOV(float)
,hfov()
,setFOV(float)
- It returns
-
setHFOV
public void setHFOV(float hfov)
Sets thehfov()
of theeye()
(in radians).hfov()
andfov()
are linked by theaspectRatio()
. This method actually calls:setFOV(2.0f * (float) Math.atan((float) Math.tan(hfov / 2.0f) / aspectRatio()))
so that a call tohfov()
returns the expected value.- See Also:
setFOV(float)
,fov()
,hfov()
,setFOV(float)
-
hfov
public float hfov()
Same asreturn type() == Type.PERSPECTIVE ? radians(eye().magnitude() * aspectRatio()) : eye().magnitude()
.Returns the
eye()
horizontal field-of-view in radians.- See Also:
fov()
,setHFOV(float)
,setFOV(float)
-
zNear
public float zNear()
Returns the near clipping plane distance used to compute theprojection()
matrix.- See Also:
zFar()
-
zNearSupplier
public Supplier<Float> zNearSupplier()
Retrieves the currentzNear()
computation routine.- See Also:
zNearSupplier()
-
setZNear
public void setZNear(Supplier<Float> zNear)
Sets thezNear()
computation routine.- See Also:
zNearSupplier()
,setZFar(Supplier)
-
ballZNear
public float ballZNear()
The clipping planes' positions depend on theradius()
andcenter()
rather than being fixed small-enough and large-enough values. A good approximation will hence result in an optimal precision of the z-buffer.The near clipping plane is positioned at a distance equal to
zClippingCoefficient
*radius()
in front of thecenter()
:Vector.scalarProjection( Vector.subtract(eye().position(), center()), eye().zAxis()) - zClippingCoefficient() * radius()
In order to prevent negative or too small
zNear()
values (which would degrade the z precision),zNearCoefficient
is used when the eye is inside theradius()
ball:zMin = zNearCoefficient() * zClippingCoefficient() * radius();
zNear = zMin;
With an ORTHOGRAPHIC and TWO_D types, the value is simply clamped to 0
See also the
zFar()
documentation. Attention: The value is always positive, although the clipping plane is positioned at a negative z value in the eye coordinate system.- See Also:
ballZFar()
-
zFar
public float zFar()
Returns the far clipping plane distance used to compute theprojection()
matrix.- See Also:
zNear()
-
zFarSupplier
public Supplier<Float> zFarSupplier()
Retrieves the currentzFar()
computation routine.- See Also:
zNearSupplier()
-
setZFar
public void setZFar(Supplier<Float> zFar)
Sets thezFar()
computation routine.- See Also:
zFarSupplier()
,setZNear(Supplier)
-
ballZFar
public float ballZFar()
The far clipping plane is positioned at a distance equal tozClippingCoefficient() * radius()
behind thecenter()
:zFar = Vector.scalarProjection(Vector.subtract(eye().position(), center()), eye().zAxis()) + zClippingCoefficient() * radius()
.- See Also:
ballZNear()
-
clearTree
public static void clearTree()
Same asfor(Node node : _leadingNodes()) detach(node)
.- See Also:
Node.detach()
-
nodes
public static List<Node> nodes()
Returns a list of all the nodes that are reachable by therender()
algorithm.Note that node collections should be kept at user space for efficiency.
- See Also:
isEye(Node)
-
beginHUD
public void beginHUD()
Begin Heads Up Display (HUD) so that drawing can be done using 2D screen coordinates.All screen drawing should be enclosed between
beginHUD()
andendHUD()
. Then you can just begin drawing your screen shapes. Attention: If you want your screen drawing to appear on top of your 3d graph then draw first all your 3d before doing any call to abeginHUD()
andendHUD()
pair.Warning: Offscreen scenes should call
beginHUD()
andendHUD()
before closing the context (closeContext()
).- See Also:
endHUD()
,MatrixHandler.beginHUD(int, int)
-
endHUD
public void endHUD()
Ends Heads Up Display (HUD). Throws an exception ifbeginHUD()
wasn't properly called before.Wrapper for
MatrixHandler.endHUD()
.- See Also:
beginHUD()
,MatrixHandler.endHUD()
-
eye
public Node eye()
Returns the associated eye. Never null.- See Also:
setEye(Node)
-
isPointVisible
public boolean isPointVisible(float x, float y, float z)
Same asreturn isPointVisible(new Vector(x, y, z))
.- See Also:
isPointVisible(Vector)
-
isPointVisible
public boolean isPointVisible(Vector point)
Returnstrue
ifpoint
is visible (i.e, lies within the eye bounds) andfalse
otherwise.
-
ballVisibility
public Graph.Visibility ballVisibility(Vector center, float radius)
ReturnsGraph.Visibility.VISIBLE
,Graph.Visibility.INVISIBLE
, orGraph.Visibility.SEMIVISIBLE
, depending whether the ball (of radiusradius
and centercenter
) is visible, invisible, or semi-visible, respectively.
-
boxVisibility
public Graph.Visibility boxVisibility(Vector corner1, Vector corner2)
ReturnsGraph.Visibility.VISIBLE
,Graph.Visibility.INVISIBLE
, orGraph.Visibility.SEMIVISIBLE
, depending whether the axis aligned box (defined by cornersp1
andp2
) is visible, invisible, or semi-visible, respectively.
-
bounds
public float[][] bounds()
Returns the bounds plane equations.In 2D the four 4-component vectors, respectively correspond to the left, right, top and bottom eye bounds lines. Each vector holds a plane equation of the form:
a*x + b*y + c = 0
wherea
,b
andc
are the 3 components of each vector, in that order.In 3D the six 4-component vectors returned by this method, respectively correspond to the left, right, near, far, top and bottom eye bounding planes. Each vector holds a plane equation of the form:
a*x + b*y + c*z + d = 0
where
a
,b
,c
andd
are the 4 components of each vector, in that order.
-
distanceToBound
public float distanceToBound(int index, Vector position)
Returns the signed distance between pointposition
and planeindex
in world units. The distance is negative if the point lies in the planes's bounding halfspace, and positive otherwise.In 2D
index
is a value between0
and3
which respectively correspond to the left, right, top and bottom eye bounding planes.In 3D
index
is a value between0
and5
which respectively correspond to the left, right, near, far, top and bottom eye bounding planes.
-
pixelToSceneRatio
public float pixelToSceneRatio(Vector position)
Returns the pixel to scene (units) ratio atposition
.Convenience function that simply returns
1 / sceneToPixelRatio(position)
.- See Also:
sceneToPixelRatio(Vector)
-
sceneToPixelRatio
public float sceneToPixelRatio(Vector position)
Returns the ratio of scene (units) to pixel atposition
.A line of
n * sceneToPixelRatio()
graph units, located atposition
in the world coordinate system, will be projected with a length ofn
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
center()
and always directed along the screen vertical direction (upVector()
):beginShape(LINES);
vertex(scene.center().x(), scene.center().y(), scene.center().z());
Vector v = Vector.add(scene.center(), Vector.multiply(scene.upVector(), 20 * scene.sceneToPixelRatio(scene.center())));
vertex(v.x(), v.y(), v.z());
endShape();
-
isFaceFrontFacing
public boolean isFaceFrontFacing(Vector a, Vector b, Vector c)
Same asreturn !isFaceBackFacing(a, b, c)
.- See Also:
isFaceBackFacing(Vector, Vector, Vector)
-
isFaceBackFacing
public boolean isFaceBackFacing(Vector a, Vector b, Vector c)
Returnstrue
if the given face is back-facing the eye. Otherwise returnsfalse
.Vertices must given in clockwise order if graph is not
leftHanded
or in counter-clockwise order ifleftHanded
.- Parameters:
a
- first face vertexb
- second face vertexc
- third face vertex- See Also:
isFaceBackFacing(Vector, Vector)
,isConeBackFacing(Vector, Vector, float)
-
isFaceFrontFacing
public boolean isFaceFrontFacing(Vector vertex, Vector normal)
Same asreturn !isFaceBackFacing(vertex, normal)
.- See Also:
isFaceBackFacing(Vector, Vector)
-
isFaceBackFacing
public boolean isFaceBackFacing(Vector vertex, Vector normal)
Returnstrue
if the given face is back-facing the camera. Otherwise returnsfalse
.- Parameters:
vertex
- belonging to the facenormal
- face normal- See Also:
isFaceBackFacing(Vector, Vector, Vector)
,isConeBackFacing(Vector, Vector, float)
-
isConeFrontFacing
public boolean isConeFrontFacing(Vector vertex, ArrayList<Vector> normals)
Same asreturn !isConeBackFacing(vertex, normals)
.- See Also:
isConeBackFacing(Vector, ArrayList)
-
isConeBackFacing
public boolean isConeBackFacing(Vector vertex, ArrayList<Vector> normals)
Returnstrue
if the given cone is back-facing the eye andfalse
otherwise.- Parameters:
vertex
- Cone vertexnormals
- ArrayList of normals defining the cone.- See Also:
isConeBackFacing(Vector, Vector[])
,isConeBackFacing(Vector, Vector, float)
-
isConeFrontFacing
public boolean isConeFrontFacing(Vector vertex, Vector[] normals)
Same as!isConeBackFacing(vertex, normals)
.- See Also:
isConeBackFacing(Vector, Vector[])
-
isConeBackFacing
public boolean isConeBackFacing(Vector vertex, Vector[] normals)
Returnstrue
if the given cone is back-facing the eye andfalse
otherwise.- Parameters:
vertex
- Cone vertexnormals
- Array of normals defining the cone.- See Also:
isConeBackFacing(Vector, ArrayList)
,isConeBackFacing(Vector, Vector, float)
-
isConeFrontFacing
public boolean isConeFrontFacing(Vector vertex, Vector axis, float angle)
Same asreturn !isConeBackFacing(vertex, axis, angle)
.- See Also:
isConeBackFacing(Vector, Vector, float)
-
isConeBackFacing
public boolean isConeBackFacing(Vector vertex, Vector axis, float angle)
Returnstrue
if the given cone is back-facing the eye andfalse
otherwise.- Parameters:
vertex
- Cone vertexaxis
- Cone axisangle
- Cone angle
-
setBoundingBall
public void setBoundingBall(Vector center, float radius)
Sets the ball forzNear()
andzFar()
computations within theballZNear()
andballZFar()
functions. CallssetCenter(Vector)
setRadius(float)
.To only affect eye motions interactions and interpolations (while leaving the current z-near and z-far computations unaffected) call
setCenter(Vector)
andsetRadius(float)
.
-
radius
public float radius()
Radius of the ball (defined in world coordinates) used in eye motions interaction (e.g.,shift(float, float, float)
,spin(int, int, int, int)
,turn(float, float, float)
) and interpolation routines (e.g.,fit()
). This ball is different from the one used by theballZNear()
andballZFar()
algorithms ({see @link #setBoundingBall(Vector, float)}).Set it with
setRadius(float)
.- See Also:
center()
,setBoundingBall(Vector, float)
-
setRadius
public void setRadius(float radius)
Setsradius()
. To be used in conjuntion withsetCenter(Vector)
.- See Also:
setCenter(Vector)
,setBoundingBall(Vector, float)
-
center
public Vector center()
Center of the ball (defined in world coordinates) used in eye motions interaction (e.g.,shift(float, float, float)
,spin(int, int, int, int)
,turn(float, float, float)
) and interpolation routines (e.g.,fit()
). This ball is different from the one used by theballZNear()
andballZFar()
algorithms ({see @link #setBoundingBall(Vector, float)}).Set it with
setCenter(Vector)
.- See Also:
radius()
,setBoundingBall(Vector, float)
-
setCenter
public void setCenter(Vector center)
Setscenter()
. To be used in conjuntion withsetRadius(float)
.- See Also:
setRadius(float)
,setBoundingBall(Vector, float)
-
viewDirection
public Vector viewDirection()
Returns the normalized view direction of the eye, defined in the world coordinate system. This corresponds to the negative Z axis of theeye()
(node().worldDisplacement(new Vector(0.0f, 0.0f, -1.0f))
). In 2D it always is (0,0,-1).Change this value using
setViewDirection(Vector)
,lookAt(Vector)
orNode.setWorldOrientation(Quaternion)
. It is orthogonal toupVector()
and torightVector()
.
-
setViewDirection
public void setViewDirection(Vector direction)
Rotates the eye so that itsviewDirection()
isdirection
(defined in the world coordinate system).The eye
Node.worldPosition()
is not modified. The eye is rotated so that the horizon (defined by itsupVector()
) is preserved.- See Also:
lookAt(Vector)
,setUpVector(Vector)
-
setUpVector
public void setUpVector(Vector up)
Convenience function that simply callssetUpVector(up, true)
.- See Also:
setUpVector(Vector, boolean)
-
setUpVector
public void setUpVector(Vector up, boolean noMove)
Rotates the eye so that itsupVector()
becomesup
(defined in the world coordinate system).The eye is rotated around an axis orthogonal to
up
and to the currentupVector()
direction.Use this method in order to define the eye horizontal plane.
When
noMove
is set tofalse
, the orientation modification is compensated by a translation, so that thecenter()
stays projected at the same position on screen. This is especially useful when the eye is an observer of the graph.When
noMove
is true, the EyeNode.worldPosition()
is left unchanged, which is an intuitive behavior when the Eye is in first person mode.- See Also:
lookAt(Vector)
-
upVector
public Vector upVector()
Returns the normalized up vector of the eye, defined in the world coordinate system.Set using
setUpVector(Vector)
orNode.setWorldOrientation(Quaternion)
. It is orthogonal toviewDirection()
and torightVector()
.It corresponds to the Y axis of the associated
eye()
(actually returnsnode().yAxis()
-
lookAt
public void lookAt(Vector target)
2D eyes simply callnode().setPosition(target.x(), target.y())
. 3D eyes setNode.worldOrientation()
, so that it looks at pointtarget
defined in the world coordinate system (The eyeNode.worldPosition()
is not modified. SimplysetViewDirection(Vector)
).- See Also:
at()
,setUpVector(Vector)
,fit()
,fit(Vector, Vector)
-
rightVector
public Vector rightVector()
Returns the normalized right vector of the eye, defined in the world coordinate system.This vector lies in the eye horizontal plane, directed along the X axis (orthogonal to
upVector()
and toviewDirection()
. Set usingsetUpVector(Vector)
,lookAt(Vector)
orNode.setWorldOrientation(Quaternion)
.Simply returns
node().xAxis()
.
-
at
public Vector at()
2D eyes return the position. 3D eyes return a point defined in the world coordinate system where the eyes is pointing at (just in front ofviewDirection()
). Useful for setting the Processing camera() which uses a similar approach of that found in gluLookAt.- See Also:
lookAt(Vector)
-
fit
public void fit(Node node)
Convenience function that simply callsfit(node, 0)
.
-
fit
public void fit(Node node, float duration)
Smoothly interpolates the eye on a interpolator path so that it goes tonode
. Theduration
defines the interpolation speed.
-
fit
public void fit()
-
fit
public void fit(float duration)
Moves the eye duringduration
milliseconds so that the ball defined bycenter()
andradius()
is visible and fits the window.In 3D the eye is simply translated along its
viewDirection()
so that the ball fits the screen. ItsNode.worldOrientation()
and itsfov()
are unchanged. You should therefore orientate the eye before you call this method.
-
fitFOV
public void fitFOV(float duration)
Rescales thefov()
duration
milliseconds so that the ball defined bycenter
andradius
is visible and fits the window.The eye position and orientation are not modified and you first have to orientate the eye in order to actually see the scene (see
lookAt(Vector)
orfit()
).Attention: The
fov()
is clamped to PI/2. This happens when the eye is at a distance lower than sqrt(2) * radius() from the center().
-
fitFOV
public void fitFOV()
Changes theeye()
fov()
so that the entire scene (defined bycenter()
andradius()
) is visible.The eye position and orientation are not modified and you first have to orientate the eye in order to actually see the scene (see
lookAt(Vector)
).Attention: The
fov()
is clamped to PI/2. This happens when the eye is at a distance lower than sqrt(2) * radius() from the center().
-
fit
public void fit(Vector corner1, Vector corner2, float duration)
Smoothly moves the eye duringduration
milliseconds so that the world axis aligned box defined bycorner1
andcorner2
is entirely visible.
-
fit
public void fit(Vector corner1, Vector corner2)
Moves the eye so that the world axis aligned box defined bycorner1
andcorner2
is entirely visible.
-
fit
public void fit(int x, int y, int width, int height, float duration)
Smoothly moves the eye duringduration
milliseconds so that the rectangular screen region defined byrectangle
(pixel units, with origin in the upper left corner) fits the screen.The eye is translated (its
Node.worldOrientation()
is unchanged) so thatrectangle
is entirely visible. Since the pixel coordinates only define bounds in 3D, it's the intersection of this bounds with a plane (orthogonal to theviewDirection()
and passing through thecenter()
) that is used to define the 3D rectangle that is eventually fitted.
-
fit
public void fit(int x, int y, int width, int height)
Moves the eye so that the rectangular screen region defined byx, y, width, height
(pixel units, with origin in the upper left corner) fits the screen.In 3D the eye is translated (its
Node.worldOrientation()
is unchanged) so thatrectangle
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 theviewDirection()
and passing through thecenter()
) that is used to define the 3D rectangle that is eventually fitted.- Parameters:
x
- coordinate of the rectangley
- coordinate of the rectanglewidth
- width of the rectangleheight
- height of the rectangle- See Also:
fit(int, int, int, int, float)
,fit(Vector, Vector, float)
,fit(Vector, Vector)
,fit(float)
,fit(Node)
,fit(Node, float)
,fit()
,fitFOV()
,fitFOV(float)
-
pixelToLine
public void pixelToLine(int pixelX, int pixelY, Vector origin, Vector direction)
Gives the coefficients of a 3D half-line passing through the eye position and pixel (pixelX,pixelY). Origin in the upper left corner. Useheight()
- pixelY to locate the origin at the lower left corner.The origin of the half line (eye position) is stored in
origin
, whiledirection
contains the properly oriented and normalized direction of the half line.This method is useful for analytical intersection in a selection method.
-
is2D
public boolean is2D()
- Returns:
- true if the graph is 2D.
-
is3D
public boolean is3D()
- Returns:
- true if the graph is 3D.
-
lastUpdate
public long lastUpdate()
Max betweenNode.lastUpdate()
and_lastNonEyeUpdate()
.- Returns:
- last frame the eye was updated
- See Also:
_lastNonEyeUpdate()
-
updateTag
public Node updateTag(int pixelX, int pixelY, Node[] nodeArray)
Same asreturn track(null, pixelX, pixelY, nodeArray)
.- See Also:
updateTag(String, int, int, Node[])
-
updateTag
public Node updateTag(String tag, int pixelX, int pixelY, Node[] nodeArray)
Tags (withtag
which may benull
) the node innodeArray
picked with ray-casting at pixelpixelX, pixelY
and returns it (seenode(String)
).- See Also:
updateTag(Node, String, int, int)
,updateTag(String, int, int)
,updateTag(String, int, int, List)
,render()
,node(String)
,removeTag(String)
,tracks(Node, int, int)
,tag(String, Node)
,hasTag(String, Node)
,Node.tagging
,Node.bullsEyeSize()
,Node.setBullsEyeSize(float)
,tag(String, int, int)
,tag(String, int, int)
-
updateTag
public Node updateTag(int pixelX, int pixelY, List<Node> nodeList)
Same asreturn track(null, pixelX, pixelY, nodeList)
.- See Also:
updateTag(String, int, int, List)
-
updateTag
public Node updateTag(String tag, int pixelX, int pixelY, List<Node> nodeList)
Same asupdateTag(String, int, int, Node[])
but using a node list instead of an array.- See Also:
updateTag(String, int, int, Node[])
-
updateTag
public Node updateTag(int pixelX, int pixelY)
Same asreturn updateTag(null, null, pixelX, pixelY)
.- See Also:
updateTag(Node, String, int, int)
-
updateTag
public Node updateTag(Node subtree, int pixelX, int pixelY)
Same asreturn return updateTag(subtree, null, pixelX, pixelY)
.- See Also:
updateTag(Node, String, int, int)
-
updateTag
public Node updateTag(String tag, int pixelX, int pixelY)
Tags (withtag
which may benull
) the node innodes()
picked with ray-casting at pixelpixelX, pixelY
and returns it (seenode(String)
). May returnnull
if no node is intersected by the ray. Not that theeye()
is never tagged. Same asreturn updateTag(null, tag, pixelX, pixelY)
.
-
updateTag
public Node updateTag(Node subtree, String tag, int pixelX, int pixelY)
Tags (withtag
which may benull
) the node in thesubtree
(or the whole tree whensubtree
isnull
) picked with ray-casting at pixelpixelX, pixelY
and returns it (seenode(String)
). May returnnull
if no node is intersected by the ray. Not that theeye()
is never tagged.
-
tracks
public boolean tracks(Node node, int pixelX, int pixelY)
Casts a ray at pixel position(pixelX, pixelY)
and returnstrue
if the ray picks thenode
andfalse
otherwise. The node is picked according to theNode.bullsEyeSize()
.
-
tag
public void tag(int pixelX, int pixelY)
Same astag(null, pixelX, pixelY)
.- See Also:
tag(String, int, int)
-
tag
public void tag(String tag, int pixelX, int pixelY)
Same asupdateTag(String, int, int)
but doesn't return immediately the tagged node. The algorithm schedules an updated of the node to be tagged for the next traversal and hence should be always be used in conjunction withrender()
.The tagged node (see
node(String)
) would be available after the next call torender()
. It may benull
if no node is intersected by the ray. Not that theeye()
is never tagged.This method is optimal since it tags the nodes at traversal time. Prefer this method over
updateTag(String, int, int)
when dealing with several tags.
-
hasFocus
public boolean hasFocus(int pixelX, int pixelY)
Returns whether or not the scene has focus or not under the given pixel.
-
isOffscreen
public boolean isOffscreen()
Returnstrue
if this scene is off-screen andfalse
otherwise.
-
context
public Object context()
Returns the main renderer context.
-
pre
public void pre()
Paint method which is called just before your main event loop starts. Handles timing tasks, resize events, prepares caches, and opens the context if the scene is onscreen.This method should be registered at the PApplet (which requires it to be public and named as pre) and hence you don't need to call it.
- See Also:
draw()
,render()
,isOffscreen()
-
draw
public void draw()
Paint method which is called just after your main event loop. Closes the context if the scene is onscreen and renders when needed the back buffer (useful for picking).This method should be registered at the PApplet (which requires it to be pubic and be named as draw) and hence you don't need to call it.
- See Also:
pre()
,render()
,isOffscreen()
-
projection
public Matrix projection()
Returns the cached projection matrix computed atopenContext()
.
-
projectionView
public Matrix projectionView()
Returns the projection times view cached matrix computed atopenContext()
}.
-
projectionViewInverse
public Matrix projectionViewInverse()
Returns the projection times view inverse matrix.
-
openContext
public void openContext()
Begins the rendering process (seerender(Node)
). Use it always beforecloseContext()
. Binds the matrices to the renderer.This method is automatically called by
render(Node)
. Call it explicitly when you need to customize that which is to be rendered, as follows:scene.openContext(); worldCustomRender() scene.closeContext();
render(Node)
withinopenContext
andcloseContext
, beforeopenContext
or aftercloseContext
, or not even call it.- See Also:
render(Node)
,closeContext()
,isOffscreen()
,context()
-
closeContext
public void closeContext()
Ends the rendering process (seerender(Node)
). Use it always afteropenContext()
. Clears the picking cache. Displays the scene HUD.- See Also:
render(Node)
,openContext()
,isOffscreen()
,context()
-
render
public void render()
Renders the node tree onto thecontext()
from theeye()
viewpoint. CallsaddBehavior(Node, BiConsumer)
on each visited node (refer to theNode
documentation). Same asrender(null)
.
-
render
public void render(Node subtree)
CallsopenContext()
, then renders the nodesubtree
(or the whole tree whensubtree
isnull
) onto thecontext()
from theeye()
viewpoint, and callscloseContext()
. All rendered nodes are marked as such (Node.rendered(Graph)
). After issuing a render command you'll be left out at the world coordinate system. If the scene is offscreen this method should be called withinopenContext()
andcloseContext()
.Note that the rendering algorithm executes the custom behavior (set with
addBehavior(Node, BiConsumer)
) on each rendered node. (refer to theNode
documentation).
-
addBehavior
public void addBehavior(Node node, BiConsumer<Graph,Node> behavior)
Adds a custom node behavior to be executed for this scenerender()
algorithm.Bypassing the node rendering and/or performing hierarchical culling, i.e., culling of the node and its children, should be done here.
Graph scene = new Graph(context, width, height); Node space = new Node(); public void behavior(Graph graph, Node node) { if (graph.cullingCondition) { node.cull = true; } else if (bypassCondition) { node.bypass(); } } scene.addBehavior(space, behavior);
ballVisibility(Vector, float)
orboxVisibility(Vector, Vector)
.
-
addBehavior
public void addBehavior(Node node, Consumer<Node> behavior)
Same assetBehavior(node, (g, n) -> behavior.accept(n))
.
-
resetBehavior
public void resetBehavior(Node node)
Resets the node custom behavior which is set withaddBehavior(Node, BiConsumer)
.- See Also:
addBehavior(Node, BiConsumer)
,render(Node)
,Node.bypass()
,Node.cull
-
tag
public void tag(Node node)
Same astag(null, node)
.- See Also:
tag(String, Node)
-
tag
public void tag(String tag, Node node)
Tags thenode
(withtag
which may benull
) (seenode(String)
). Tagging theeye()
is not allowed. CallupdateTag(String, int, int)
ortag(String, int, int)
to tag the node with ray casting.
-
node
public Node node()
Same asreturn node(null)
.- See Also:
node(String)
-
node
public Node node(String tag)
Returns the node tagged withtag
(which may benull
) which is usually set by ray casting (seeupdateTag(String, int, int)
). May returnnull
. Reset it withremoveTag(String)
.
-
isTagValid
public boolean isTagValid()
Same asisTagValid(null)
.- See Also:
isTagValid(String)
-
isTagValid
public boolean isTagValid(String tag)
Returnstrue
if some node is tagged withtag
(which may be {code null}) andfalse
otherwise.
-
isTagged
public boolean isTagged(Node node)
Returnstrue
if the node is currently being tagged andfalse
otherwise.
-
hasTag
public boolean hasTag(Node node)
Same asreturn hasTag(null, node)
.- See Also:
hasTag(String, Node)
-
clearTags
public void clearTags()
Removes all tags so thatnode(String)
returnsnull
.
-
disableTagging
public void disableTagging(Node node)
Disables tagging the node. CallsunTag(node)
and thennode.disableTagging()
.- See Also:
untag(Node)
,Node.tagging
-
untag
public void untag(Node node)
Removes all tags pointing to thenode
.
-
removeTag
public void removeTag()
Same asremoveTag(null)
.- See Also:
removeTag(String)
-
removeTag
public void removeTag(String tag)
-
ndcToScreenLocation
public Vector ndcToScreenLocation(Vector vector)
Convertsvector
location from normalized device coordinates (NDC) to screen space.screenToNDCLocation(Vector)
performs the inverse transformation.ndcToScreenDisplacement(Vector)
transforms vector displacements instead of locations.
-
screenToNDCLocation
public Vector screenToNDCLocation(Vector vector)
Convertsvector
location from screen space to normalized device coordinates (NDC).ndcToScreenLocation(Vector)
performs the inverse transformation.screenToNDCDisplacement(Vector)
transforms vector displacements instead of locations.
-
screenLocation
public Vector screenLocation(Node node)
Converts thenode
origin location to screen space. Same asreturn screenLocation(new Vector(), node)
.
-
screenLocation
public Vector screenLocation(Vector vector)
Convertsvector
location from world to screen space. Same asreturn screenLocation(src, null)
.- See Also:
screenLocation(Node)
,screenLocation(Vector, Node)
-
screenLocation
public Vector screenLocation(Vector vector, Node node)
Convertsvector
location fromnode
to screen. Uselocation(Vector, Node)
to perform the inverse transformation.The x and y coordinates of the returned vector are expressed in screen coordinates, (0,0) being the upper left corner of the window. The z coordinate ranges between 0 (near plane) and 1 (excluded, far plane).
-
location
public Vector location(Vector pixel)
Convenience function that simply returnslocation(pixel, null)
.- See Also:
location(Vector, Node)
-
location
public Vector location(Vector pixel, Node node)
Returns thenode
coordinates ofpixel
.The pixel (0,0) corresponds to the upper left corner of the window. The
pixel.z()
is a depth value ranging in [0..1] (near and far plane respectively). In 3D note thatpixel.z
is not a linear interpolation betweenzNear()
andzFar()
;pixel.z = zFar() / (zFar() - zNear()) * (1.0f - zNear() / z);
wherez
is the distance from the point you project to the camera, along theviewDirection()
.The result is expressed in the
node
coordinate system. Whennode
isnull
, the result is expressed in the world coordinates system. The possiblenode
hierarchy (i.e., whenNode.reference()
is non-null) is taken into account.screenLocation(Vector, Node)
performs the inverse transformation.screenDisplacement(Vector, Node)
converts vector displacements instead of locations.This method only uses the intrinsic eye parameters (view and projection matrices),
width()
andheight()
). You can hence define a virtual eye and use this method to compute un-projections out of a classical rendering context.
-
ndcToScreenDisplacement
public Vector ndcToScreenDisplacement(Vector vector)
Convertsvector
displacement from normalized device coordinates (NDC) to screen space.screenToNDCDisplacement(Vector)
performs the inverse transformation.ndcToScreenLocation(Vector)
transforms locations instead of vector displacements.
-
screenToNDCDisplacement
public Vector screenToNDCDisplacement(Vector vector)
Convertsvector
displacement from screen space to normalized device coordinates (NDC).ndcToScreenDisplacement(Vector)
performs the inverse transformation.screenToNDCLocation(Vector)
transforms locations instead of vector displacements.
-
displacement
public Vector displacement(Vector vector)
Same asreturn displacement(vector, null)
.- See Also:
displacement(Vector, Node)
,location(Vector, Node)
-
displacement
public Vector displacement(Vector vector, Node node)
Convertsvector
displacement given in screen space to thenode
coordinate system. The screen space coordinate system is centered at the bounding box ofwidth()
*height()
* 1} dimensions. The screen space defines the place where user gestures takes place, e.g.,shift(Node, float, float, float)
.screenDisplacement(Vector, Node)
performs the inverse transformation.screenLocation(Vector, Node)
converts pixel locations instead.
-
screenDisplacement
public Vector screenDisplacement(Vector vector)
Same asreturn screenDisplacement(vector, null)
.
-
screenDisplacement
public Vector screenDisplacement(Vector vector, Node node)
Converts thenode
vector
displacement to screen space.displacement(Vector, Node)
performs the inverse transformation.screenLocation(Vector, Node)
converts pixel locations instead.
-
interact
public void interact(Object... gesture)
Same asinteract((String)null, gesture)
.- See Also:
interact(String, Object...)
-
interact
public void interact(String tag, Object... gesture)
Same asif (tag == null || node(tag) != null) interact(node(tag), gesture)
.- See Also:
interact(Node, Object...)
-
interact
public void interact(Node node, Object... gesture)
Call thenode
(or theeye()
ifnode
is null) interact gesture parser function set either withNode.setInteraction(Consumer)
orNode.setInteraction(BiConsumer)
.
-
align
public void align()
Same asalign((String)null)
.- See Also:
align(String)
,align(Node)
-
align
public void align(String tag)
Same asif (tag == null || node(tag) != null) align(node(tag))
.- See Also:
align()
,align(Node)
,node(String)
-
align
public void align(Node node)
Aligns the node (use null for the world) with theeye()
.- See Also:
align()
,align(String tag)
-
focus
public void focus()
Same asfocus((String)null)
.- See Also:
focus(String)
,focus(Node)
-
focus
public void focus(String tag)
Same asif (tag == null || node(tag) != null) focus(node(tag))
.- See Also:
focus()
,focus(Node)
,node(String)
-
focus
public void focus(Node node)
Focuses the node (use null for the world) with theeye()
.Note that the ball
center()
is used as reference point when focusing the eye.- See Also:
focus()
,focus(String tag)
-
zoom
public void zoom(float delta)
Same aszoom(delta, Graph.inertia)
.- See Also:
zoom(float, float)
-
zoom
public void zoom(float delta, float inertia)
Same aszoom((String)null, delta, inertia)
.- See Also:
zoom(String, float, float)
-
zoom
public void zoom(String tag, float delta)
Same aszoom(tag, delta, Graph.inertia)
.- See Also:
zoom(String, float, float)
-
zoom
public void zoom(String tag, float delta, float inertia)
Same asif (tag == null || node(tag) != null) zoom(node(tag), delta, inertia)
.- See Also:
zoom(Node, float, float)
-
zoom
public void zoom(Node node, float delta)
Same aszoom(node, delta, Graph.inertia)
.- See Also:
zoom(Node, float, float)
-
zoom
public void zoom(Node node, float delta, float inertia)
Scales thenode
(use null for the world) according todelta
andinertia
which should be in[0..1]
, 0 no inertia & 1 no friction.
-
shift
public void shift(float dx, float dy, float dz)
Same asshift(dx, dy, dz, Graph.inertia)
.- See Also:
shift(float, float, float, float)
-
shift
public void shift(float dx, float dy, float dz, float inertia)
Same asshift((String)null, dx, dy, dz, inertia)
.
-
shift
public void shift(String tag, float dx, float dy, float dz)
Same asshift(tag, dx, dy, dz, Graph.inertia)
.
-
shift
public void shift(String tag, float dx, float dy, float dz, float inertia)
Same asif (tag == null || node(tag) != null) shift(node(tag), dx, dy, dz, inertia)
.- See Also:
shift(Node, float, float, float, float)
-
shift
public void shift(Node node, float dx, float dy, float dz)
Same asshift(node, dx, dy, dz, Graph.inertia)
.- See Also:
shift(Node, float, float, float, float)
-
shift
public void shift(Node node, float dx, float dy, float dz, float inertia)
-
turn
public void turn(float roll, float pitch, float yaw)
Same asturn(roll, pitch, yaw, Graph.inertia)
.- See Also:
turn(float, float, float, float)
-
turn
public void turn(float roll, float pitch, float yaw, float inertia)
Same asturn((String)null, roll, pitch, yaw, inertia)
.- See Also:
turn(String, float, float, float, float)
-
turn
public void turn(String tag, float roll, float pitch, float yaw)
Same asturn(tag, roll, pitch, yaw, Graph.inertia)
.- See Also:
turn(String, float, float, float, float)
-
turn
public void turn(String tag, float roll, float pitch, float yaw, float inertia)
Same asif (tag == null || node(tag) != null) turn(node(tag), roll, pitch, yaw, inertia)
.- See Also:
turn(Node, float, float, float, float)
-
turn
public void turn(Node node, float roll, float pitch, float yaw)
Same asturn(node, roll, pitch, yaw, Graph.inertia)
.- See Also:
turn(Node, float, float, float, float)
-
turn
public void turn(Node node, float roll, float pitch, float yaw, float inertia)
Rotates thenode
(use null for the world) around the x-y-z screen axes according toroll
,pitch
andyaw
radians, resp., and according toinertia
which should be in[0..1]
, 0 no inertia & 1 no friction.Note that the ball
center()
is used as reference point when turning the eye.
-
spin
public void spin(int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
Same asspin(pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia)
.- See Also:
spin(int, int, int, int, float)
-
spin
public void spin(int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
Same asspin((String)null, pixel1X, pixel1Y, pixel2X, pixel2Y, inertia)
.- See Also:
spin(String, int, int, int, int, float)
-
spin
public void spin(String tag, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
Same asspin(tag, pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia)
.- See Also:
spin(String, int, int, int, int, float)
-
spin
public void spin(String tag, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
Same asif (tag == null || node(tag) != null) spin(node(tag), pixel1X, pixel1Y, pixel2X, pixel2Y, inertia)
.- See Also:
spin(Node, int, int, int, int, float)
-
spin
public void spin(Node node, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)
Same asspin(node, pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia)
.- See Also:
spin(Node, int, int, int, int, float)
-
spin
public void spin(Node node, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)
Rotates thenode
(use null for the world) using an arcball interface, from points(pixel1X, pixel1Y)
to(pixel2X, pixel2Y)
pixel positions. Theinertia
controls the gesture strength and it should be in[0..1]
, 0 no inertia & 1 no friction. The center of the rotation is the screen projected node origin (seeNode.worldPosition()
).For implementation details refer to Shoemake 92 paper: Arcball: a user interface for specifying three-dimensional orientation using a mouse.
Note that the ball
center()
is used as pivot when spinning the eye.
-
moveForward
public void moveForward(float delta)
Same asmoveForward(delta, Graph.inertia)
.- See Also:
moveForward(float, float)
-
moveForward
public void moveForward(float delta, float inertia)
Same astranslateEye(0, 0, delta / (zNear() - zFar()))
. The gesture strength is controlled withinertia
which should be in[0..1]
, 0 no inertia & 1 no friction. Also rescales theeye()
if the graph type isGraph.Type.ORTHOGRAPHIC
so that nearby objects appear bigger when moving towards them.- See Also:
shift(float, float, float)
-
lookAround
public void lookAround(float deltaX, float deltaY)
Same aslookAround(deltaX, deltaY, Graph.inertia)
.
-
lookAround
public void lookAround(float deltaX, float deltaY, float inertia)
Look around (without translating the eye) according to angular displacementsdeltaX
anddeltaY
expressed in radians. The gesture strength is controlled withinertia
which should be in[0..1]
, 0 no inertia & 1 no friction.
-
cad
public void cad(float roll, float pitch)
Same asrotateCAD(roll, pitch, new Vector(0, 1, 0), Graph.inertia)
.- See Also:
cad(float, float, Vector, float)
-
cad
public void cad(float roll, float pitch, Vector upVector)
Same asrotateCAD(roll, pitch, upVector, Graph.inertia)
.- See Also:
cad(float, float, Vector, float)
-
cad
public void cad(float roll, float pitch, Vector upVector, float inertia)
Defines an axis which the eye rotates around. The eye can rotate left or right around this axis. It can also be moved up or down to show the 'top' and 'bottom' views of the scene. As a result, theupVector
will always appear vertical in the scene, and the horizon is preserved and stays projected along the eye's horizontal axis. The gesture strength is controlled withinertia
which should be in[0..1]
, 0 no inertia & 1 no friction.This method requires calling
scene.eye().setYAxis(upVector)
(seeNode.setYAxis(Vector)
) andfit()
first.Note that the ball
center()
is used as reference point when rotating the eye.- See Also:
cad(float, float)
-
-