hmi.environment
Class GraphicsDemoEnvironment

java.lang.Object
  extended by hmi.environment.GraphicsDemoEnvironment
All Implemented Interfaces:
GLRenderObject, KeyListener, EventListener
Direct Known Subclasses:
PhysicalDemoEnvironment

public class GraphicsDemoEnvironment
extends Object
implements GLRenderObject, KeyListener

Graphical demo helper class, contains a key navigator, 3D environment with checkerboard ground, play button and some useful function hooks for subclasses. REMARKS & CHANGES BY DENNIS - i want to be able to add new graphical elements (VGLNodes) to the scene that are NOT added to the root VGLNode. Rather, they are stored in a list of many objects that need to be rendered. WHY? because I sometimes want to be able to do some attrib pushing/popping around each render call - i want to have a list of debugvisualisation objects too -- so we can activate and deactivate rendering for all debug visualsiations, online, with one boolean setting - for both the 'normal' and 'debug' render objects, we need to take into account that when they are added online, i.e. after the applicatino has already been running for some time, we sti;ll need to initialise them (glInit). - instead of the stupid hard coded openglstate, i add a preGlInit and a preGlRender. (also stupid, but probably more flexible & useful.) - animationRootJoint becomes vjWorldAnimationRoot (maar moet bewaard als doorlus variabele? - renderroot becomes vglSceneRenderRoot (maar moet bewaard als doorlus variabele? - initgraphics wordt initrender en initgraphicscene (maar is bewaard als deprecated) - clock becomes renderClock (there will be more! - after init, you need to call StartAll separately (which starts clocks and such) - setupUI becomes initUI

Author:
Herwin van Welbergen, Dennis Reidsma

Nested Class Summary
(package private)  class GraphicsDemoEnvironment.DebugCheckListener
           
(package private)  class GraphicsDemoEnvironment.MyRenderclockCallback
          This object is responsible for doing extra things on the render tick, such as navigation.
(package private)  class GraphicsDemoEnvironment.PlayListener
           
(package private)  class GraphicsDemoEnvironment.ResetListener
           
 
Field Summary
protected  Background background
          This simple colored background is always available, and will always be rendered just *after* the glPreRender and BEFORE the elements in the visualisations list
(package private)  GLTextureWow color_buf_tex
          Used to copy the rendered area into
 boolean debugJOGL
          If true, the JOGL renderer will be set to use the DEBUG GL
private  ArrayList<VGLNode> debugVisualisations
          Debugvisulaisations are stored in a separate array - this allows us to add some setting 'allowDebugRender' in the future.
private  ArrayList<VGLNode> debugVisualisationsUninitialized
          Unitialized debug visulaisations -- see also visualisationsUnititialized.
(package private)  GLTextureWow depth_buf_tex
          Used to copy the depth of the rendered area into
(package private)  float dx
           
(package private)  float dy
           
(package private)  float dz
           
 boolean enableFSAA
          enableFSAA
 double fovyFar
          NEar and Far planes
 double fovyNear
          NEar and Far planes
 String frameTitle
          Title of the frame.
 int FSAA_samples
          FSAA
 boolean fullscreen
          fullscreen mode
protected  javax.media.opengl.GLCanvas glCanvas
          The 3D enabled Canvas, inside the JFrame
protected  NavigationControl glNavControl
          The glNavControl operates on the vjNavigationNode and its children, and allows for keyboard based navigation through the scene
protected  VJointMoveControl glObjectControl
          The glObjectControl operates on an as of yet unspecified vjoint, and allows for keyboard based manipulation of one object
protected  ArrayList<VGLNode> hiddenVisualisations
          Visualisations that have been (GL)initialized already, but are currently hidden (so moved from visualisations to this list)
protected  JFrame jframe
          The JFrame for the application
 boolean laptop
          Set to true if you are running on a laptop and the program crashes, or the mesh looks exploded.
protected  SimpleLight light0
          several simple openGL lights that are always available
protected  SimpleLight light1
           
protected  SimpleLight light2
           
protected  SimpleLight light3
           
protected  SimpleLight light4
           
protected  float[] lightPos0
          This is the position of light0..
protected  float[] lightPos1
           
protected  float[] lightPos2
           
protected  float[] lightPos3
           
protected  float[] lightPos4
           
private static org.slf4j.Logger logger
           
 int numStencilBits
          Number of stencil bits
 boolean render
           
 SystemClock renderClock
          The Clock that triggers rendering.
 boolean renderDebugVisualisations
          If true, debug visualisations will be rendered
protected  JOGLRenderer renderer
          The module that renders the 3D scene.
protected  List<Runnable> renderRunners
           
protected  Object shutdownSync
          this sync is used because we do not want to dispose the frame in the middle of an openGL render action
protected  JToolBar toolBar
           
 boolean useVsync
          denotes whether vsync should be used or not.
protected  VGLNode vglSceneRenderRoot
          This node is available as the top-level VGLNode for the scene -- the VGLNode for vjSceneRenderRoot.
protected  ArrayList<VGLNode> visualisations
          The shapes, meshes, materials, etc that are to be rendered are contained in this list of VGLNodes.
protected  ArrayList<VGLNode> visualisationsUninitialized
          When a new visulaisation object is added through addVisualisation, we need to be sure that glInit is called on it before calling glRender on it.
protected  VJoint vjNavigationNode
          The vjWorldRenderRoot is added to vjNavigationNode; the navigation controls operate on the vjNavigationNode.
protected  VJoint vjSceneRenderRoot
          At the top of the VJoint hierarchy, we find the vjSceneRenderRoot.
protected  VJoint vjWorldAnimationRoot
          The vjWorldAnimationRoot defines the world, in which the VJoints of all objects that must be animated reside.
protected  VJoint vjWorldRenderRoot
          The vjWorldRenderRoot is the render node of the World.
(package private)  float[] wowTransformMatrix
           
 boolean wowvx
          Set to true to use the WOWVX screen capabilities
(package private)  byte[] wowvx_header_data
          The header is a magic sequence of pixels (1 stands for blue, 0 stands for black) that fills the first half of the first line.
(package private)  GLTextureWow wowvx_header_tex
          Contains the header that should be drawn at the top left of the screen to make the wowvx switch to 3D mode.
 
Constructor Summary
GraphicsDemoEnvironment()
          Constructor.
 
Method Summary
 void addDebugVisualisation(VGLNode viz)
          Add a VGLNode to the list of debugvisualisations.
protected  void addRenderRunner(Runnable r)
          Add a runner to the render thread.
 void addVisualisation(VGLNode viz)
          Add a VGLNode to the list of visualisations.
protected  void close()
          close button pressed, extend or override in subclass
(package private)  void convertBufferToWowVX(GLRenderContext glc)
          Convert the region in the bottom left to 2d + depth format.
protected  void disposeFrame()
          close button pressed, extend or override in subclass
protected  void exit()
           
 JFrame getFrame()
           
 ImageIcon getGeneralImageIcon(String imageName, String altText)
           
 ImageIcon getImageIcon(String imageName, String altText)
           
 VJoint getWorldAnimationRoot()
          get vjWorldAnimationRoot.
 VJoint getWorldRenderRoot()
          get vjWorldAnimationRoot.
 void glInit(GLRenderContext glc)
          Run the init for some default stuff (glpreInit, can be overridden), followed by the init for everything that is in the list of uninitialized objects
 void glPreInit(GLRenderContext glc)
          Do some basic initialization prior to initializing the scene: smoothing, cull_face, etc
 void glPreRender(GLRenderContext glc)
          Do some basic rendering calls prior to initializing the scene: It clears the necessary OpenGL buffers (color, depth, ..) and calls glInit on any uninitialized (debug)visualisations
 void glRender(GLRenderContext glc)
          do the main rendering step.
 boolean hasVisualisation(VGLNode viz)
          Checks if a visualization is already in the scene (returns true on hidden VGLNodes too)
 void init()
          The init method has been moved out of the constructor, because we sometimes want to override it with additional initialisation BEFORE calling the superclass init() method
protected  void initGraphics()
          For backwards compatibility -- calls initRender & initGraphicScene
protected  void initGraphicScene()
          initialize the actual graphic scene (floor, lights, objects, etc).
protected  void initQuickSettings()
          Override this method to change the quick-settings for your application (see top of source file)
protected  void initRender()
          initialize the renderer
protected  void initToolbar()
          Initializes the toolbar.
protected  void initUI()
          Make frame, make canvas, make toolbars & buttons...
protected  void initVisualGround()
          you can override this one to get rid of the visual ground... called from initGraphicScene()
protected  void initVJointStructure()
          Setup the main scene structure with the navigation node, the node to be animated, the central nodes to render, etc.
 boolean isVisualisationVisible(VGLNode viz)
           
 void keyPressed(KeyEvent e)
          KeyListener callback: exit if the escape key was pressed
 void keyReleased(KeyEvent e)
           
 void keyTyped(KeyEvent e)
           
protected  void navigate(double currentTime)
          Do the navigation for this time step
protected  void play()
          Play button pressed, override in subclass
protected  void prepareClose()
          prepare to close on a renderrunner
protected  void prepareDispose()
          prepare to close on a renderrunner
 void prepareReset()
          prepare to reset on a renderrunner
 void processAnimationResultForRender(GLRenderContext glc)
          This method makes sure that all relevant information from the vjWorldAnimationRoot is processed.
 void removeDebugVisualisation(VGLNode viz)
           
 void removeVisualisation(VGLNode viz)
           
protected  void renderTime(double currentTime)
           
protected  void reset()
          Reset button pressed, override in subclass
 void setFullScreen(boolean full)
          This method may be changed to use the stuff described here: http://java.sun.com/docs/books/tutorial/extra/fullscreen/exclusivemode.html because this gives us more control over the display...
 void setupMediaButton(ImageIcon icon, ActionListener listener, String toolTipText, String altText, JButton button)
           
 void setupMediaButton(String imageName, ActionListener listener, String toolTipText, String altText, JButton button)
           
protected  void setupUI()
          Deprecated. 
protected  void setupVJointStructure()
          Deprecated. 
 void setVisualisationVisible(VGLNode viz, boolean enabled)
          Show/hide a VGLNode
 void startAll()
          start the frame, canvas, clocks and render loops.
 void startClocks()
          start render clock...
 void toggleDebugViz()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shutdownSync

protected Object shutdownSync
this sync is used because we do not want to dispose the frame in the middle of an openGL render action


logger

private static org.slf4j.Logger logger

laptop

public boolean laptop
Set to true if you are running on a laptop and the program crashes, or the mesh looks exploded. Possibly set through constructor.


frameTitle

public String frameTitle
Title of the frame. Possibly set through constructor.


useVsync

public boolean useVsync
denotes whether vsync should be used or not. If set to true, render speed is synchronised to the framerate of the display; otherwise, the frame title may display the actual frame rate in its title.


debugJOGL

public boolean debugJOGL
If true, the JOGL renderer will be set to use the DEBUG GL


renderDebugVisualisations

public volatile boolean renderDebugVisualisations
If true, debug visualisations will be rendered


render

public volatile boolean render

numStencilBits

public int numStencilBits
Number of stencil bits


FSAA_samples

public int FSAA_samples
FSAA


fovyNear

public double fovyNear
NEar and Far planes


fovyFar

public double fovyFar
NEar and Far planes


enableFSAA

public boolean enableFSAA
enableFSAA


fullscreen

public boolean fullscreen
fullscreen mode


wowvx

public boolean wowvx
Set to true to use the WOWVX screen capabilities


jframe

protected JFrame jframe
The JFrame for the application


toolBar

protected JToolBar toolBar

glCanvas

protected javax.media.opengl.GLCanvas glCanvas
The 3D enabled Canvas, inside the JFrame


renderer

protected JOGLRenderer renderer
The module that renders the 3D scene. Here, we use JOGL


renderClock

public SystemClock renderClock
The Clock that triggers rendering.


renderRunners

protected List<Runnable> renderRunners

vjWorldAnimationRoot

protected VJoint vjWorldAnimationRoot
The vjWorldAnimationRoot defines the world, in which the VJoints of all objects that must be animated reside. One would animate these VJoints; the environment then takes care that these manipulations are transferred to the render nodes. see YYY for info about synchronisation!!!


vjWorldRenderRoot

protected VJoint vjWorldRenderRoot
The vjWorldRenderRoot is the render node of the World. It contains the vjoints of objects that must be rendered. VJoints added here are affected by navigation interaction.


vjNavigationNode

protected VJoint vjNavigationNode
The vjWorldRenderRoot is added to vjNavigationNode; the navigation controls operate on the vjNavigationNode.


vjSceneRenderRoot

protected VJoint vjSceneRenderRoot
At the top of the VJoint hierarchy, we find the vjSceneRenderRoot. This root is unaffected by the navigation controls. HUD elements will have to be added to this vjSceneRenderRoot.


glNavControl

protected NavigationControl glNavControl
The glNavControl operates on the vjNavigationNode and its children, and allows for keyboard based navigation through the scene


glObjectControl

protected VJointMoveControl glObjectControl
The glObjectControl operates on an as of yet unspecified vjoint, and allows for keyboard based manipulation of one object


vglSceneRenderRoot

protected VGLNode vglSceneRenderRoot
This node is available as the top-level VGLNode for the scene -- the VGLNode for vjSceneRenderRoot. Note: if you add children to this node after it was initialised, you may get problems because the children were NOT initlaized yet with glInit(glc).


visualisations

protected ArrayList<VGLNode> visualisations
The shapes, meshes, materials, etc that are to be rendered are contained in this list of VGLNodes. They will be rendered in the order in which they are stored in this list. Actually, one might create *one* VGLNode (renderScene...) and add the others as children to it. However, we do it like this because on some machines, we need to restore all rendering properties between rendering two different objects, to avoid java opengl crashes... New visualsiation objects are added using the method addVisualisation() By default, vglSceneRenderRoot is also added to this list. Note: access to this variable must be synchronized on itself.


hiddenVisualisations

protected ArrayList<VGLNode> hiddenVisualisations
Visualisations that have been (GL)initialized already, but are currently hidden (so moved from visualisations to this list)


visualisationsUninitialized

protected ArrayList<VGLNode> visualisationsUninitialized
When a new visulaisation object is added through addVisualisation, we need to be sure that glInit is called on it before calling glRender on it. To this end, they are stored first in this array of uninitialized vglNodes. Note: access to this variable must be synchronized on itself.


debugVisualisations

private ArrayList<VGLNode> debugVisualisations
Debugvisulaisations are stored in a separate array - this allows us to add some setting 'allowDebugRender' in the future. Note: access to this variable must be synchronized on itself.


debugVisualisationsUninitialized

private ArrayList<VGLNode> debugVisualisationsUninitialized
Unitialized debug visulaisations -- see also visualisationsUnititialized. Note: access to this variable must be synchronized on itself.


background

protected Background background
This simple colored background is always available, and will always be rendered just *after* the glPreRender and BEFORE the elements in the visualisations list


light0

protected SimpleLight light0
several simple openGL lights that are always available


light1

protected SimpleLight light1

light2

protected SimpleLight light2

light3

protected SimpleLight light3

light4

protected SimpleLight light4

lightPos0

protected float[] lightPos0
This is the position of light0.. Point source


lightPos1

protected float[] lightPos1

lightPos2

protected float[] lightPos2

lightPos3

protected float[] lightPos3

lightPos4

protected float[] lightPos4

color_buf_tex

GLTextureWow color_buf_tex
Used to copy the rendered area into


depth_buf_tex

GLTextureWow depth_buf_tex
Used to copy the depth of the rendered area into


wowvx_header_tex

GLTextureWow wowvx_header_tex
Contains the header that should be drawn at the top left of the screen to make the wowvx switch to 3D mode.


wowvx_header_data

byte[] wowvx_header_data
The header is a magic sequence of pixels (1 stands for blue, 0 stands for black) that fills the first half of the first line. This header was obtained by taking a screen grab of the 3D Combobulator app. I should note that the grabs I examined did not conform to the (rather unclear) header specs.


wowTransformMatrix

float[] wowTransformMatrix

dx

float dx

dy

float dy

dz

float dz
Constructor Detail

GraphicsDemoEnvironment

public GraphicsDemoEnvironment()
Constructor. Does not really do anything. TO initialize all elements, call init(). To start clocks and such, call StartAll subsequently

Method Detail

getWorldAnimationRoot

public VJoint getWorldAnimationRoot()
get vjWorldAnimationRoot. BE VERY CAREFUL MANIPULATING THIS VJOINT! Add stuff to it for which you want to animate directly...


addRenderRunner

protected void addRenderRunner(Runnable r)
Add a runner to the render thread. These runners is executed as a last step in renderTime. Here the proper synchronisation is in place to do 'stuff' with render joints or the render clock (e.g. reset it). The Runnable itself may not call addRenderRunner or in any other way tinker with physicsRunners.


getWorldRenderRoot

public VJoint getWorldRenderRoot()
get vjWorldAnimationRoot. BE VERY CAREFUL MANIPULATING THIS VJOINT!


init

public void init()
The init method has been moved out of the constructor, because we sometimes want to override it with additional initialisation BEFORE calling the superclass init() method


initQuickSettings

protected void initQuickSettings()
Override this method to change the quick-settings for your application (see top of source file)


setupVJointStructure

@Deprecated
protected void setupVJointStructure()
Deprecated. 


initVJointStructure

protected void initVJointStructure()
Setup the main scene structure with the navigation node, the node to be animated, the central nodes to render, etc. Documented somewhere how this structure works?


setupUI

@Deprecated
protected void setupUI()
Deprecated. 


initUI

protected void initUI()
Make frame, make canvas, make toolbars & buttons...


initToolbar

protected void initToolbar()
Initializes the toolbar. Subclasses can overwrite this method for custom toolbars, or no toolbar (to do that, just set toolBar to null).


setFullScreen

public void setFullScreen(boolean full)
This method may be changed to use the stuff described here: http://java.sun.com/docs/books/tutorial/extra/fullscreen/exclusivemode.html because this gives us more control over the display...


toggleDebugViz

public void toggleDebugViz()

initGraphics

protected void initGraphics()
For backwards compatibility -- calls initRender & initGraphicScene


initRender

protected void initRender()
initialize the renderer


initGraphicScene

protected void initGraphicScene()
initialize the actual graphic scene (floor, lights, objects, etc). Pre: worldrendernode exists; ... etc ?


initVisualGround

protected void initVisualGround()
you can override this one to get rid of the visual ground... called from initGraphicScene()


startAll

public void startAll()
start the frame, canvas, clocks and render loops.


startClocks

public void startClocks()
start render clock... Override this if other clocks need to be started... such as physics clocks and voice clocks...


play

protected void play()
Play button pressed, override in subclass


prepareReset

public void prepareReset()
prepare to reset on a renderrunner


prepareClose

protected void prepareClose()
prepare to close on a renderrunner


prepareDispose

protected void prepareDispose()
prepare to close on a renderrunner


reset

protected void reset()
Reset button pressed, override in subclass


close

protected void close()
close button pressed, extend or override in subclass


disposeFrame

protected void disposeFrame()
                     throws InterruptedException,
                            InvocationTargetException
close button pressed, extend or override in subclass

Throws:
InvocationTargetException
InterruptedException

exit

protected void exit()

addVisualisation

public void addVisualisation(VGLNode viz)
Add a VGLNode to the list of visualisations. This method will add the VGLNode first to a list of nodes waiting to be initialized.


hasVisualisation

public boolean hasVisualisation(VGLNode viz)
Checks if a visualization is already in the scene (returns true on hidden VGLNodes too)


isVisualisationVisible

public boolean isVisualisationVisible(VGLNode viz)

setVisualisationVisible

public void setVisualisationVisible(VGLNode viz,
                                    boolean enabled)
Show/hide a VGLNode


removeVisualisation

public void removeVisualisation(VGLNode viz)

addDebugVisualisation

public void addDebugVisualisation(VGLNode viz)
Add a VGLNode to the list of debugvisualisations. This method will add the VGLNode first to a list of nodes waiting to be initialized.


removeDebugVisualisation

public void removeDebugVisualisation(VGLNode viz)

glPreInit

public void glPreInit(GLRenderContext glc)
Do some basic initialization prior to initializing the scene: smoothing, cull_face, etc


glInit

public void glInit(GLRenderContext glc)
Run the init for some default stuff (glpreInit, can be overridden), followed by the init for everything that is in the list of uninitialized objects

Specified by:
glInit in interface GLRenderObject

glPreRender

public void glPreRender(GLRenderContext glc)
Do some basic rendering calls prior to initializing the scene: It clears the necessary OpenGL buffers (color, depth, ..) and calls glInit on any uninitialized (debug)visualisations


processAnimationResultForRender

public void processAnimationResultForRender(GLRenderContext glc)
This method makes sure that all relevant information from the vjWorldAnimationRoot is processed. THIS METHOD MUST BE CALLED SYNCRHONISED ON THE ANIMATIONSYNCH!!!! to adapt the meshes. In essence, this means calling calculatematrices and/or deform() on the right objects...


glRender

public void glRender(GLRenderContext glc)
do the main rendering step. Consists of calling prerender, then processAnimationResultForRender, then rendering all visualsaitions

Specified by:
glRender in interface GLRenderObject

renderTime

protected void renderTime(double currentTime)

navigate

protected void navigate(double currentTime)
Do the navigation for this time step


convertBufferToWowVX

void convertBufferToWowVX(GLRenderContext glc)
Convert the region in the bottom left to 2d + depth format. This means copying the colour buffer to the left half of the screen, and the depth buffer to the right half. Note that all even lines are "don't care", so we do not use smoothing when copying.


keyPressed

public void keyPressed(KeyEvent e)
KeyListener callback: exit if the escape key was pressed

Specified by:
keyPressed in interface KeyListener

keyTyped

public void keyTyped(KeyEvent e)
Specified by:
keyTyped in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)
Specified by:
keyReleased in interface KeyListener

getFrame

public JFrame getFrame()
Returns:
the jframe

getImageIcon

public ImageIcon getImageIcon(String imageName,
                              String altText)

getGeneralImageIcon

public ImageIcon getGeneralImageIcon(String imageName,
                                     String altText)

setupMediaButton

public void setupMediaButton(ImageIcon icon,
                             ActionListener listener,
                             String toolTipText,
                             String altText,
                             JButton button)

setupMediaButton

public void setupMediaButton(String imageName,
                             ActionListener listener,
                             String toolTipText,
                             String altText,
                             JButton button)