Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## codeanticode.proscene
Class PScene

    java.lang.Object
      codeanticode.proscene.PScene

All Implemented Interfaces:
  java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener, javax.swing.event.MouseInputListener

    public class PScene

extends java.lang.Object
implements java.awt.event.MouseWheelListener, javax.swing.event.MouseInputListener

A processing 3D interactive scene. A PScene provides a default interactivity for your scene through the mouse and keyboard in the hope that it should fit most user needs. For those users whose needs are not completely fulfill by default, proscene main interactivity mechanisms can easily be extended to fit them.

A PScene has a full reach PSCamera, an two means to manipulate objects: an `interactiveFrame()` single instance (which by default is null) and a `mouseGrabber()` pool.

To use a PScene, you can instantiate a PScene object directly or you can implement your own derived PScene class. You also need to call `defaultKeyBindings()` from your PApplet.keyPressed() function. That's all there is to it.

If you instantiate your own PScene object you should implement your `PApplet.draw()` as usual, but enclosing your drawing calls between `beginDraw()` and `endDraw()`. Thus, for instance, if the following code define the body of your `PApplet.draw()`:

`scene.beginDraw();`
`processing drawing routines...`
`scene.endDraw();`

you would obtain full interactivity to manipulate your scene "for free".

If you derive from PScene, you should implement `scene()` which defines the objects in your scene. Then all you have to do is to call `scene()` from `PApplet.draw()`, e.g., `public void draw() {scene.draw();}`

See the examples BasicUse and AlternativeUse for an illustration of both techniques.

Nested Class Summary
`static class` | `PScene.MouseAction` This enum defines mouse actions to be binded to the mouse.

Constructor Summary
`PScene(processing.core.PApplet p)` All viewer parameters (display flags, scene parameters, associated objects...) are set to their default values.

Method Summary
`float` | `aspectRatio()` Returns the `PApplet.width` to `PApplet.height` aspect ratio of the processing display window.
`boolean` | `axisIsDrawn()` Returns `true` if axis is currently being drawn and `false` otherwise.
`void` | `beginDraw()` Sets the processing camera parameters from `camera()` and displays axis and grid accordingly to user flags
`PSCamera` | `camera()` Returns the associated PSCamera, never `null`.
`boolean` | `cameraIsInRevolveMode()` Tests if the `camera()` is in revolve mode (also known as arc-ball).
`PSCamera.Type` | `cameraType()` Returns the current `camera()` type.
`static void` | `cone(float r, float h)` Same as `cone(12, 0, 0, r, h);`
`void` | `cone(int det, float r, float h)` Same as `cone(det, 0, 0, r, h);`
`static void` | `cone(int detail, float x, float y, float r, float h)` Places a cone with it's base centered at `(x,y)`, height `h` in positive `z`, radius `r`.
`static void` | `cylinder(float w, float h)` Draws a cylinder of width `w` and height `h`.
`void` | `defaultKeyBindings()` Associates interactivity actions to default keys.
`void` | `draw()` Main paint method.
`static void` | `drawArrow(float length)` Simply calls `drawArrow(length, 0.05f * length)`
`static void` | `drawArrow(float length, float radius)` Draws a 3D arrow along the positive Z axis.
`static void` | `drawArrow(processing.core.PVector from, processing.core.PVector to, float radius)` Draws a 3D arrow between the 3D point `from` and the 3D point `to`, both defined in the current ModelView coordinates system.
`static void` | `drawAxis()` Convenience function that simply calls `drawAxis(1.0f)`
`static void` | `drawAxis(float length)` Draws an axis of length `length` which origin correspond to that of the world coordinate system.
`static void` | `drawGrid()` Convenience function that simply calls `drawGrid(1.0f, 10)`
`static void` | `drawGrid(float size)` Convenience function that simply calls `drawGrid(size, 10)`
`static void` | `drawGrid(float size, int nbSubdivisions)` Draws a grid in the XY plane, centered on (0,0,0) (defined in the current coordinate system).
`static void` | `drawGrid(int nbSubdivisions)` Convenience function that simply calls `drawGrid(1.0f, nbSubdivisions)`
`boolean` | `drawIsConstrained()` Returns `true` if drawn is currently being constrained and `false` otherwise.
`void` | `endDraw()` Displays some visual hints, such the `help()` text.
`boolean` | `gridIsDrawn()` Returns `true` if grid is currently being drawn and `false` otherwise.
`void` | `help()` Displays the help text describing how interactivity actions are binded to the keyboard and mouse.
`boolean` | `helpIsDrawn()` Returns `true` if the `help()` is currently being drawn and `false` otherwise.
`void` | `init()` This method is called before the first drawing and should be overloaded to initialize stuff not initialized in `PApplet.setup()`.
`PSInteractiveFrame` | `interactiveFrame()` Returns the PSInteractiveFrame associated to this PScene.
`boolean` | `interactiveFrameIsDrawn()` Returns `true` if axis is currently being drawn and `false` otherwise.
`void` | `mouseClicked(java.awt.event.MouseEvent event)` Implementation of the MouseMotionListener interface method.
`void` | `mouseDragged(java.awt.event.MouseEvent event)` Implementation of the MouseMotionListener interface method.
`void` | `mouseEntered(java.awt.event.MouseEvent event)` Implementation of the MouseMotionListener interface method.
`void` | `mouseExited(java.awt.event.MouseEvent event)` Implementation of the MouseMotionListener interface method.
`PSMouseGrabber` | `mouseGrabber()` Returns the current PSMouseGrabber, or `null` if none currently grabs mouse events.
`void` | `mouseMoved(java.awt.event.MouseEvent event)` Implementation of the MouseMotionListener interface method.
`void` | `mousePressed(java.awt.event.MouseEvent event)` Implementation of the MouseMotionListener interface method.
`void` | `mouseReleased(java.awt.event.MouseEvent event)` Implementation of the MouseMotionListener interface method.
`void` | `mouseWheelMoved(java.awt.event.MouseWheelEvent event)` Implementation of the MouseWheelListener interface method.
`void` | `scene()` The method that actually defines the scene.
`processing.core.PVector` | `sceneCenter()` Returns the scene center.
`float` | `sceneRadius()` Returns the scene radius.
`void` | `setAxisIsDrawn()` Convenience function that simply calls `setAxisIsDrawn(true)`
`void` | `setAxisIsDrawn(boolean draw)` Sets the display of the axis according to `draw`
`void` | `setCamera(PSCamera camera)` Replaces the current `camera()` with `camera`
`void` | `setCameraType(PSCamera.Type type)` Sets the `camera()` type.
`void` | `setDrawInteractiveFrame()`
`void` | `setDrawInteractiveFrame(boolean draw)` Sets the interactivity to the PScene `interactiveFrame()` instance according to `draw`
`void` | `setDrawWithConstraint(boolean wConstraint)` Constrain frame displacements according to `wConstraint`
`void` | `setGridIsDrawn()` Convenience function that simply calls `setGridIsDrawn(true)`
`void` | `setGridIsDrawn(boolean draw)` Sets the display of the grid according to `draw`
`void` | `setHelpIsDrawn()` Convenience function that simply calls `setHelpIsDrawn(true)`
`void` | `setHelpIsDrawn(boolean draw)` Sets the display of the `help()` according to `draw`
`void` | `setInteractiveFrame(PSInteractiveFrame frame)` Sets `frame` as the PSInteractiveFrame associated to this PScene.
`void` | `setSceneBoundingBox(processing.core.PVector min, processing.core.PVector max)` Sets the `sceneCenter()` and `sceneRadius()` of the PScene from the `min` and `max` PVectors.
`void` | `setSceneCenter(processing.core.PVector center)` Sets the `sceneCenter()` of the PScene.
`void` | `setSceneRadius(float radius)` Sets the `sceneRadius()` of the PScene.
`void` | `showEntireScene()` Convenience wrapper function that simply calls `camera().showEntireScene()`
`void` | `toggleAxisIsDrawn()` Toggles the state of `axisIsDrawn()`.
`void` | `toggleCameraMode()` Toggles the `camera()` mode between arc-ball and fly.
`void` | `toggleCameraType()` Toggles the `camera()` type between PERSPECTIVE and ORTHOGRAPHIC.
`void` | `toggleDrawInteractiveFrame()` Toggles the `interactiveFrame()` interactivity on and off.
`void` | `toggleDrawWithConstraint()` Toggles the draw with constraint on and off.
`void` | `toggleGridIsDrawn()` Toggles the state of `gridIsDrawn()`.
`void` | `toggleHelpIsDrawn()` Toggles the state of the `helpIsDrawn()`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PScene

    public PScene(processing.core.PApplet p)

  All viewer parameters (display flags, scene parameters, associated objects...) are set to their default values. See the associated documentation.

Method Detail

### camera

    public PSCamera camera()

  Returns the associated PSCamera, never `null`.

### setCamera

    public void setCamera(PSCamera camera)

  Replaces the current `camera()` with `camera`

### interactiveFrame

    public PSInteractiveFrame interactiveFrame()

  Returns the PSInteractiveFrame associated to this PScene. It could be null if there's no PSInteractiveFrame associated to this PScene.

  See Also:
    `setInteractiveFrame(PSInteractiveFrame)`

### setInteractiveFrame

    public void setInteractiveFrame(PSInteractiveFrame frame)

  Sets `frame` as the PSInteractiveFrame associated to this PScene.

  See Also:
    `interactiveFrame()`

### mouseGrabber

    public PSMouseGrabber mouseGrabber()

  Returns the current PSMouseGrabber, or `null` if none currently grabs mouse events.

  When `proscene.PSMouseGrabber#grabsMouse()`, the different mouse events are sent to it instead of their usual targets (`camera()` or `interactiveFrame()`).

### toggleAxisIsDrawn

    public void toggleAxisIsDrawn()

  Toggles the state of `axisIsDrawn()`.

  See Also:
    `axisIsDrawn()`, `setAxisIsDrawn(boolean)`

### toggleGridIsDrawn

    public void toggleGridIsDrawn()

  Toggles the state of `gridIsDrawn()`.

  See Also:
    `setGridIsDrawn(boolean)`

### toggleHelpIsDrawn

    public void toggleHelpIsDrawn()

  Toggles the state of the `helpIsDrawn()`

  See Also:
    `setHelpIsDrawn()`

### cameraIsInRevolveMode

    public boolean cameraIsInRevolveMode()

  Tests if the `camera()` is in revolve mode (also known as arc-ball). The other `camera()` mode is fly. `toggleCameraMode()`

### toggleCameraMode

    public void toggleCameraMode()

  Toggles the `camera()` mode between arc-ball and fly.

### toggleCameraType

    public void toggleCameraType()

  Toggles the `camera()` type between PERSPECTIVE and ORTHOGRAPHIC.

### toggleDrawInteractiveFrame

    public void toggleDrawInteractiveFrame()

  Toggles the `interactiveFrame()` interactivity on and off.

### toggleDrawWithConstraint

    public void toggleDrawWithConstraint()

  Toggles the draw with constraint on and off.

### defaultKeyBindings

    public void defaultKeyBindings()

  Associates interactivity actions to default keys.

### help

    public void help()

  Displays the help text describing how interactivity actions are binded to the keyboard and mouse.

### init

    public void init()

  This method is called before the first drawing and should be overloaded to initialize stuff not initialized in `PApplet.setup()`. The default implementation is empty.

  Typical usage include `camera()` initialization (`showEntireScene()`) and PScene state setup (`setAxisIsDrawn(boolean)`, `setGridIsDrawn(boolean)` `setHelpIsDrawn(boolean)`).

### draw

    public void draw()

  Main paint method.

  Calls the following methods, in that order:
  `beginDraw()`: Sets processing camera parameters from the PSCamera and displays axis and grid accordingly to user flags.
  `scene()`: Main drawing method that could be overloaded.
  `endDraw()`: Displays some visual hints, such the `help()` text.

### beginDraw

    public void beginDraw()

  Sets the processing camera parameters from `camera()` and displays axis and grid accordingly to user flags

### scene

    public void scene()

  The method that actually defines the scene.

  If you build a class that inherits from PScene, this is the method you should overload, but no if you instantiate your own PScene object (in this case you should just overload `PApplet.draw()` to define your scene).

  The processing camera set in `beginDraw()` converts from the world to the camera coordinate systems. Vertices given in `scene()` can then be considered as being given in the world coordinate system. The camera is moved in this world using the mouse. This representation is much more intuitive than a camera-centric system (which for instance is the standard in OpenGL).

### endDraw

    public void endDraw()

  Displays some visual hints, such the `help()` text.

### sceneRadius

    public float sceneRadius()

  Returns the scene radius.

  Convenience wrapper function that simply calls `camera().sceneRadius()`

  See Also:
    `setSceneRadius(float)`, `sceneCenter()`

### sceneCenter

    public processing.core.PVector sceneCenter()

  Returns the scene center.

  Convenience wrapper function that simply calls `camera().sceneCenter()`

  See Also:
    `{@link #sceneRadius()}`

### setSceneRadius

    public void setSceneRadius(float radius)

  Sets the `sceneRadius()` of the PScene.

  Convenience wrapper function that simply calls `camera().setSceneRadius(radius)`

  See Also:
    `setSceneCenter(PVector)`

### setSceneCenter

    public void setSceneCenter(processing.core.PVector center)

  Sets the `sceneCenter()` of the PScene.

  Convenience wrapper function that simply calls ``

  See Also:
    `setSceneRadius(float)`

### setSceneBoundingBox

    public void setSceneBoundingBox(processing.core.PVector min,
                                    processing.core.PVector max)

  Sets the `sceneCenter()` and `sceneRadius()` of the PScene from the `min` and `max` PVectors.

  Convenience wrapper function that simply calls `camera().setSceneBoundingBox(min,max)`

  See Also:
    `setSceneRadius(float)`, `setSceneCenter(PVector)`

### showEntireScene

    public void showEntireScene()

  Convenience wrapper function that simply calls `camera().showEntireScene()`

  See Also:
    `proscene.PSCamera#showEntireScene()`

### cameraType

    public final PSCamera.Type cameraType()

  Returns the current `camera()` type.

### setCameraType

    public void setCameraType(PSCamera.Type type)

  Sets the `camera()` type.

### aspectRatio

    public float aspectRatio()

  Returns the `PApplet.width` to `PApplet.height` aspect ratio of the processing display window.

### axisIsDrawn

    public boolean axisIsDrawn()

  Returns `true` if axis is currently being drawn and `false` otherwise.

### gridIsDrawn

    public boolean gridIsDrawn()

  Returns `true` if grid is currently being drawn and `false` otherwise.

### helpIsDrawn

    public boolean helpIsDrawn()

  Returns `true` if the `help()` is currently being drawn and `false` otherwise.

### interactiveFrameIsDrawn

    public boolean interactiveFrameIsDrawn()

  Returns `true` if axis is currently being drawn and `false` otherwise.

### drawIsConstrained

    public boolean drawIsConstrained()

  Returns `true` if drawn is currently being constrained and `false` otherwise.

### setAxisIsDrawn

    public void setAxisIsDrawn()

  Convenience function that simply calls `setAxisIsDrawn(true)`

### setAxisIsDrawn

    public void setAxisIsDrawn(boolean draw)

  Sets the display of the axis according to `draw`

### setGridIsDrawn

    public void setGridIsDrawn()

  Convenience function that simply calls `setGridIsDrawn(true)`

### setGridIsDrawn

    public void setGridIsDrawn(boolean draw)

  Sets the display of the grid according to `draw`

### setHelpIsDrawn

    public void setHelpIsDrawn()

  Convenience function that simply calls `setHelpIsDrawn(true)`

### setHelpIsDrawn

    public void setHelpIsDrawn(boolean draw)

  Sets the display of the `help()` according to `draw`

### setDrawInteractiveFrame

    public void setDrawInteractiveFrame()

### setDrawInteractiveFrame

    public void setDrawInteractiveFrame(boolean draw)

  Sets the interactivity to the PScene `interactiveFrame()` instance according to `draw`

### setDrawWithConstraint

    public void setDrawWithConstraint(boolean wConstraint)

  Constrain frame displacements according to `wConstraint`

### drawAxis

    public static void drawAxis()

  Convenience function that simply calls `drawAxis(1.0f)`

### drawAxis

    public static void drawAxis(float length)

  Draws an axis of length `length` which origin correspond to that of the world coordinate system.

  See Also:
    `drawGrid(float, int)`

### drawArrow

    public static void drawArrow(float length)

  Simply calls `drawArrow(length, 0.05f * length)`

  See Also:
    `drawArrow(float, float)`

### drawArrow

    public static void drawArrow(float length,
                                 float radius)

  Draws a 3D arrow along the positive Z axis.

  `length` and `radius` define its geometry.

  Use `drawArrow(PVector, PVector, float)` to place the arrow in 3D.

### drawArrow

    public static void drawArrow(processing.core.PVector from,
                                 processing.core.PVector to,
                                 float radius)

  Draws a 3D arrow between the 3D point `from` and the 3D point `to`, both defined in the current ModelView coordinates system.

  See Also:
    `drawArrow(float, float)`

### drawGrid

    public static void drawGrid()

  Convenience function that simply calls `drawGrid(1.0f, 10)`

  See Also:
    `drawGrid(float, int)`

### drawGrid

    public static void drawGrid(float size)

  Convenience function that simply calls `drawGrid(size, 10)`

  See Also:
    `drawGrid(float, int)`

### drawGrid

    public static void drawGrid(int nbSubdivisions)

  Convenience function that simply calls `drawGrid(1.0f, nbSubdivisions)`

  See Also:
    `drawGrid(float, int)`

### drawGrid

    public static void drawGrid(float size,
                                int nbSubdivisions)

  Draws a grid in the XY plane, centered on (0,0,0) (defined in the current coordinate system).

  `size` (processing scene units) and `nbSubdivisions` define its geometry.

  See Also:
    `drawAxis(float)`

### mouseMoved

    public void mouseMoved(java.awt.event.MouseEvent event)

  Implementation of the MouseMotionListener interface method.

  Sets the PSCamera from processing camera parameters.

  `setMouseGrabber(PSMouseGrabber)` to the PSMouseGrabber that grabs the mouse (or to `null` if none of them grab it).

  Specified by:
    `mouseMoved` in interface `java.awt.event.MouseMotionListener`

### mousePressed

    public void mousePressed(java.awt.event.MouseEvent event)

  Implementation of the MouseMotionListener interface method.

  When the user clicks on the mouse: If a `mouseGrabber()` is defined, `proscene.PSMouseGrabber#mousePressEvent(MouseEvent, PSCamera)` is called. Otherwise, the `camera()` or the `interactiveFrame()` interprets the mouse displacements, depending on mouse bindings.

  Specified by:
    `mousePressed` in interface `java.awt.event.MouseListener`
  See Also:
    `mouseDragged(MouseEvent)`

### mouseDragged

    public void mouseDragged(java.awt.event.MouseEvent event)

  Implementation of the MouseMotionListener interface method.

  Mouse drag event is sent to the `mouseGrabber()` (if any) or to the `camera()` or the `interactiveFrame()`, depending on mouse bindings.

  Specified by:
    `mouseDragged` in interface `java.awt.event.MouseMotionListener`
  See Also:
    `mouseMoved(MouseEvent)`

### mouseReleased

    public void mouseReleased(java.awt.event.MouseEvent event)

  Implementation of the MouseMotionListener interface method.

  Calls the `mouseGrabber()`, `camera()` or `interactiveFrame()` mouseReleaseEvent method.

  Specified by:
    `mouseReleased` in interface `java.awt.event.MouseListener`

### mouseClicked

    public void mouseClicked(java.awt.event.MouseEvent event)

  Implementation of the MouseMotionListener interface method.

  Implements mouse double click events: left button aligns scene, middle button shows entire scene, and right button centers scene.

  Specified by:
    `mouseClicked` in interface `java.awt.event.MouseListener`

### mouseEntered

    public void mouseEntered(java.awt.event.MouseEvent event)

  Implementation of the MouseMotionListener interface method.

  Current implementation is empty.

  Specified by:
    `mouseEntered` in interface `java.awt.event.MouseListener`

### mouseExited

    public void mouseExited(java.awt.event.MouseEvent event)

  Implementation of the MouseMotionListener interface method.

  Current implementation is empty.

  Specified by:
    `mouseExited` in interface `java.awt.event.MouseListener`

### mouseWheelMoved

    public void mouseWheelMoved(java.awt.event.MouseWheelEvent event)

  Implementation of the MouseWheelListener interface method.

  Calls the `mouseGrabber()`, `camera()` or `interactiveFrame()` mouseWheelEvent method.

  Specified by:
    `mouseWheelMoved` in interface `java.awt.event.MouseWheelListener`

### cylinder

    public static void cylinder(float w,
                                float h)

  Draws a cylinder of width `w` and height `h`.

  Code adapted from http://www.processingblogs.org/category/processing-java/

### cone

    public void cone(int det,
                     float r,
                     float h)

  Same as `cone(det, 0, 0, r, h);`

  See Also:
    `cone(int, float, float, float, float)`

### cone

    public static void cone(float r,
                            float h)

  Same as `cone(12, 0, 0, r, h);`

  See Also:
    `cone(int, float, float, float, float)`

### cone

    public static void cone(int detail,
                            float x,
                            float y,
                            float r,
                            float h)

  Places a cone with it's base centered at `(x,y)`, height `h` in positive `z`, radius `r`.

  The code of this function was taken from http://processinghacks.com/hacks:cone Thanks to Tom Carden

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

processing library glgraphics by Andres Colubri. (c) 2008