Class Viewport
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
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 JPanel
implements SceneChangeListener, MouseListener, MouseMotionListener, MouseWheelListener
Viewport
is an JPanel
that uses a set of RenderPass
es 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.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
-
Field Summary
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
afterSceneChange
(Node newScene) Called after the scene changes.void
beforeSceneChange
(Node oldScene) Called before the scene changes.int
double
javax.vecmath.Vector3d
In OpenGL camera space +Y is up and in screen space +Y is down so invert the Y value.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.javax.vecmath.Point2d
int
int
double
getRayThroughPoint
(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) double
boolean
boolean
boolean
void
void
void
void
void
void
void
void
void
void
void
void
void
Save the viewport pass state to thePreferences
.void
setActiveCamera
(Camera camera) void
setActiveToolIndex
(int index) Set the active tool by index.void
setFsaaSamples
(Integer value) void
setHardwareAccelerated
(boolean selected) void
setOrbitChangeFactor
(double amount) void
setOriginShift
(boolean b) void
setUserMovementScale
(double scale) Set the scale of user movement.void
setVerticalSync
(boolean selected) void
updateAllNodes
(double dt) Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
Methods 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, update
Methods 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, validate
Methods 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:
addNotify
in classJComponent
-
removeNotify
public void removeNotify()- Overrides:
removeNotify
in classJComponent
-
renderAllPasses
public void renderAllPasses() -
updateAllNodes
public void updateAllNodes(double dt) -
mouseClicked
- Specified by:
mouseClicked
in interfaceMouseListener
-
mousePressed
- Specified by:
mousePressed
in interfaceMouseListener
-
mouseReleased
- Specified by:
mouseReleased
in interfaceMouseListener
-
mouseEntered
- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
- Specified by:
mouseExited
in interfaceMouseListener
-
mouseDragged
- Specified by:
mouseDragged
in interfaceMouseMotionListener
-
mouseWheelMoved
- Specified by:
mouseWheelMoved
in interfaceMouseWheelListener
-
mouseMoved
- Specified by:
mouseMoved
in 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:SceneChangeListener
Called before the scene changes. This is a good time to unregister listeners.- Specified by:
beforeSceneChange
in interfaceSceneChangeListener
- Parameters:
oldScene
- the scene that is about to be replaced.
-
afterSceneChange
Description copied from interface:SceneChangeListener
Called after the scene changes. This is a good time to register listeners.- Specified by:
afterSceneChange
in 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
-