Class Viewport
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.marginallyclever.ro3.apps.App
com.marginallyclever.ro3.apps.viewport.Viewport
- All Implemented Interfaces:
SceneChangeListener,MouseListener,MouseMotionListener,MouseWheelListener,ImageObserver,MenuContainer,Serializable,EventListener,Accessible
- Direct Known Subclasses:
OpenGLPanel
public class Viewport
extends App
implements SceneChangeListener, MouseListener, MouseMotionListener, MouseWheelListener
Viewport is an JPanel that uses a set of RenderPasses to draw the
Registry.getScene() from the perspective of the active Camera. Mouse actions in the panel
can be used to manipulate the active camera.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior -
Field Summary
FieldsFields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidafterSceneChange(Node newScene) Called after the scene changes.voidbeforeSceneChange(Node oldScene) Called before the scene changes.intdoublejavax.vecmath.Vector3dIn OpenGL camera space +Y is up and in screen space +Y is down so invert the Y value.javax.vecmath.Vector3dgetCursorAsNormalized(double x, double y) In OpenGL camera space +Y is up and in screen space +Y is down so invert the Y value.javax.vecmath.Point2dintintdoublegetRayThroughPoint(Camera camera, double normalizedX, double normalizedY) Return the ray, in world space, that starts at the camera and passes through this viewport at (x,y) in the current projection.getRayThroughPointUntransformed(Camera camera, double normalizedX, double normalizedY) Return the ray, in camera space, that starts at the origin and passes through this viewport at (x,y) in the current projection.getTool(int index) doublebooleanbooleanbooleanbooleanbooleanvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidSave the viewport pass state to thePreferences.voidsetActiveCamera(Camera camera) voidsetActiveToolIndex(int index) Set the active tool by index.voidsetDebugGL(boolean debugGL) voidsetFsaaSamples(Integer value) voidsetHardwareAccelerated(boolean selected) voidsetOrbitChangeFactor(double amount) voidsetOriginShift(boolean b) voidsetTraceGL(boolean traceGL) voidsetUserMovementScale(double scale) Set the scale of user movement.voidsetVerticalSync(boolean selected) voidupdateAllNodes(double dt) Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validateMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
renderPasses
-
-
Constructor Details
-
Viewport
public Viewport() -
Viewport
-
-
Method Details
-
saveRenderPassState
public void saveRenderPassState()Save the viewport pass state to thePreferences. -
addNotify
public void addNotify()- Overrides:
addNotifyin classJComponent
-
removeNotify
public void removeNotify()- Overrides:
removeNotifyin classJComponent
-
renderAllPasses
public void renderAllPasses() -
updateAllNodes
public void updateAllNodes(double dt) -
mouseClicked
- Specified by:
mouseClickedin interfaceMouseListener
-
mousePressed
- Specified by:
mousePressedin interfaceMouseListener
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener
-
mouseEntered
- Specified by:
mouseEnteredin interfaceMouseListener
-
mouseExited
- Specified by:
mouseExitedin interfaceMouseListener
-
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener
-
mouseWheelMoved
- Specified by:
mouseWheelMovedin interfaceMouseWheelListener
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener
-
getOrbitChangeFactor
public double getOrbitChangeFactor() -
setOrbitChangeFactor
public void setOrbitChangeFactor(double amount) - Parameters:
amount- a value greater than one.
-
getRayThroughPoint
Return the ray, in world space, that starts at the camera and passes through this viewport at (x,y) in the current projection. x,y should be normalized screen coordinates adjusted for the vertical flip.
Remember that in OpenGL the camera -Z=forward, +X=right, +Y=up
- Parameters:
normalizedX- the cursor position in screen coordinates [-1,1]normalizedY- the cursor position in screen coordinates [-1,1]- Returns:
- the ray coming through the viewport in the current projection.
-
getRayThroughPointUntransformed
Return the ray, in camera space, that starts at the origin and passes through this viewport at (x,y) in the current projection. x,y should be normalized screen coordinates adjusted for the vertical flip.
Remember that in OpenGL the camera -Z=forward, +X=right, +Y=up
- Parameters:
normalizedX- the cursor position in screen coordinates [-1,1]normalizedY- the cursor position in screen coordinates [-1,1]- Returns:
- the ray coming through the viewport in the current projection.
-
getCursorAsNormalized
public javax.vecmath.Vector3d getCursorAsNormalized()In OpenGL camera space +Y is up and in screen space +Y is down so invert the Y value.- Returns:
- the cursor position as (-1...1,-1...1,0).
-
getCursorAsNormalized
public javax.vecmath.Vector3d getCursorAsNormalized(double x, double y) In OpenGL camera space +Y is up and in screen space +Y is down so invert the Y value.- Returns:
- the cursor position as (-1...1,-1...1,0).
-
getCursorPosition
public javax.vecmath.Point2d getCursorPosition() -
getAspectRatio
public double getAspectRatio() -
getNumTools
public int getNumTools() -
setActiveToolIndex
public void setActiveToolIndex(int index) Set the active tool by index.- Parameters:
index- the index of the tool to activate.
-
getActiveToolIndex
public int getActiveToolIndex() -
getTool
-
getUserMovementScale
public double getUserMovementScale() -
setUserMovementScale
public void setUserMovementScale(double scale) Set the scale of user movement. This is used to scale the mouse movement to the camera movement.- Parameters:
scale- a value greater than zero.
-
beforeSceneChange
Description copied from interface:SceneChangeListenerCalled before the scene changes. This is a good time to unregister listeners.- Specified by:
beforeSceneChangein interfaceSceneChangeListener- Parameters:
oldScene- the scene that is about to be replaced.
-
afterSceneChange
Description copied from interface:SceneChangeListenerCalled after the scene changes. This is a good time to register listeners.- Specified by:
afterSceneChangein interfaceSceneChangeListener- Parameters:
newScene- the scene that has just been added.
-
getActiveCamera
-
setActiveCamera
-
isHardwareAccelerated
public boolean isHardwareAccelerated() -
setHardwareAccelerated
public void setHardwareAccelerated(boolean selected) -
isVerticalSync
public boolean isVerticalSync() -
setVerticalSync
public void setVerticalSync(boolean selected) -
getFsaaSamples
public int getFsaaSamples() -
setFsaaSamples
-
savePrefs
public void savePrefs() -
isOriginShift
public boolean isOriginShift() -
setOriginShift
public void setOriginShift(boolean b) -
addToolChangeListener
-
removeToolChangeListener
-
isDebugGL
public boolean isDebugGL() -
setDebugGL
public void setDebugGL(boolean debugGL) -
isTraceGL
public boolean isTraceGL() -
setTraceGL
public void setTraceGL(boolean traceGL)
-