render
Class RenderJPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--render.RenderJPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class RenderJPanel
extends javax.swing.JPanel
implements java.lang.Runnable

Provides an applet interface to the Renderer.

It also implements control features dealing with mouse and keyboard interaction.

Extend this class to create an interactive web applet.

See Also:
Renderer, Serialized Form

Nested Class Summary
protected  class RenderJPanel.KeyHandler
           
protected  class RenderJPanel.MouseHandler
           
 
Field Summary
protected  double currentTime
          Holds current system time.
protected  double elapsed
          Measures time elapsed from initialization.
 boolean enableLod
          Enables level of detail computation for meshes.
protected  double frameRate
          Contains current frame rate of the renderer
protected  int H
          Image height
protected  java.awt.Image im
          Image framebuffer
protected  boolean isDamage
          Flag to force a renderer refresh when true.
protected  int mx
          Current mouse position
protected  int my
          Current mouse position
 double phi
          Euler angle for camera positioning (vertical view rotation).
 Renderer renderer
          Renderer object
 boolean showFPS
          Flag that determines whether to display current frame rate.
protected  double startTime
          Holds actual time of initialization.
 double theta
          Euler angle for camera positioning (horizontal view rotation).
protected  int W
          Image width
 Geometry world
          root of the scene Geometry
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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
RenderJPanel()
           
 
Method Summary
 void addLight(double x, double y, double z, double r, double g, double b)
          Adds light source with direction (x, y, z) & color (r, g, b).
 void animate(double time)
          Override this to animate.
 void damage()
          Forces a refresh of the renderer.
 void identity()
          Sets current matrix to the identity matrix.
 void init()
          Initializes the applet and internal variables.
 void initialize()
          Override this to initialize the application program.
 Matrix m()
          Returns the matrix at the top of the stack.
 void paintComponent(java.awt.Graphics g)
          Updates the image buffer to output device.
 void pop()
          Pops the top matrix from the stack.
 int pull(Geometry s, double x0, double x1, double x2, double y0, double y1, double y2, double z0, double z1, double z2)
          Deforms a geometric shape according to the beginning, middle, and end parameters in each dimension.
 void push()
          Pushes a copy of the top matrix onto the stack.
 void renderFrame()
           
 void rotateX(double t)
          Rotates the top matrix around the X axis by angle t (radians).
 void rotateY(double t)
          Rotates the top matrix around the Y axis by angle t (radians).
 void rotateZ(double t)
          Rotates the top matrix around the Z axis by angle t (radians).
 void run()
          Renderer thread.
 void scale(double x, double y, double z)
          Scales the top matrix by x, y, z in their respective dimensions.
 void setBgColor(double r, double g, double b)
          Sets the background color ( RGB values range: 0..1).
 void setFL(double value)
          Sets the camera's focal length.
 void setFOV(double value)
          Sets the field of view value.
 void setOpaque(boolean opaque)
           
 void start()
          Starts the renderer thread.
 void stop()
          Stops the renderer thread.
 void transform(Geometry s)
          Applies the top transformation matrix to Geometry s.
 void translate(double[] v)
          Translates the top matrix by vector v.
 void translate(double x, double y, double z)
          Translates the top matrix by x, y, z.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

renderer

public Renderer renderer
Renderer object


world

public Geometry world
root of the scene Geometry


showFPS

public boolean showFPS
Flag that determines whether to display current frame rate.


enableLod

public boolean enableLod
Enables level of detail computation for meshes.


theta

public double theta
Euler angle for camera positioning (horizontal view rotation).


phi

public double phi
Euler angle for camera positioning (vertical view rotation).


mx

protected int mx
Current mouse position


my

protected int my
Current mouse position


W

protected int W
Image width


H

protected int H
Image height


im

protected java.awt.Image im
Image framebuffer


isDamage

protected boolean isDamage
Flag to force a renderer refresh when true.


startTime

protected double startTime
Holds actual time of initialization.


currentTime

protected double currentTime
Holds current system time. Used to compute time elapsed between frames.


elapsed

protected double elapsed
Measures time elapsed from initialization.


frameRate

protected double frameRate
Contains current frame rate of the renderer

Constructor Detail

RenderJPanel

public RenderJPanel()
Method Detail

animate

public void animate(double time)
Override this to animate.

Parameters:
time - system time

damage

public void damage()
Forces a refresh of the renderer. Sets isDamage true.


setFOV

public void setFOV(double value)
Sets the field of view value.

Parameters:
value -
See Also:
Renderer.setFOV(double value)

setFL

public void setFL(double value)
Sets the camera's focal length.

Parameters:
value - focal length
See Also:
Renderer.setFL(double value)

setBgColor

public void setBgColor(double r,
                       double g,
                       double b)
Sets the background color ( RGB values range: 0..1).

Parameters:
r - red component 0..1
g - green component 0..1
b - blue component 0..1

setOpaque

public void setOpaque(boolean opaque)
Overrides:
setOpaque in class javax.swing.JComponent

addLight

public void addLight(double x,
                     double y,
                     double z,
                     double r,
                     double g,
                     double b)
Adds light source with direction (x, y, z) & color (r, g, b).

Arguments x,y,z indicate light direction. Arguments r,g,b indicate light direction.

See Also:
Renderer.addLight(double x,double y,double z, double r,double g,double b)

identity

public void identity()
Sets current matrix to the identity matrix.


m

public Matrix m()
Returns the matrix at the top of the stack.

Returns:
the top matrix on the stack

pop

public void pop()
Pops the top matrix from the stack.


push

public void push()
Pushes a copy of the top matrix onto the stack.


rotateX

public void rotateX(double t)
Rotates the top matrix around the X axis by angle t (radians).

Parameters:
t - angle in radians

rotateY

public void rotateY(double t)
Rotates the top matrix around the Y axis by angle t (radians).

Parameters:
t - angle in radians

rotateZ

public void rotateZ(double t)
Rotates the top matrix around the Z axis by angle t (radians).

Parameters:
t - angle in radians

scale

public void scale(double x,
                  double y,
                  double z)
Scales the top matrix by x, y, z in their respective dimensions.

Parameters:
x - x scale factor
y - y scale factor
z - z scale factor

transform

public void transform(Geometry s)
Applies the top transformation matrix to Geometry s.

Parameters:
s - Geometry object

translate

public void translate(double[] v)
Translates the top matrix by vector v.

Parameters:
v - an array of three doubles representing translations in the x,y,z directions.

translate

public void translate(double x,
                      double y,
                      double z)
Translates the top matrix by x, y, z.

Parameters:
x - - translation in the x direction.
y - - translation in the y direction.
z - - translation in the z direction.

pull

public int pull(Geometry s,
                double x0,
                double x1,
                double x2,
                double y0,
                double y1,
                double y2,
                double z0,
                double z1,
                double z2)
Deforms a geometric shape according to the beginning, middle, and end parameters in each dimension. For each dimesion the three parameters indicate the amount of deformation at each position.

0 - beginning, 1 - middle, 2 - end. To indicate infinity (a constant transformation) set two adjacent parameters to the same value. Setting all three parameters to the same value transforms the shape geometry consistently across the entire axis of the parameters.

Parameters:
s - shape object to be deformed
x0 - location of beginning of deformation along the x axis
x1 - location of beginning of deformation along the x axis
x2 - location of beginning of deformation along the x axis
y0 - location of beginning of deformation along the y axis
y1 - location of beginning of deformation along the y axis
y2 - location of beginning of deformation along the y axis
z0 - location of beginning of deformation along the z axis
z1 - location of beginning of deformation along the z axis
z2 - location of beginning of deformation along the z axis
Returns:
1 if pull operation was successful, 0 otherwise
See Also:
Geometry.pull(render.Matrix, double, double, double, double, double, double, double, double, double)

init

public void init()
Initializes the applet and internal variables. To initialize components of the application program use initialize().

See Also:
initialize()

initialize

public void initialize()
Override this to initialize the application program.


start

public void start()
Starts the renderer thread.


stop

public void stop()
Stops the renderer thread.


run

public void run()
Renderer thread.

Specified by:
run in interface java.lang.Runnable

renderFrame

public void renderFrame()

paintComponent

public void paintComponent(java.awt.Graphics g)
Updates the image buffer to output device.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - Specifies the output device.