hmi.environment
Class PhysicalDemoEnvironment

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

public class PhysicalDemoEnvironment
extends GraphicsDemoEnvironment

Extends GraphicsDemoEnvironment with a physical world and physical simulation. Adds, by default, the checkerboard ground as physical representation, and a throwable ball, to the scene.

Author:
Herwin van Welbergen, Dennis Reidsma

Nested Class Summary
(package private)  class PhysicalDemoEnvironment.CollisionCheckListener
           
(package private)  class PhysicalDemoEnvironment.PhysicsCheckListener
           
(package private)  class PhysicalDemoEnvironment.PhysicsClockListener
          Links physics clock to the physicsTime method in which the simulation should be updated
(package private) static class PhysicalDemoEnvironment.Sleeper
          Added as a hack to enforce high precision timing
(package private)  class PhysicalDemoEnvironment.ThrowBallListener
          position the physical sphere, and give it a speed; the graphical sphere will follow the physical one...
 
Nested classes/interfaces inherited from class hmi.environment.GraphicsDemoEnvironment
GraphicsDemoEnvironment.DebugCheckListener, GraphicsDemoEnvironment.MyRenderclockCallback, GraphicsDemoEnvironment.PlayListener, GraphicsDemoEnvironment.ResetListener
 
Field Summary
protected  org.odejava.collision.JavaCollision collision
          To calculate collisions and their effecting forces/impulses.
 boolean collisionEnabled
          Simulate collisions yes or no?
protected  float[] g
          Direction and strength of gravity in this environment
protected  org.odejava.JointGroup glueJointGroup
          all joints that are glued to the floor?
protected  org.odejava.GeomPlane groundGeom
          By default, the physical world contains this physical representation of the Visual ground
private  org.slf4j.Logger logger
           
protected  OdeRigidBody phsphere
          By default, the scene contains this hard coded physical sphere, which also has a graphical and Animation representation.
protected  org.odejava.World phworld
          The Physical World
protected  SystemClock physicsClock
          The clock on which steps in the physical simulation are taken
 long physicsLoopFrequency
          physics is calculated on about 2 times render speed: you want every render tick to surely have latest physics results in it, or at most one animatino step (half a render frame time) behind time...
protected  List<Runnable> physicsRunners
           
protected  double prevTime
          last time stamp for which physics was simulated.
 boolean runphysics
          If set to false, no physics are calculated
protected  org.odejava.HashSpace space
          Collison space?
private static float[] sphereAmbient
          color settings for the default phsphere object
protected  VJoint sphereAnimationJoint
          The animation joint of the phsphere
private static float[] sphereDiffuse
          color settings for the default phsphere object
private static float[] sphereEmission
          color settings for the default phsphere object
protected  VJoint sphereRenderJoint
          The render vjoint of the phsphere
private static float[] sphereSpecular
          color settings for the default phsphere object
protected  float timeStep
          Stepsize for physics simulation in seconds.
 
Fields inherited from class hmi.environment.GraphicsDemoEnvironment
background, color_buf_tex, debugJOGL, depth_buf_tex, dx, dy, dz, enableFSAA, fovyFar, fovyNear, frameTitle, FSAA_samples, fullscreen, glCanvas, glNavControl, glObjectControl, hiddenVisualisations, jframe, laptop, light0, light1, light2, light3, light4, lightPos0, lightPos1, lightPos2, lightPos3, lightPos4, numStencilBits, render, renderClock, renderDebugVisualisations, renderer, renderRunners, shutdownSync, toolBar, useVsync, vglSceneRenderRoot, visualisations, visualisationsUninitialized, vjNavigationNode, vjSceneRenderRoot, vjWorldAnimationRoot, vjWorldRenderRoot, wowTransformMatrix, wowvx, wowvx_header_data, wowvx_header_tex
 
Constructor Summary
PhysicalDemoEnvironment()
           
 
Method Summary
 void addPhysicsRunner(Runnable r)
          Add a runner to the physics thread.
private  void cleanUpOdeObjects()
           
 void close()
          Clean up native ODE objects.
protected  void disposeFrame()
          close button pressed, extend or override in subclass
 void glueFeetToFloor(PhysicalHumanoid pHuman)
          Connects the ankle segments to the world with a fixed, unmovable joint, to prevent the feet from slipping
 void init()
          Init the world physics before initializing the rest of the system; after initialization, set up the physics of the default sphere (graphics of it was already done in initGraphicScene) and of the ground
protected  void initGraphicScene()
          Add the graphical representation for the phsphere to the graphical scene
protected  void initGraphicSphere()
          do the init of the graphical sphere
protected  void initGroundPhysics()
          Initialise the default physical representation of the ground The default invocation from init is synchronized to the PhysicsSync
protected  void initQuickSettings()
          By default, override the frameTitl.
protected  void initSpherePhysics()
          Create the physics of the default sphere and connect it to the graphical representation of the sphere.
 void initThrowBallButton()
           
protected  void initUI()
          Make frame, make canvas, make toolbars & buttons...
protected  void initUI(boolean collisionEnabledCheck, boolean runPhysicsCheck)
          Add a 'throw ball' button to the default UI, and a 'collisionenabled' and 'runphysics' box
protected  void initWorldPhysics()
          Initialise the world physics, collision space, etc When called from init, this is garanteed to be locked on the physics sync
protected  void physicsCopy()
           
protected  void physicsRun(double currentTime)
           
protected  void physicsTick(float delta)
          Called for every tick of the physics simulation, runs collisions and steps the physical world.
protected  void physicsTime(double currentTime)
          Called from the physicsclock.
protected  void prepareClose()
          prepare to close on a physicsrunner
 void prepareDispose()
          prepare to close on a renderrunner
 void prepareReset()
          prepare to reset on a physicsrunner
protected  void reset()
          On reset, reset some of the collision info.
 void setCollisionEnabled(boolean ce)
          CAn also be done through overriding the quicksettings...
 void setPhysicsEnabled(boolean rp)
          CAn also be done through overriding the quicksettings...
 void startClocks()
          in addition to super.startClocks, start physics clock...
 void toggleCollision()
           
 void togglePhysics()
           
 
Methods inherited from class hmi.environment.GraphicsDemoEnvironment
addDebugVisualisation, addRenderRunner, addVisualisation, convertBufferToWowVX, exit, getFrame, getGeneralImageIcon, getImageIcon, getWorldAnimationRoot, getWorldRenderRoot, glInit, glPreInit, glPreRender, glRender, hasVisualisation, initGraphics, initRender, initToolbar, initVisualGround, initVJointStructure, isVisualisationVisible, keyPressed, keyReleased, keyTyped, navigate, play, processAnimationResultForRender, removeDebugVisualisation, removeVisualisation, renderTime, setFullScreen, setupMediaButton, setupMediaButton, setupUI, setupVJointStructure, setVisualisationVisible, startAll, toggleDebugViz
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private org.slf4j.Logger logger

runphysics

public boolean runphysics
If set to false, no physics are calculated


physicsLoopFrequency

public long physicsLoopFrequency
physics is calculated on about 2 times render speed: you want every render tick to surely have latest physics results in it, or at most one animatino step (half a render frame time) behind time... Note: this is NOT the resolution with which physics is simulated; that is determined by timeStep or by the AnimationPlayerManager.getH()


collisionEnabled

public boolean collisionEnabled
Simulate collisions yes or no?


g

protected float[] g
Direction and strength of gravity in this environment


timeStep

protected float timeStep
Stepsize for physics simulation in seconds. Note that in the ElckerlycEnvironment subclass, this value is ignored.


physicsRunners

protected List<Runnable> physicsRunners

phworld

protected org.odejava.World phworld
The Physical World


space

protected org.odejava.HashSpace space
Collison space?


collision

protected org.odejava.collision.JavaCollision collision
To calculate collisions and their effecting forces/impulses.


physicsClock

protected SystemClock physicsClock
The clock on which steps in the physical simulation are taken


prevTime

protected double prevTime
last time stamp for which physics was simulated. Note that in the ElckerlycEnvironment subclass, prevTime is ignored because taking phsyics steps is delegated to the animationplayermanager


groundGeom

protected org.odejava.GeomPlane groundGeom
By default, the physical world contains this physical representation of the Visual ground


phsphere

protected OdeRigidBody phsphere
By default, the scene contains this hard coded physical sphere, which also has a graphical and Animation representation. Useful for quick testing...


sphereAnimationJoint

protected VJoint sphereAnimationJoint
The animation joint of the phsphere


sphereRenderJoint

protected VJoint sphereRenderJoint
The render vjoint of the phsphere


sphereDiffuse

private static final float[] sphereDiffuse
color settings for the default phsphere object


sphereSpecular

private static final float[] sphereSpecular
color settings for the default phsphere object


sphereAmbient

private static final float[] sphereAmbient
color settings for the default phsphere object


sphereEmission

private static final float[] sphereEmission
color settings for the default phsphere object


glueJointGroup

protected org.odejava.JointGroup glueJointGroup
all joints that are glued to the floor?

Constructor Detail

PhysicalDemoEnvironment

public PhysicalDemoEnvironment()
Method Detail

initUI

protected void initUI(boolean collisionEnabledCheck,
                      boolean runPhysicsCheck)
Add a 'throw ball' button to the default UI, and a 'collisionenabled' and 'runphysics' box


initUI

protected void initUI()
Description copied from class: GraphicsDemoEnvironment
Make frame, make canvas, make toolbars & buttons...

Overrides:
initUI in class GraphicsDemoEnvironment

initThrowBallButton

public void initThrowBallButton()

addPhysicsRunner

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


initGraphicScene

protected void initGraphicScene()
Add the graphical representation for the phsphere to the graphical scene

Overrides:
initGraphicScene in class GraphicsDemoEnvironment

initGraphicSphere

protected void initGraphicSphere()
do the init of the graphical sphere


startClocks

public void startClocks()
in addition to super.startClocks, start physics clock...

Overrides:
startClocks in class GraphicsDemoEnvironment

initQuickSettings

protected void initQuickSettings()
By default, override the frameTitl. Overide this method to change the quicksettings

Overrides:
initQuickSettings in class GraphicsDemoEnvironment

init

public void init()
Init the world physics before initializing the rest of the system; after initialization, set up the physics of the default sphere (graphics of it was already done in initGraphicScene) and of the ground

Overrides:
init in class GraphicsDemoEnvironment

initWorldPhysics

protected void initWorldPhysics()
Initialise the world physics, collision space, etc When called from init, this is garanteed to be locked on the physics sync


initSpherePhysics

protected void initSpherePhysics()
Create the physics of the default sphere and connect it to the graphical representation of the sphere. Pre: the graphical representation was already made in initGraphicScene The default invocation from init is synchronized to the PhysicsSync


initGroundPhysics

protected void initGroundPhysics()
Initialise the default physical representation of the ground The default invocation from init is synchronized to the PhysicsSync


physicsTick

protected void physicsTick(float delta)
Called for every tick of the physics simulation, runs collisions and steps the physical world. By default, called by physicsTime, which is called from the physicsClock and calls physicsTick until the simulation is again current with the clock


physicsRun

protected void physicsRun(double currentTime)

physicsCopy

protected void physicsCopy()

physicsTime

protected void physicsTime(double currentTime)
Called from the physicsclock. First physicsRun(currentTime) is called, running the actual physical simulation. By default, this calls physicsTick until the physics simulation is current with the clock again; Then copies the result of the simulation onto the animation VJoint structure, using the physicsCopy() function. Note that this method is done quite differently in the ElcerklycEnvironment where some of this task is delegated to the animationplayermanager. Both physicsRun and physicsCopy have the appropiate synchronisations set. Finally all physics runners are executed. It is strongly encouraged to not override this method but to override physicsRun and physicsCopy instead, since they have the proper synchronisation mechanisms in place already.


cleanUpOdeObjects

private void cleanUpOdeObjects()

close

public void close()
Clean up native ODE objects. Call this before ending your Java program.

Overrides:
close in class GraphicsDemoEnvironment

disposeFrame

protected void disposeFrame()
                     throws InterruptedException,
                            InvocationTargetException
Description copied from class: GraphicsDemoEnvironment
close button pressed, extend or override in subclass

Overrides:
disposeFrame in class GraphicsDemoEnvironment
Throws:
InterruptedException
InvocationTargetException

reset

protected void reset()
On reset, reset some of the collision info. No need to reset physics clock, here. Should not be called directly, use prepareReset to set up a physicsRunner for that.

Overrides:
reset in class GraphicsDemoEnvironment

toggleCollision

public void toggleCollision()

togglePhysics

public void togglePhysics()

prepareReset

public void prepareReset()
prepare to reset on a physicsrunner

Overrides:
prepareReset in class GraphicsDemoEnvironment

prepareClose

protected void prepareClose()
prepare to close on a physicsrunner

Overrides:
prepareClose in class GraphicsDemoEnvironment

prepareDispose

public void prepareDispose()
Description copied from class: GraphicsDemoEnvironment
prepare to close on a renderrunner

Overrides:
prepareDispose in class GraphicsDemoEnvironment

glueFeetToFloor

public void glueFeetToFloor(PhysicalHumanoid pHuman)
Connects the ankle segments to the world with a fixed, unmovable joint, to prevent the feet from slipping

Parameters:
pHuman - human to tighten in place like this

setCollisionEnabled

public void setCollisionEnabled(boolean ce)
CAn also be done through overriding the quicksettings...

Parameters:
ce - the collisionEnabled to set

setPhysicsEnabled

public void setPhysicsEnabled(boolean rp)
CAn also be done through overriding the quicksettings...

Parameters:
rp - the runPhysics to set