org.xith3d.render
Class Canvas3D

java.lang.Object
  extended by org.xith3d.render.Canvas3D
All Implemented Interfaces:
org.openmali.types.twodee.ExtPositioned2i, org.openmali.types.twodee.ExtSized2i, org.openmali.types.twodee.Positioned2i, org.openmali.types.twodee.Positioned2iRO, org.openmali.types.twodee.Sized2i, org.openmali.types.twodee.Sized2iRO, PickEngine, ScreenshotEngine

public class Canvas3D
extends java.lang.Object
implements org.openmali.types.twodee.ExtPositioned2i, org.openmali.types.twodee.ExtSized2i, ScreenshotEngine, PickEngine

A Canvas3D offers a plane area where the scene is projectively rendered on. A RenderPassConfigProvider is used to define some rendering parameters. This can be the configuration of a RenderPass or a View.


Field Summary
protected  int oldHeight
           
protected  int oldWidth
           
 
Constructor Summary
protected Canvas3D(CanvasPeer peer)
           
protected Canvas3D(CanvasPeer peer, org.openmali.vecmath2.Colorf backgroundColor)
           
protected Canvas3D(CanvasPeer peer, float backgroundColorR, float backgroundColorG, float backgroundColorB)
           
 
Method Summary
 void addRepositionListener(org.openmali.types.twodee.util.RepositionListener2i listener)
          Not used!
 void addResizeListener(org.openmali.types.twodee.util.ResizeListener2i listener)
           Notification occurs in the Xith3D rendering thread and complies with its threading rules.
 void addWindowClosingListener(WindowClosingListener l)
          Adds a new WindowClosingListener to be notified, when a non-fullscreen Canvas3D's Window is to be closed by clicking the X-button.
protected  void checkForResized()
          Checks the Canvas3D for resizing.
 void clear()
          Clears the screen to BLACK.
 void disableLighting()
          Disables lighting on this Canvas3D.
 void enableLighting()
          Enables lighting on this Canvas3D.
protected  void fireResizeEvent()
          Notifies any interested parties that this Canvas3D has been resized.
 float getAspect()
           
 org.openmali.vecmath2.Colorf getBackgroundColor()
           
 float getBrightness()
           
 CanvasPeer getCanvasPeer()
          Deprecated. Use and see getPeer().
 float getContrast()
           
 org.jagatoo.input.render.Cursor getCursor()
           
 float getGamma()
           
 int getHeight()
           
 org.jagatoo.input.devices.InputDeviceFactory getInputDeviceFactory()
           
 int getLeft()
           
 org.openmali.vecmath2.Tuple2i getLocation()
           
 CanvasPeer getPeer()
           
 Renderer getRenderer()
           
 RenderOptions getRenderOptions()
           
 org.openmali.vecmath2.Tuple2i getSize()
           
 java.lang.String getTitle()
           
 int getTop()
           
 View getView()
           
 org.openmali.types.twodee.Rect2i getViewport()
           
 int getWidth()
           
 boolean isFullscreen()
           
 boolean isUndecorated()
           
 boolean isWireframeMode()
           
 void pickAll(GroupNode group, org.jagatoo.input.devices.components.MouseButton button, int x, int y, AllPickListener pl)
          Picks all Nodes in the given Group.
 void pickAll(GroupNode group, org.jagatoo.input.devices.components.MouseButton button, int x, int y, AllPickListener pl, java.lang.Object userObject)
          Picks all Nodes in the given Group.
 void pickAll(java.util.List<? extends GroupNode> groups, org.jagatoo.input.devices.components.MouseButton button, int x, int y, AllPickListener pl)
          Picks all Nodes in the given Groups.
 void pickAll(java.util.List<? extends GroupNode> groups, org.jagatoo.input.devices.components.MouseButton button, int x, int y, AllPickListener pl, java.lang.Object userObject)
          Picks all Nodes in the given Groups.
 void pickAll(java.util.List<? extends GroupNode> groups, org.jagatoo.input.devices.components.MouseButton button, int x, int y, int width, int height, AllPickListener pl, java.lang.Object userObject)
           
 void pickNearest(GroupNode group, org.jagatoo.input.devices.components.MouseButton button, int x, int y, NearestPickListener pl)
          Picks the all Nodes in the given Group and finds the closest one to the View.
 void pickNearest(GroupNode group, org.jagatoo.input.devices.components.MouseButton button, int x, int y, NearestPickListener pl, java.lang.Object userObject)
          Picks the all Nodes in the given Group and finds the closest one to the View.
 void pickNearest(java.util.List<? extends GroupNode> groups, org.jagatoo.input.devices.components.MouseButton button, int x, int y, int width, int height, NearestPickListener pl, java.lang.Object userObject)
           
 void pickNearest(java.util.List<? extends GroupNode> groups, org.jagatoo.input.devices.components.MouseButton button, int x, int y, NearestPickListener pl)
          Picks the all Nodes in the given Groups and finds the closest one to the View.
 void pickNearest(java.util.List<? extends GroupNode> groups, org.jagatoo.input.devices.components.MouseButton button, int x, int y, NearestPickListener pl, java.lang.Object userObject)
          Picks the all Nodes in the given Groups and finds the closest one to the View.
 void removeRepositionListener(org.openmali.types.twodee.util.RepositionListener2i listener)
          Not used!
 void removeResizeListener(org.openmali.types.twodee.util.ResizeListener2i listener)
          
 void removeWindowClosingListener(WindowClosingListener l)
          Removes a WindowClosingListener.
 void setBackgroundColor(org.openmali.vecmath2.Colorf color)
          Sets the background color for this Canvas3D (in fact for the CanvasPeer).
 void setBackgroundColor(float red, float green, float blue)
          Sets the background color for this Canvas3D (in fact for the CanvasPeer).
 void setCentered()
          Adjusts this standalone canvas's location so that it is centered on the screen
 void setCursor(org.jagatoo.input.render.Cursor cursor)
          Sets the new Cursor for this Mouse.
 boolean setFullscreen(boolean fullscreen)
          Switches this Canvas3D's fullscreen flag.
 void setGamma(float gamma, float brightness, float contrast)
          Changes the gamma-, brightness- and contrast values for this CanvasPeer.
 void setHeight(int height)
           
 void setIcon(java.net.URL iconResource)
          Changes the window icon.
 Canvas3D setLocation(int left, int top)
          Sets the location of the Canvas3D
 Canvas3D setLocation(org.openmali.vecmath2.Tuple2i loc)
          Sets the location of the Canvas3D
protected  void setPeer(CanvasPeer peer)
           
protected  void setRenderer(Renderer renderer)
          Sets the Renderer, this Canvas3D is registered to.
 void setRenderOptions(RenderOptions ro)
          Sets this Canvas3D's RenderOptions
 Canvas3D setSize(int width, int height)
          Sets the size of the Canvas3D
 Canvas3D setSize(org.openmali.types.twodee.Sized2iRO size)
          Sets the size of the Canvas3D
 Canvas3D setSize(org.openmali.vecmath2.Tuple2i size)
          Sets the size of the Canvas3D
 void setTitle(java.lang.String title)
          Sets the containing window's title
 void setView(View view)
          Assotiates a View with this Canvas3D.
 void setViewport(org.openmali.types.twodee.Rect2i viewport)
          Sets this CanvasPeer's Viewport.
 void setWidth(int width)
           
 void setWireframeMode(boolean enabled)
          Enables or disables wireframe mode.
 boolean switchWireframeMode()
          Switches wireframe mode.
 java.io.File takeScreenshot(boolean alpha)
          Takes a screenshot of the current rendering of the first added Canvas3D.
 void takeScreenshot(java.io.File file, boolean alpha)
          Takes a screenshot of the current rendering
 java.io.File takeScreenshot(java.lang.String filenameBase, boolean alpha)
          Takes a screenshot of the current rendering
 void worldToScreen(org.openmali.vecmath2.Tuple3f world, org.openmali.vecmath2.Tuple2i screen)
          Calculates screen coordinates for the given world coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oldWidth

protected int oldWidth

oldHeight

protected int oldHeight
Constructor Detail

Canvas3D

protected Canvas3D(CanvasPeer peer,
                   float backgroundColorR,
                   float backgroundColorG,
                   float backgroundColorB)

Canvas3D

protected Canvas3D(CanvasPeer peer,
                   org.openmali.vecmath2.Colorf backgroundColor)

Canvas3D

protected Canvas3D(CanvasPeer peer)
Method Detail

setRenderer

protected final void setRenderer(Renderer renderer)
Sets the Renderer, this Canvas3D is registered to.

Parameters:
renderer -

getRenderer

public final Renderer getRenderer()
Returns:
the Renderer, this Canvas3D is registered to.

addRepositionListener

public void addRepositionListener(org.openmali.types.twodee.util.RepositionListener2i listener)
Not used!

Specified by:
addRepositionListener in interface org.openmali.types.twodee.ExtPositioned2i

removeRepositionListener

public void removeRepositionListener(org.openmali.types.twodee.util.RepositionListener2i listener)
Not used!

Specified by:
removeRepositionListener in interface org.openmali.types.twodee.ExtPositioned2i

addResizeListener

public void addResizeListener(org.openmali.types.twodee.util.ResizeListener2i listener)
Notification occurs in the Xith3D rendering thread and complies with its threading rules.

Specified by:
addResizeListener in interface org.openmali.types.twodee.ExtSized2i

removeResizeListener

public void removeResizeListener(org.openmali.types.twodee.util.ResizeListener2i listener)

Specified by:
removeResizeListener in interface org.openmali.types.twodee.ExtSized2i

fireResizeEvent

protected void fireResizeEvent()
Notifies any interested parties that this Canvas3D has been resized. This method should not be called from the Renderer.


addWindowClosingListener

public void addWindowClosingListener(WindowClosingListener l)
Adds a new WindowClosingListener to be notified, when a non-fullscreen Canvas3D's Window is to be closed by clicking the X-button.

Parameters:
l -

removeWindowClosingListener

public void removeWindowClosingListener(WindowClosingListener l)
Removes a WindowClosingListener.

Parameters:
l -

checkForResized

protected void checkForResized()
Checks the Canvas3D for resizing.


setView

public final void setView(View view)
Assotiates a View with this Canvas3D.

Parameters:
view -

getView

public final View getView()
Returns:
the assotiated View

setPeer

protected final void setPeer(CanvasPeer peer)

getPeer

public final CanvasPeer getPeer()
Returns:
the CanvasPeer, backing this Canvas3D. This is the connection to the rendering system.

getCanvasPeer

@Deprecated
public final CanvasPeer getCanvasPeer()
Deprecated. Use and see getPeer().


getTitle

public final java.lang.String getTitle()
Returns:
the containing window's title

setTitle

public final void setTitle(java.lang.String title)
Sets the containing window's title

Parameters:
title - the new title

setIcon

public final void setIcon(java.net.URL iconResource)
                   throws java.io.IOException
Changes the window icon.

Parameters:
iconResource - the resource of the image for the new icon
Throws:
java.io.IOException

clear

public final void clear()
Clears the screen to BLACK.


setCursor

public final void setCursor(org.jagatoo.input.render.Cursor cursor)
Sets the new Cursor for this Mouse. Use null for an invisible Cursor. Use Cursor.DEFAULT_CURSOR for the system's default Cursor.

Parameters:
cursor -

getCursor

public final org.jagatoo.input.render.Cursor getCursor()

getInputDeviceFactory

public final org.jagatoo.input.devices.InputDeviceFactory getInputDeviceFactory()
Returns:
the InputDeviceFactory, that provides methods to retrieve InputDevices for the specified implementation.
See Also:
CanvasPeer.getInputDeviceFactory()

getLocation

public final org.openmali.vecmath2.Tuple2i getLocation()
Specified by:
getLocation in interface org.openmali.types.twodee.Positioned2iRO
Returns:
The location of the Canvas3D

setLocation

public final Canvas3D setLocation(int left,
                                  int top)
Sets the location of the Canvas3D

Specified by:
setLocation in interface org.openmali.types.twodee.Positioned2i
Parameters:
left -
top -
Returns:
true, if the location actually has changed

setCentered

public void setCentered()
Adjusts this standalone canvas's location so that it is centered on the screen


setLocation

public final Canvas3D setLocation(org.openmali.vecmath2.Tuple2i loc)
Sets the location of the Canvas3D

Specified by:
setLocation in interface org.openmali.types.twodee.Positioned2i

getLeft

public final int getLeft()
Specified by:
getLeft in interface org.openmali.types.twodee.Positioned2iRO
Returns:
The left position of the Canvas3D

getTop

public final int getTop()
Specified by:
getTop in interface org.openmali.types.twodee.Positioned2iRO
Returns:
The top position of the Canvas3D

getSize

public final org.openmali.vecmath2.Tuple2i getSize()
Returns:
The width of the Canvas3D

setSize

public final Canvas3D setSize(int width,
                              int height)
Sets the size of the Canvas3D

Specified by:
setSize in interface org.openmali.types.twodee.Sized2i
Parameters:
width -
height -
Returns:
true, if the size actually has changed

setSize

public final Canvas3D setSize(org.openmali.types.twodee.Sized2iRO size)
Sets the size of the Canvas3D

Specified by:
setSize in interface org.openmali.types.twodee.Sized2i
Parameters:
size -
Returns:
true, if the size actually has changed

setSize

public final Canvas3D setSize(org.openmali.vecmath2.Tuple2i size)
Sets the size of the Canvas3D

Specified by:
setSize in interface org.openmali.types.twodee.Sized2i
Parameters:
size -
Returns:
true, if the size actually has changed

setWidth

public final void setWidth(int width)
Specified by:
setWidth in interface org.openmali.types.twodee.Sized2i

setHeight

public final void setHeight(int height)
Specified by:
setHeight in interface org.openmali.types.twodee.Sized2i

getWidth

public final int getWidth()
Specified by:
getWidth in interface org.openmali.types.twodee.Sized2iRO
Returns:
The width of the Canvas3D

getHeight

public final int getHeight()
Specified by:
getHeight in interface org.openmali.types.twodee.Sized2iRO
Returns:
The height of the Canvas3D

getAspect

public final float getAspect()
Specified by:
getAspect in interface org.openmali.types.twodee.Sized2iRO
Returns:
The aspect ratio of the Canvas3D

setFullscreen

public final boolean setFullscreen(boolean fullscreen)
Switches this Canvas3D's fullscreen flag.
Depending on the implementation this flag may be applied on the next render-frame, but not instantly.

Parameters:
fullscreen -
Returns:
the previous fullscreen flag.

isFullscreen

public final boolean isFullscreen()
Returns:
true, if the rendering is done in fullscreen mode

isUndecorated

public final boolean isUndecorated()
Returns:
true, if this Canvas'es window is undecorated.

setViewport

public final void setViewport(org.openmali.types.twodee.Rect2i viewport)
Sets this CanvasPeer's Viewport.

Parameters:
viewport -

getViewport

public final org.openmali.types.twodee.Rect2i getViewport()
Returns:
this CanvasPeer's Viewport

setBackgroundColor

public final void setBackgroundColor(float red,
                                     float green,
                                     float blue)
Sets the background color for this Canvas3D (in fact for the CanvasPeer).

Parameters:
red - the red component of the new background color
green - the green component of the new background color
blue - the blue component of the new background color

setBackgroundColor

public final void setBackgroundColor(org.openmali.vecmath2.Colorf color)
Sets the background color for this Canvas3D (in fact for the CanvasPeer).

Parameters:
color - the new background color

getBackgroundColor

public final org.openmali.vecmath2.Colorf getBackgroundColor()
Returns:
the background color for this Canvas3D (in fact for the CanvasPeer).

setRenderOptions

public void setRenderOptions(RenderOptions ro)
Sets this Canvas3D's RenderOptions


getRenderOptions

public final RenderOptions getRenderOptions()
Returns:
this Canvas3D's RenderOptions

setWireframeMode

public void setWireframeMode(boolean enabled)
Enables or disables wireframe mode.

Parameters:
enabled - if true, wireframe mode will be enabled

isWireframeMode

public boolean isWireframeMode()
Returns:
if wireframe mode is enabled or disabled.

switchWireframeMode

public boolean switchWireframeMode()
Switches wireframe mode.

Returns:
the new state.

enableLighting

public void enableLighting()
Enables lighting on this Canvas3D.


disableLighting

public void disableLighting()
Disables lighting on this Canvas3D.


setGamma

public void setGamma(float gamma,
                     float brightness,
                     float contrast)
Changes the gamma-, brightness- and contrast values for this CanvasPeer.

Parameters:
gamma - the gamma value
brightness - the brightness value [-1.0, +1.0]
contrast - the contrast value [0, +1.0]

getGamma

public float getGamma()
Returns:
the current gamma value for this CanvasPeer.

getBrightness

public float getBrightness()
Returns:
the current brightness value for this CanvasPeer.

getContrast

public float getContrast()
Returns:
the current contrast value for this CanvasPeer.

takeScreenshot

public final void takeScreenshot(java.io.File file,
                                 boolean alpha)
Takes a screenshot of the current rendering

Specified by:
takeScreenshot in interface ScreenshotEngine
Parameters:
file - the file to save the screenshot to
alpha - with alpha channel?

takeScreenshot

public final java.io.File takeScreenshot(java.lang.String filenameBase,
                                         boolean alpha)
Takes a screenshot of the current rendering

Specified by:
takeScreenshot in interface ScreenshotEngine
Parameters:
filenameBase - the filenameBase to save the screenshot to (e.g. "screens/shot") The current date and ".png" are appended.
alpha - with alpha channel?
Returns:
the file where the screenshot has been saved

takeScreenshot

public final java.io.File takeScreenshot(boolean alpha)
Takes a screenshot of the current rendering of the first added Canvas3D.

Specified by:
takeScreenshot in interface ScreenshotEngine
Parameters:
alpha - with alpha channel?
Returns:
the file where the screenshot has been saved

pickAll

public final void pickAll(java.util.List<? extends GroupNode> groups,
                          org.jagatoo.input.devices.components.MouseButton button,
                          int x,
                          int y,
                          int width,
                          int height,
                          AllPickListener pl,
                          java.lang.Object userObject)

pickNearest

public final void pickNearest(java.util.List<? extends GroupNode> groups,
                              org.jagatoo.input.devices.components.MouseButton button,
                              int x,
                              int y,
                              int width,
                              int height,
                              NearestPickListener pl,
                              java.lang.Object userObject)

pickAll

public final void pickAll(java.util.List<? extends GroupNode> groups,
                          org.jagatoo.input.devices.components.MouseButton button,
                          int x,
                          int y,
                          AllPickListener pl,
                          java.lang.Object userObject)
Picks all Nodes in the given Groups.

Specified by:
pickAll in interface PickEngine
Parameters:
groups - the Groups to do the picking on
button - the mouse button, that was clicked to initiate the picking
x - the mouse-x-position where the picking is to be done
y - the mouse-y-position where the picking is to be done
pl - the PickListener to be notified of the pick results
userObject - the user-object to be passed back to the PickListener

pickAll

public final void pickAll(java.util.List<? extends GroupNode> groups,
                          org.jagatoo.input.devices.components.MouseButton button,
                          int x,
                          int y,
                          AllPickListener pl)
Picks all Nodes in the given Groups.

Specified by:
pickAll in interface PickEngine
Parameters:
groups - the Groups to do the picking on
button - the mouse button, that was clicked to initiate the picking
x - the mouse-x-position where the picking is to be done
y - the mouse-y-position where the picking is to be done
pl - the PickListener to be notified of the pick results

pickNearest

public final void pickNearest(java.util.List<? extends GroupNode> groups,
                              org.jagatoo.input.devices.components.MouseButton button,
                              int x,
                              int y,
                              NearestPickListener pl,
                              java.lang.Object userObject)
Picks the all Nodes in the given Groups and finds the closest one to the View.

Specified by:
pickNearest in interface PickEngine
Parameters:
groups - the Groups to do the picking on
button - the mouse button, that was clicked to initiate the picking
x - the mouse-x-position where the picking is to be done
y - the mouse-y-position where the picking is to be done
pl - the PickListener to be notified of the pick results
userObject - the user-object to be passed back to the PickListener

pickNearest

public final void pickNearest(java.util.List<? extends GroupNode> groups,
                              org.jagatoo.input.devices.components.MouseButton button,
                              int x,
                              int y,
                              NearestPickListener pl)
Picks the all Nodes in the given Groups and finds the closest one to the View.

Specified by:
pickNearest in interface PickEngine
Parameters:
groups - the Groups to do the picking on
button - the mouse button, that was clicked to initiate the picking
x - the mouse-x-position where the picking is to be done
y - the mouse-y-position where the picking is to be done
pl - the PickListener to be notified of the pick results

pickAll

public final void pickAll(GroupNode group,
                          org.jagatoo.input.devices.components.MouseButton button,
                          int x,
                          int y,
                          AllPickListener pl,
                          java.lang.Object userObject)
Picks all Nodes in the given Group.

Specified by:
pickAll in interface PickEngine
Parameters:
group - the Group to do the picking on
button - the mouse button, that was clicked to initiate the picking
x - the mouse-x-position where the picking is to be done
y - the mouse-y-position where the picking is to be done
pl - the PickListener to be notified of the pick results
userObject - the user-object to be passed back to the PickListener

pickAll

public final void pickAll(GroupNode group,
                          org.jagatoo.input.devices.components.MouseButton button,
                          int x,
                          int y,
                          AllPickListener pl)
Picks all Nodes in the given Group.

Specified by:
pickAll in interface PickEngine
Parameters:
group - the Group to do the picking on
button - the mouse button, that was clicked to initiate the picking
x - the mouse-x-position where the picking is to be done
y - the mouse-y-position where the picking is to be done
pl - the PickListener to be notified of the pick results

pickNearest

public final void pickNearest(GroupNode group,
                              org.jagatoo.input.devices.components.MouseButton button,
                              int x,
                              int y,
                              NearestPickListener pl,
                              java.lang.Object userObject)
Picks the all Nodes in the given Group and finds the closest one to the View.

Specified by:
pickNearest in interface PickEngine
Parameters:
group - the Group to do the picking on
button - the mouse button, that was clicked to initiate the picking
x - the mouse-x-position where the picking is to be done
y - the mouse-y-position where the picking is to be done
pl - the PickListener to be notified of the pick results
userObject - the user-object to be passed back to the PickListener

pickNearest

public final void pickNearest(GroupNode group,
                              org.jagatoo.input.devices.components.MouseButton button,
                              int x,
                              int y,
                              NearestPickListener pl)
Picks the all Nodes in the given Group and finds the closest one to the View.

Specified by:
pickNearest in interface PickEngine
Parameters:
group - the Group to do the picking on
button - the mouse button, that was clicked to initiate the picking
x - the mouse-x-position where the picking is to be done
y - the mouse-y-position where the picking is to be done
pl - the PickListener to be notified of the pick results

worldToScreen

public void worldToScreen(org.openmali.vecmath2.Tuple3f world,
                          org.openmali.vecmath2.Tuple2i screen)
Calculates screen coordinates for the given world coordinates.

Parameters:
world -
screen -