Package eu.svjatoslav.sixth.e3d.gui
Class ViewPanel
java.lang.Object
java.awt.Component
java.awt.Canvas
eu.svjatoslav.sixth.e3d.gui.ViewPanel
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
AWT Canvas that provides a 3D rendering surface with built-in camera navigation.
ViewPanel is the primary entry point for embedding the Sixth 3D engine into
a Java application. It manages the render loop, maintains a scene graph
(ShapeCollection), and handles user input for camera navigation.
Uses BufferStrategy for efficient page-flipping and tear-free rendering.
Quick start - creating a 3D view in a window:
// Option 1: Use ViewFrame (creates a maximized JFrame for you)
ViewFrame frame = new ViewFrame();
ViewPanel viewPanel = frame.getViewPanel();
// Option 2: Embed ViewPanel in your own window
JFrame frame = new JFrame("My 3D App");
ViewPanel viewPanel = new ViewPanel();
frame.add(viewPanel);
frame.setSize(800, 600);
frame.setVisible(true);
// Add shapes to the scene
ShapeCollection scene = viewPanel.getRootShapeCollection();
scene.addShape(new WireframeCube(
new Point3D(0, 0, 200), 50,
new LineAppearance(5, Color.GREEN)
));
// Position the camera
viewPanel.getCamera().setLocation(new Point3D(0, 0, -100));
// Listen for frame updates (e.g., for animations)
viewPanel.addFrameListener((panel, deltaMs) -> {
// Called before each frame. Return true to force repaint.
return false;
});
Architecture:
- A background render thread continuously generates frames at the target FPS
- The engine intelligently skips rendering when no visual changes are detected
FrameListeners are notified before each potential frame, enabling animations- Mouse/keyboard input is managed by
InputManager - Keyboard focus is managed by
KeyboardFocusStack
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvasNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsFields inherited from class java.awt.Component
accessibleContext, 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 TypeMethodDescriptionvoidaddFrameListener(FrameListener listener) Registers a listener that will be notified before each frame render.Returns the camera representing the viewer's position and orientation.Returns the debug log buffer for this view panel.Returns the developer tools for this view panel.Returns the input manager handling mouse and keyboard events for this view.Returns the keyboard focus stack, which manages which component receives keyboard input.Returns the global lighting manager for the scene.Returns the current rendering context for the active frame.Returns the root shape collection (scene graph).voidvoidremoveFrameListener(FrameListener frameListener) Removes a previously registered frame listener.voidCalling these methods tells 3D engine that current 3D view needs to be repainted on first opportunity.voidsetFrameRate(int frameRate) Set target frames per second rate for this view.voidShows the developer tools panel, toggling it if already open.voidstop()Stops rendering of this view.voidMethods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategyMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
-
Field Details
-
backgroundColor
The background color of the view.
-
-
Constructor Details
-
ViewPanel
public ViewPanel()Creates a new view panel with default settings.
-
-
Method Details
-
getCamera
Returns the camera representing the viewer's position and orientation.- Returns:
- the camera
-
getKeyboardFocusStack
Returns the keyboard focus stack, which manages which component receives keyboard input.- Returns:
- the keyboard focus stack
-
getRootShapeCollection
Returns the root shape collection (scene graph). Add your 3D shapes here to make them visible in the view.viewPanel.getRootShapeCollection().addShape(myShape);- Returns:
- the root shape collection
-
getInputManager
Returns the input manager handling mouse and keyboard events for this view.- Returns:
- the input manager
-
addFrameListener
Registers a listener that will be notified before each frame render. Listeners can trigger repaints by returningtruefromFrameListener.onFrame(eu.svjatoslav.sixth.e3d.gui.ViewPanel, int).- Parameters:
listener- the listener to add- See Also:
-
getPreferredSize
- Overrides:
getPreferredSizein classComponent
-
getMinimumSize
- Overrides:
getMinimumSizein classComponent
-
getMaximumSize
- Overrides:
getMaximumSizein classComponent
-
getRenderingContext
Returns the current rendering context for the active frame.- Returns:
- the rendering context, or null if no frame is being rendered
-
getDeveloperTools
Returns the developer tools for this view panel.- Returns:
- the developer tools
-
getDebugLogBuffer
Returns the debug log buffer for this view panel.- Returns:
- the debug log buffer
-
getLightingManager
Returns the global lighting manager for the scene. Add light sources here to illuminate the world.- Returns:
- the lighting manager
-
showDeveloperToolsPanel
public void showDeveloperToolsPanel()Shows the developer tools panel, toggling it if already open. Called when F12 is pressed. -
paint
-
update
-
repaintDuringNextViewUpdate
public void repaintDuringNextViewUpdate()Calling these methods tells 3D engine that current 3D view needs to be repainted on first opportunity. -
setFrameRate
public void setFrameRate(int frameRate) Set target frames per second rate for this view. Target FPS can be changed at runtime. Use 0 or negative value for unlimited FPS (max performance mode for benchmarking).- Parameters:
frameRate- target frames per second rate for this view.
-
stop
public void stop()Stops rendering of this view. -
removeFrameListener
Removes a previously registered frame listener.- Parameters:
frameListener- the listener to remove
-