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.ORTHOGRAPHICfor 3d graphs andGraph.Type.TWO_Dfor 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 ofNodes 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
nulltag, 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.inertiain [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 theMatrixHandlerdocumentation 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 areMatrixHandlerwrapper functions with the same signatures provided for convenience.- See Also:
MatrixHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGraph.TypeEnumerates the graph types.static classGraph.VisibilityEnumerates 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 voidaddBehavior(Node node, BiConsumer<Graph,Node> behavior)Adds a custom node behavior to be executed for this scenerender()algorithm.voidaddBehavior(Node node, Consumer<Node> behavior)Same assetBehavior(node, (g, n) -> behavior.accept(n)).voidalign()Same asalign((String)null).voidalign(String tag)Same asif (tag == null || node(tag) != null) align(node(tag)).voidalign(Node node)Aligns the node (use null for the world) with theeye().floataspectRatio()Vectorat()2D eyes return the position.Graph.VisibilityballVisibility(Vector center, float radius)ReturnsGraph.Visibility.VISIBLE,Graph.Visibility.INVISIBLE, orGraph.Visibility.SEMIVISIBLE, depending whether the ball (of radiusradiusand centercenter) is visible, invisible, or semi-visible, respectively.floatballZFar()The far clipping plane is positioned at a distance equal tozClippingCoefficient() * radius()behind thecenter():floatballZNear()voidbeginHUD()Begin Heads Up Display (HUD) so that drawing can be done using 2D screen coordinates.float[][]bounds()Returns the bounds plane equations.Graph.VisibilityboxVisibility(Vector corner1, Vector corner2)ReturnsGraph.Visibility.VISIBLE,Graph.Visibility.INVISIBLE, orGraph.Visibility.SEMIVISIBLE, depending whether the axis aligned box (defined by cornersp1andp2) is visible, invisible, or semi-visible, respectively.static List<Node>branch(Node node)Collectsnodeand all its descendant nodes.voidcad(float roll, float pitch)Same asrotateCAD(roll, pitch, new Vector(0, 1, 0), Graph.inertia).voidcad(float roll, float pitch, Vector upVector)Same asrotateCAD(roll, pitch, upVector, Graph.inertia).voidcad(float roll, float pitch, Vector upVector, float inertia)Defines an axis which the eye rotates around.static FloatcastToFloat(Object o)Castoto aFloat.static IntegercastToInt(Object o)Castoto anInteger.Vectorcenter()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()).voidclearTags()Removes all tags so thatnode(String)returnsnull.static voidclearTree()Same asfor(Node node : _leadingNodes()) detach(node).voidcloseContext()Ends the rendering process (seerender(Node)).Objectcontext()Returns the main renderer context.voiddisableTagging(Node node)Disables tagging the node.Vectordisplacement(Vector vector)Same asreturn displacement(vector, null).Vectordisplacement(Vector vector, Node node)Convertsvectordisplacement given in screen space to thenodecoordinate system.floatdistanceToBound(int index, Vector position)Returns the signed distance between pointpositionand planeindexin world units.voiddraw()Paint method which is called just after your main event loop.voidendHUD()Ends Heads Up Display (HUD).Nodeeye()Returns the associated eye.voidfit()voidfit(float duration)voidfit(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.voidfit(int x, int y, int width, int height, float duration)Smoothly moves the eye duringdurationmilliseconds so that the rectangular screen region defined byrectangle(pixel units, with origin in the upper left corner) fits the screen.voidfit(Node node)Convenience function that simply callsfit(node, 0).voidfit(Node node, float duration)Smoothly interpolates the eye on a interpolator path so that it goes tonode.voidfit(Vector corner1, Vector corner2)Moves the eye so that the world axis aligned box defined bycorner1andcorner2is entirely visible.voidfit(Vector corner1, Vector corner2, float duration)Smoothly moves the eye duringdurationmilliseconds so that the world axis aligned box defined bycorner1andcorner2is entirely visible.voidfitFOV()voidfitFOV(float duration)Rescales thefov()durationmilliseconds so that the ball defined bycenterandradiusis visible and fits the window.voidfocus()Same asfocus((String)null).voidfocus(String tag)Same asif (tag == null || node(tag) != null) focus(node(tag)).voidfocus(Node node)Focuses the node (use null for the world) with theeye().floatfov()Retrieves the scene field-of-view in radians.booleanhasFocus(int pixelX, int pixelY)Returns whether or not the scene has focus or not under the given pixel.booleanhasTag(String tag, Node node)booleanhasTag(Node node)Same asreturn hasTag(null, node).intheight()Returns height of the screen window.floathfov()Same asreturn type() == Type.PERSPECTIVE ? radians(eye().magnitude() * aspectRatio()) : eye().magnitude().voidinteract(Object... gesture)Same asinteract((String)null, gesture).voidinteract(String tag, Object... gesture)Same asif (tag == null || node(tag) != null) interact(node(tag), gesture).voidinteract(Node node, Object... gesture)Call thenode(or theeye()ifnodeis null) interact gesture parser function set either withNode.setInteraction(Consumer)orNode.setInteraction(BiConsumer).booleanis2D()booleanis3D()booleanisConeBackFacing(Vector vertex, ArrayList<Vector> normals)Returnstrueif the given cone is back-facing the eye andfalseotherwise.booleanisConeBackFacing(Vector vertex, Vector[] normals)Returnstrueif the given cone is back-facing the eye andfalseotherwise.booleanisConeBackFacing(Vector vertex, Vector axis, float angle)Returnstrueif the given cone is back-facing the eye andfalseotherwise.booleanisConeFrontFacing(Vector vertex, ArrayList<Vector> normals)Same asreturn !isConeBackFacing(vertex, normals).booleanisConeFrontFacing(Vector vertex, Vector[] normals)Same as!isConeBackFacing(vertex, normals).booleanisConeFrontFacing(Vector vertex, Vector axis, float angle)Same asreturn !isConeBackFacing(vertex, axis, angle).booleanisEye(Node node)Checks whether or not the given node is theeye().booleanisFaceBackFacing(Vector vertex, Vector normal)Returnstrueif the given face is back-facing the camera.booleanisFaceBackFacing(Vector a, Vector b, Vector c)Returnstrueif the given face is back-facing the eye.booleanisFaceFrontFacing(Vector vertex, Vector normal)Same asreturn !isFaceBackFacing(vertex, normal).booleanisFaceFrontFacing(Vector a, Vector b, Vector c)Same asreturn !isFaceBackFacing(a, b, c).static booleanisNumInstance(Object o)booleanisOffscreen()Returnstrueif this scene is off-screen andfalseotherwise.booleanisPointVisible(float x, float y, float z)Same asreturn isPointVisible(new Vector(x, y, z)).booleanisPointVisible(Vector point)Returnstrueifpointis visible (i.e, lies within the eye bounds) andfalseotherwise.booleanisTagged(Node node)Returnstrueif the node is currently being tagged andfalseotherwise.booleanisTagValid()Same asisTagValid(null).booleanisTagValid(String tag)Returnstrueif some node is tagged withtag(which may be {code null}) andfalseotherwise.longlastUpdate()Max betweenNode.lastUpdate()and_lastNonEyeUpdate().Vectorlocation(Vector pixel)Convenience function that simply returnslocation(pixel, null).Vectorlocation(Vector pixel, Node node)Returns thenodecoordinates ofpixel.voidlookAround(float deltaX, float deltaY)Same aslookAround(deltaX, deltaY, Graph.inertia).voidlookAround(float deltaX, float deltaY, float inertia)Look around (without translating the eye) according to angular displacementsdeltaXanddeltaYexpressed in radians.voidlookAt(Vector target)2D eyes simply callnode().setPosition(target.x(), target.y()).voidmoveForward(float delta)Same asmoveForward(delta, Graph.inertia).voidmoveForward(float delta, float inertia)Same astranslateEye(0, 0, delta / (zNear() - zFar())).VectorndcToScreenDisplacement(Vector vector)Convertsvectordisplacement from normalized device coordinates (NDC) to screen space.VectorndcToScreenLocation(Vector vector)Convertsvectorlocation from normalized device coordinates (NDC) to screen space.Nodenode()Same asreturn node(null).Nodenode(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.voidopenContext()Begins the rendering process (seerender(Node)).voidpixelToLine(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).floatpixelToSceneRatio(Vector position)Returns the pixel to scene (units) ratio atposition.voidpre()Paint method which is called just before your main event loop starts.Matrixprojection()Returns the cached projection matrix computed atopenContext().MatrixprojectionView()Returns the projection times view cached matrix computed atopenContext()}.MatrixprojectionViewInverse()Returns the projection times view inverse matrix.floatradius()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()).voidrandomize(Node node)Same asnode.randomize(center(), radius(), is3D()).NoderandomNode()Same asreturn Node.random(this).voidremoveTag()Same asremoveTag(null).voidremoveTag(String tag)voidrender()voidrender(Node subtree)CallsopenContext(), then renders the nodesubtree(or the whole tree whensubtreeisnull) onto thecontext()from theeye()viewpoint, and callscloseContext().voidresetBehavior(Node node)Resets the node custom behavior which is set withaddBehavior(Node, BiConsumer).VectorrightVector()Returns the normalized right vector of the eye, defined in the world coordinate system.floatsceneToPixelRatio(Vector position)Returns the ratio of scene (units) to pixel atposition.VectorscreenDisplacement(Vector vector)Same asreturn screenDisplacement(vector, null).VectorscreenDisplacement(Vector vector, Node node)Converts thenodevectordisplacement to screen space.VectorscreenLocation(Node node)Converts thenodeorigin location to screen space.VectorscreenLocation(Vector vector)Convertsvectorlocation from world to screen space.VectorscreenLocation(Vector vector, Node node)Convertsvectorlocation fromnodeto screen.VectorscreenToNDCDisplacement(Vector vector)Convertsvectordisplacement from screen space to normalized device coordinates (NDC).VectorscreenToNDCLocation(Vector vector)Convertsvectorlocation from screen space to normalized device coordinates (NDC).voidsetBoundingBall(Vector center, float radius)voidsetCenter(Vector center)Setscenter().voidsetEye(Node eye)Replaces the currenteye()witheye.voidsetFOV(float fov)Sets theeye()Node.worldMagnitude(), according tofov(field-of-view) which is expressed in radians.voidsetHeight(int height)Sets the graphheight()in pixels.voidsetHFOV(float hfov)voidsetRadius(float radius)Setsradius().voidsetType(Graph.Type type)Defines the graph_typeaccording to the projection of the scene.voidsetUpVector(Vector up)Convenience function that simply callssetUpVector(up, true).voidsetUpVector(Vector up, boolean noMove)Rotates the eye so that itsupVector()becomesup(defined in the world coordinate system).voidsetViewDirection(Vector direction)Rotates the eye so that itsviewDirection()isdirection(defined in the world coordinate system).voidsetWidth(int width)Sets the graphwidth()in pixels.voidsetZFar(Supplier<Float> zFar)Sets thezFar()computation routine.voidsetZNear(Supplier<Float> zNear)Sets thezNear()computation routine.voidshift(float dx, float dy, float dz)Same asshift(dx, dy, dz, Graph.inertia).voidshift(float dx, float dy, float dz, float inertia)Same asshift((String)null, dx, dy, dz, inertia).voidshift(String tag, float dx, float dy, float dz)Same asshift(tag, dx, dy, dz, Graph.inertia).voidshift(String tag, float dx, float dy, float dz, float inertia)Same asif (tag == null || node(tag) != null) shift(node(tag), dx, dy, dz, inertia).voidshift(Node node, float dx, float dy, float dz)Same asshift(node, dx, dy, dz, Graph.inertia).voidshift(Node node, float dx, float dy, float dz, float inertia)voidspin(int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)Same asspin(pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia).voidspin(int pixel1X, int pixel1Y, int pixel2X, int pixel2Y, float inertia)Same asspin((String)null, pixel1X, pixel1Y, pixel2X, pixel2Y, inertia).voidspin(String tag, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)Same asspin(tag, pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia).voidspin(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).voidspin(Node node, int pixel1X, int pixel1Y, int pixel2X, int pixel2Y)Same asspin(node, pixel1X, pixel1Y, pixel2X, pixel2Y, Graph.inertia).voidspin(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.voidtag(int pixelX, int pixelY)Same astag(null, pixelX, pixelY).voidtag(String tag, int pixelX, int pixelY)Same asupdateTag(String, int, int)but doesn't return immediately the tagged node.voidtag(String tag, Node node)voidtag(Node node)Same astag(null, node).voidtogglePerspective()Shifts the graph_typebetweenGraph.Type.PERSPECTIVEandGraph.Type.ORTHOGRAPHICwhile trying to keep thefov().booleantracks(Node node, int pixelX, int pixelY)Casts a ray at pixel position(pixelX, pixelY)and returnstrueif the ray picks thenodeandfalseotherwise.voidturn(float roll, float pitch, float yaw)Same asturn(roll, pitch, yaw, Graph.inertia).voidturn(float roll, float pitch, float yaw, float inertia)Same asturn((String)null, roll, pitch, yaw, inertia).voidturn(String tag, float roll, float pitch, float yaw)Same asturn(tag, roll, pitch, yaw, Graph.inertia).voidturn(String tag, float roll, float pitch, float yaw, float inertia)Same asif (tag == null || node(tag) != null) turn(node(tag), roll, pitch, yaw, inertia).voidturn(Node node, float roll, float pitch, float yaw)Same asturn(node, roll, pitch, yaw, Graph.inertia).voidturn(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,pitchandyawradians, resp., and according toinertiawhich should be in[0..1], 0 no inertia & 1 no friction.Graph.Typetype()Returns the graph type.voiduntag(Node node)Removes all tags pointing to thenode.NodeupdateTag(int pixelX, int pixelY)Same asreturn updateTag(null, null, pixelX, pixelY).NodeupdateTag(int pixelX, int pixelY, List<Node> nodeList)Same asreturn track(null, pixelX, pixelY, nodeList).NodeupdateTag(int pixelX, int pixelY, Node[] nodeArray)Same asreturn track(null, pixelX, pixelY, nodeArray).NodeupdateTag(String tag, int pixelX, int pixelY)Tags (withtagwhich may benull) the node innodes()picked with ray-casting at pixelpixelX, pixelYand returns it (seenode(String)).NodeupdateTag(String tag, int pixelX, int pixelY, List<Node> nodeList)Same asupdateTag(String, int, int, Node[])but using a node list instead of an array.NodeupdateTag(String tag, int pixelX, int pixelY, Node[] nodeArray)Tags (withtagwhich may benull) the node innodeArraypicked with ray-casting at pixelpixelX, pixelYand returns it (seenode(String)).NodeupdateTag(Node subtree, int pixelX, int pixelY)Same asreturn return updateTag(subtree, null, pixelX, pixelY).NodeupdateTag(Node subtree, String tag, int pixelX, int pixelY)Tags (withtagwhich may benull) the node in thesubtree(or the whole tree whensubtreeisnull) picked with ray-casting at pixelpixelX, pixelYand returns it (seenode(String)).VectorupVector()Returns the normalized up vector of the eye, defined in the world coordinate system.Matrixview()Returns the cached view matrix computed at_bind().VectorviewDirection()Returns the normalized view direction of the eye, defined in the world coordinate system.intwidth()Returns width of the screen window.floatzFar()Returns the far clipping plane distance used to compute theprojection()matrix.Supplier<Float>zFarSupplier()Retrieves the currentzFar()computation routine.floatzNear()Returns the near clipping plane distance used to compute theprojection()matrix.Supplier<Float>zNearSupplier()Retrieves the currentzNear()computation routine.voidzoom(float delta)Same aszoom(delta, Graph.inertia).voidzoom(float delta, float inertia)Same aszoom((String)null, delta, inertia).voidzoom(String tag, float delta)Same aszoom(tag, delta, Graph.inertia).voidzoom(String tag, float delta, float inertia)Same asif (tag == null || node(tag) != null) zoom(node(tag), delta, inertia).voidzoom(Node node, float delta)Same aszoom(node, delta, Graph.inertia).voidzoom(Node node, float delta, float inertia)Scales thenode(use null for the world) according todeltaandinertiawhich 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_typeaccording to the projection of the scene. EitherGraph.Type.PERSPECTIVE,Graph.Type.ORTHOGRAPHIC,Graph.Type.TWO_DorGraph.Type.CUSTOM.Graph.Type.PERSPECTIVEandGraph.Type.ORTHOGRAPHICuse 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_Dbehaves 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_typebetweenGraph.Type.PERSPECTIVEandGraph.Type.ORTHOGRAPHICwhile 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_typeisGraph.Type.ORTHOGRAPHICit will match the perspective projection obtained usingfovof 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.PERSPECTIVEand asMath.tan(fov / 2) * 2 * Math.abs(Vector.scalarProjection(Vector.subtract(eye().position(), center()), eye().zAxis())) / width()if the graph_typeisGraph.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_typeisGraph.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),zNearCoefficientis 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)
Returnstrueifpointis visible (i.e, lies within the eye bounds) andfalseotherwise.
-
ballVisibility
public Graph.Visibility ballVisibility(Vector center, float radius)
ReturnsGraph.Visibility.VISIBLE,Graph.Visibility.INVISIBLE, orGraph.Visibility.SEMIVISIBLE, depending whether the ball (of radiusradiusand 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 cornersp1andp2) 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 = 0wherea,bandcare 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 = 0where
a,b,canddare the 4 components of each vector, in that order.
-
distanceToBound
public float distanceToBound(int index, Vector position)Returns the signed distance between pointpositionand planeindexin world units. The distance is negative if the point lies in the planes's bounding halfspace, and positive otherwise.In 2D
indexis a value between0and3which respectively correspond to the left, right, top and bottom eye bounding planes.In 3D
indexis a value between0and5which 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 atpositionin the world coordinate system, will be projected with a length ofnpixels 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)
Returnstrueif the given face is back-facing the eye. Otherwise returnsfalse.Vertices must given in clockwise order if graph is not
leftHandedor 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)
Returnstrueif 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)
Returnstrueif the given cone is back-facing the eye andfalseotherwise.- 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)
Returnstrueif the given cone is back-facing the eye andfalseotherwise.- 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)
Returnstrueif the given cone is back-facing the eye andfalseotherwise.- 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
upand to the currentupVector()direction.Use this method in order to define the eye horizontal plane.
When
noMoveis 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
noMoveis 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 pointtargetdefined 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. Thedurationdefines the interpolation speed.
-
fit
public void fit()
-
fit
public void fit(float duration)
Moves the eye duringdurationmilliseconds 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()durationmilliseconds so that the ball defined bycenterandradiusis 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 duringdurationmilliseconds so that the world axis aligned box defined bycorner1andcorner2is entirely visible.
-
fit
public void fit(Vector corner1, Vector corner2)
Moves the eye so that the world axis aligned box defined bycorner1andcorner2is entirely visible.
-
fit
public void fit(int x, int y, int width, int height, float duration)Smoothly moves the eye duringdurationmilliseconds 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 thatrectangleis 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 thatrectangleis 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, whiledirectioncontains 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 (withtagwhich may benull) the node innodeArraypicked with ray-casting at pixelpixelX, pixelYand 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 (withtagwhich may benull) the node innodes()picked with ray-casting at pixelpixelX, pixelYand returns it (seenode(String)). May returnnullif 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 (withtagwhich may benull) the node in thesubtree(or the whole tree whensubtreeisnull) picked with ray-casting at pixelpixelX, pixelYand returns it (seenode(String)). May returnnullif 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 returnstrueif the ray picks thenodeandfalseotherwise. 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 benullif 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()
Returnstrueif this scene is off-screen andfalseotherwise.
-
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:
You may callscene.openContext(); worldCustomRender() scene.closeContext();render(Node)withinopenContextandcloseContext, beforeopenContextor 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 theNodedocumentation). Same asrender(null).
-
render
public void render(Node subtree)
CallsopenContext(), then renders the nodesubtree(or the whole tree whensubtreeisnull) 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 theNodedocumentation).
-
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.
Note that the graph culling condition may be set fromGraph 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(withtagwhich 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)
Returnstrueif some node is tagged withtag(which may be {code null}) andfalseotherwise.
-
isTagged
public boolean isTagged(Node node)
Returnstrueif the node is currently being tagged andfalseotherwise.
-
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)
Convertsvectorlocation 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)
Convertsvectorlocation 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 thenodeorigin location to screen space. Same asreturn screenLocation(new Vector(), node).
-
screenLocation
public Vector screenLocation(Vector vector)
Convertsvectorlocation 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)
Convertsvectorlocation fromnodeto 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 thenodecoordinates 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.zis not a linear interpolation betweenzNear()andzFar();pixel.z = zFar() / (zFar() - zNear()) * (1.0f - zNear() / z);wherezis the distance from the point you project to the camera, along theviewDirection().The result is expressed in the
nodecoordinate system. Whennodeisnull, the result is expressed in the world coordinates system. The possiblenodehierarchy (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)
Convertsvectordisplacement 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)
Convertsvectordisplacement 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)
Convertsvectordisplacement given in screen space to thenodecoordinate 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 thenodevectordisplacement 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()ifnodeis 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 todeltaandinertiawhich 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,pitchandyawradians, resp., and according toinertiawhich 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. Theinertiacontrols 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 withinertiawhich should be in[0..1], 0 no inertia & 1 no friction. Also rescales theeye()if the graph type isGraph.Type.ORTHOGRAPHICso 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 displacementsdeltaXanddeltaYexpressed in radians. The gesture strength is controlled withinertiawhich 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, theupVectorwill 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 withinertiawhich 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)
-
-