de.steeringbehaviors.simulation.renderer
Class SteeringRenderer

java.lang.Object
  extended by de.steeringbehaviors.simulation.renderer.SteeringRenderer

public class SteeringRenderer
extends java.lang.Object

This represents a simple 2d rendering system. It supports panning and zooming over the complete scene. The shapes (based on RenderInfo) are first clipped against the viewpoint. The drawing is based on the z position and done frŽom back to front.


Field Summary
protected  boolean m_allowFreePann
          Allows the panning to use negative relative window positions
protected  java.util.Vector m_clickedShapes
          Sorted structure used to cache the requested shapes at a specific position
protected  long m_frameTime
          Time used for rendering the last frame in ms
protected  java.awt.Color m_gridColor
          The color of the grid lines
protected  double m_gridHeight
          Spacing of the grid along the y axis
protected  double m_gridWidth
          Spacing of the grid along the x axis
protected  boolean m_ignoreVisiblity
          Set this flag to ignore all visibility information of the geometry objects when rendering
protected  int m_relX
          X-Offset of the viewing rectangle
protected  int m_relY
          Y-Offset of the viewing rectangle
protected  boolean m_returnBackgroundShapes
          Used to be able to distinguish between foreground and background shapes when using getVisibleObjects
protected  int m_sceneHeight
          Height of the complete scene
protected  int m_sceneWidth
          Width of the complete scene
protected  int m_screenHeight
          Height of the viewing rectangle
protected  int m_screenWidth
          Width of the viewing rectangle
protected  boolean m_showGrid
          Flag to show or hide the grid
protected  java.util.ArrayList m_visibleInfo
          Sorted structure used to cache the visible shapes for each frame
protected  double m_zoom
          Zoom factor, must be greater zero.
 
Constructor Summary
SteeringRenderer()
          Contructs an instance of the Renderer
SteeringRenderer(int width, int height)
          Constructs an instance of the renderer
 
Method Summary
 boolean allowFreePann()
          Returns true if panning is allowed to used negative values
protected  void drawGrid(java.awt.Graphics g)
          Draws a grid on the graphics context using the defined grid spacing.
 long getFrameTime()
          Returns the tim ein ms used for rendering the last frame
 java.awt.Color getGridColor()
          Sets the color of underlying grid
 boolean getIgnoreVisiblity()
          Returns the ingnoreVisiblity status of the renderer
 int getRelX()
          Access the relative x position
 int getRelY()
          Access the relative y position
 int getSceneHeight()
          Height of the scene in pixels
 int getSceneWidth()
          Width of the scene in pixels
 boolean getShowGrid()
          The state of the background grid
 int getVisibleCount()
          Get the number of visible shapes
 java.util.Vector getVisibleObjects(int x, int y)
          Get the visible shapes at the specified position
 double getZoom()
          Access the zoom factor
 void renderScene(java.util.Iterator it, java.awt.Graphics g)
          Renders the scene into the graphics object
 double screenToWorldX(int screenX)
          Transforms a screen coordinate into world space
 double screenToWorldY(int screenY)
          Transforms a screen coordinate into world space
 void setAllowFreePann(boolean freePann)
          Allow panning to use negative values
 void setGridColor(java.awt.Color gridColor)
          Sets the color of underlying grid
 void setGridHeight(double gridHeight)
          Sets the spacing of underlying grid in the y-axis
 void setGridWidth(double gridWidth)
          Sets the spacing of underlying grid in the x-axis
 void setIgnoreVisiblity(boolean ignoreVisibility)
          Sets the ingnoreVisiblity status of the renderer
 void setRelX(int relX)
          Sets the relative x position of the viewing rectangle
 void setRelY(int relY)
          Sets the relative y position of the viewing rectangle
 void setSceneHeight(int height)
          Sets the height of the scene in pixel
 void setSceneWidth(int width)
          Sets the width of the scene in pixel
 void setScreenHeight(int height)
          Sets the height of the viewing rectangle
 void setScreenWidth(int width)
          Sets the width of the viewing rectangle
 void setShowGrid(boolean showGrid)
          Sets the state of the background grid
 void setZoom(double zoom)
          Sets the new zoom factor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_allowFreePann

protected boolean m_allowFreePann
Allows the panning to use negative relative window positions


m_clickedShapes

protected java.util.Vector m_clickedShapes
Sorted structure used to cache the requested shapes at a specific position


m_frameTime

protected long m_frameTime
Time used for rendering the last frame in ms


m_gridColor

protected java.awt.Color m_gridColor
The color of the grid lines


m_gridWidth

protected double m_gridWidth
Spacing of the grid along the x axis


m_gridHeight

protected double m_gridHeight
Spacing of the grid along the y axis


m_ignoreVisiblity

protected boolean m_ignoreVisiblity
Set this flag to ignore all visibility information of the geometry objects when rendering


m_relX

protected int m_relX
X-Offset of the viewing rectangle


m_relY

protected int m_relY
Y-Offset of the viewing rectangle


m_returnBackgroundShapes

protected boolean m_returnBackgroundShapes
Used to be able to distinguish between foreground and background shapes when using getVisibleObjects


m_sceneHeight

protected int m_sceneHeight
Height of the complete scene


m_sceneWidth

protected int m_sceneWidth
Width of the complete scene


m_screenHeight

protected int m_screenHeight
Height of the viewing rectangle


m_screenWidth

protected int m_screenWidth
Width of the viewing rectangle


m_showGrid

protected boolean m_showGrid
Flag to show or hide the grid


m_visibleInfo

protected java.util.ArrayList m_visibleInfo
Sorted structure used to cache the visible shapes for each frame


m_zoom

protected double m_zoom
Zoom factor, must be greater zero. No zoom == 1.0

Constructor Detail

SteeringRenderer

public SteeringRenderer()
Contructs an instance of the Renderer


SteeringRenderer

public SteeringRenderer(int width,
                        int height)
Constructs an instance of the renderer

Parameters:
width - The width of the viewing rectangle
height - The height of the viewing rectangle
Method Detail

setAllowFreePann

public void setAllowFreePann(boolean freePann)
Allow panning to use negative values

Parameters:
freePann - New state of free panning

setGridColor

public void setGridColor(java.awt.Color gridColor)
Sets the color of underlying grid

Parameters:
gridColor - New color of the grid

setGridHeight

public void setGridHeight(double gridHeight)
Sets the spacing of underlying grid in the y-axis

Parameters:
gridWidth - New y-axis spacing of the grid

setGridWidth

public void setGridWidth(double gridWidth)
Sets the spacing of underlying grid in the x-axis

Parameters:
gridWidth - New x-axis spacing of the grid

setIgnoreVisiblity

public void setIgnoreVisiblity(boolean ignoreVisibility)
Sets the ingnoreVisiblity status of the renderer


setRelX

public void setRelX(int relX)
Sets the relative x position of the viewing rectangle

Parameters:
relX - Relative x position

setRelY

public void setRelY(int relY)
Sets the relative y position of the viewing rectangle

Parameters:
relY - Relative y position

setSceneHeight

public void setSceneHeight(int height)
Sets the height of the scene in pixel

Parameters:
height - Height in pixel

setSceneWidth

public void setSceneWidth(int width)
Sets the width of the scene in pixel

Parameters:
width - Width in pixel

setScreenWidth

public void setScreenWidth(int width)
Sets the width of the viewing rectangle

Parameters:
width - Width in pixel

setScreenHeight

public void setScreenHeight(int height)
Sets the height of the viewing rectangle

Parameters:
height - Height in pixel

setShowGrid

public void setShowGrid(boolean showGrid)
Sets the state of the background grid

Parameters:
showGrid - Flag to turn the grid on or off

setZoom

public void setZoom(double zoom)
Sets the new zoom factor

Parameters:
zoom - New zoom factor

allowFreePann

public boolean allowFreePann()
Returns true if panning is allowed to used negative values

Returns:
State of free panning

getGridColor

public java.awt.Color getGridColor()
Sets the color of underlying grid

Parameters:
gridColor - New color of the grid

getFrameTime

public long getFrameTime()
Returns the tim ein ms used for rendering the last frame

Returns:
Time used for rendering the last frame

getIgnoreVisiblity

public boolean getIgnoreVisiblity()
Returns the ingnoreVisiblity status of the renderer

Returns:
Ignore visibility information

getRelX

public int getRelX()
Access the relative x position

Returns:
The relative x position of the viewing rectangle

getRelY

public int getRelY()
Access the relative y position

Returns:
The relative y position of the viewing rectangle

getSceneWidth

public int getSceneWidth()
Width of the scene in pixels

Returns:
Width of the scene

getSceneHeight

public int getSceneHeight()
Height of the scene in pixels

Returns:
Height of the scene

getShowGrid

public boolean getShowGrid()
The state of the background grid

Returns:
The state of showing the background grid

getVisibleCount

public int getVisibleCount()
Get the number of visible shapes

Returns:
The number of visible shapes

getVisibleObjects

public java.util.Vector getVisibleObjects(int x,
                                          int y)
Get the visible shapes at the specified position

Parameters:
x - The x position
y - The y position
Returns:
The list of visible shape at the x, y position. Can be empty!

getZoom

public double getZoom()
Access the zoom factor

Returns:
The current zoom factor

drawGrid

protected void drawGrid(java.awt.Graphics g)
Draws a grid on the graphics context using the defined grid spacing. The grid is automatically adjusted to relative screen position and zoomfactor.

Parameters:
g - Graphics context to render into

renderScene

public void renderScene(java.util.Iterator it,
                        java.awt.Graphics g)
Renders the scene into the graphics object

Parameters:
it - Iterator over the Geometrie objects in the scene
g - Graphics context to render into

screenToWorldX

public double screenToWorldX(int screenX)
Transforms a screen coordinate into world space

Returns:
The screen x coordinate transformed into world space

screenToWorldY

public double screenToWorldY(int screenY)
Transforms a screen coordinate into world space

Returns:
The screen y coordinate transformed into world space