espresso3d.engine.viewport
Class E3DViewport

java.lang.Object
  extended byespresso3d.engine.base.E3DEngineItem
      extended byespresso3d.engine.renderer.base.E3DRenderable
          extended byespresso3d.engine.viewport.E3DViewport

public class E3DViewport
extends E3DRenderable

Author:
Curt A viewport is the region that defines where in the window to perform rendering, and what world to render in it Viewports can be switched to either perspective or orthographic rendering modes. They default in a perspective mode.

Field Summary
static int RENDERMODE_DEFAULT
          If a viewports rendermode is something other than default, that rendermode will overwrite any other rendermode for objects in the scene.
static int VIEWPORT_MODE_ORTHOGRAPHIC
          Orthographic mode for the viewport.
static int VIEWPORT_MODE_PERSPECTIVE
          Perspectve mode for the viewport.
 
Constructor Summary
E3DViewport(E3DEngine engine, int x, int y, int width, int height, java.lang.String viewportID)
          This is used to create a perspective viewport
 
Method Summary
 void addExternalRenderable(E3DRenderable renderableItem, int timeoutFrames)
          This adds an E3DRenderable item to the ExternalRenderable list.
 void addImage(E3DImage image)
          Add a 2D image to the viewport
 double getBottom()
          How far below the camera to render in Ortho Mode
 E3DActor getCameraActor()
          Gets the actor the camera is using as its camera
 double getFarClipPlane()
           
 double getFovY()
           
 int getHeight()
           
 java.util.HashMap getImageMap()
           
 double getLeft()
          How far left of the camera to render in Ortho Mode
 int getMode()
          Gets what mode the viewport is in.
 java.nio.FloatBuffer getModelView()
           
 double getNearClipPlane()
           
 double getOrthoZoom()
          Gets what the current ortho zoom factor is
 double getRight()
          How far right of the camera to render in Ortho Mode
 double getTop()
          How far above the camera to render in Ortho Mode
 java.lang.String getViewportID()
           
 E3DViewportPrinter getViewportPrinter()
           
 int getWidth()
           
 E3DWorld getWorld()
           
 int getX()
           
 int getY()
           
static void lookAt(E3DVector3F position, E3DVector3F forward, E3DVector3F up, E3DVector3F right)
          Deprecated.  
 E3DVector3F projectPoint(E3DVector3F point3D)
          Projecting a point converts a point in 3D worldspace to 2D screen coordinates (x, y).
 void recalcModelViewMatrix()
           
 void recalcProjectionViewMatrix()
           
 void recalcViewportMatrix()
           
 void removeExternalRenderable(E3DRenderable renderableItem)
          Remove an external renderable from the viewport even if its life hasn't expired
 void removeImage(java.lang.String imageID)
          Remove a 2D image from the viewport by imageID
 void render()
           
 void setBottom(double bottom)
          Set how far below the camera to render in Ortho Mode
 void setCameraActor(E3DActor cameraActor)
          This is the actor that the viewport uses as the camera.
 void setFarClipPlane(double farClipPlane)
          Sets the far clipping plane.
 void setFovY(double fovY)
          Sets how many degress you can see in the Y dir.
 void setHeight(int height)
           
 void setImageMap(E3DSortedRenderableMap imageMap)
           
 void setLeft(double left)
          Set how far left of the camera to render in Ortho Mode
 void setNearClipPlane(double nearClipPlane)
          Sets the near clipping plane.
 void setOrthoBounds(double left, double right, double top, double bottom, double near, double far)
          set all the boundaries for the ortho view mode in one method
 void setOrthoZoom(double zoomScalar)
          This makes the current ortho view zoom out(positive # greater than 1), or zoom in (positive number > 0.0 and < 1.0).
 void setRight(double right)
          Set how far right of the camera to render in Ortho Mode
 void setTop(double top)
          Set how far above the camera to render in Ortho Mode
 void setViewportPrinter(E3DViewportPrinter viewportPrinter)
           
 void setWidth(int width)
           
 void setWorld(E3DWorld world)
           
 void setX(int x)
          Sets the x coordinate of the bottom left corner of the viewport.
 void setY(int y)
          Sets the y coordinate of the bottom left corner of the viewport
 void switchToOrthographicMode(double left, double right, double top, double bottom, double near, double far)
          Switch this viewport to orthographic rendering.
 void switchToPerspectiveMode(double fovY, double farClipPlane, double nearClipPlane)
          Switch this viewport to perspective rendering.
 void switchToViewport()
           
 E3DVector3F unprojectPoint(E3DVector3F point2D)
          Unprojecting takes a 2D point that is in screen coordinate space (x, y) and returns its 3d counterpart in world corodinate space.
 
Methods inherited from class espresso3d.engine.renderer.base.E3DRenderable
getBlendMode, getKey, getRenderMode, initCorrectGeometryRenderer, isKeyChanged, setBlendMode, setKeyChanged, setRenderMode
 
Methods inherited from class espresso3d.engine.base.E3DEngineItem
getEngine, setEngine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RENDERMODE_DEFAULT

public static final int RENDERMODE_DEFAULT
If a viewports rendermode is something other than default, that rendermode will overwrite any other rendermode for objects in the scene. For example, if it the viewport rendermode is switched to RENDERMODE_WIREFRAME, all objects will be rendered as a wireframe object This defaults to RENDERMODE_DEFAULT meaning each object can have its own rendermode

See Also:
Constant Field Values

VIEWPORT_MODE_ORTHOGRAPHIC

public static final int VIEWPORT_MODE_ORTHOGRAPHIC
Orthographic mode for the viewport. This is used for comparing with getMode if necessary, nto for setting the mode

See Also:
Constant Field Values

VIEWPORT_MODE_PERSPECTIVE

public static final int VIEWPORT_MODE_PERSPECTIVE
Perspectve mode for the viewport. This is used for comparing with getMode if necessary, not for setting the mode

See Also:
Constant Field Values
Constructor Detail

E3DViewport

public E3DViewport(E3DEngine engine,
                   int x,
                   int y,
                   int width,
                   int height,
                   java.lang.String viewportID)
This is used to create a perspective viewport

Parameters:
engine - The engine the viewport will be part of
x - The x coordinate of the bottom left corner of the viewport
y - The y coordinate of the bottom left corner of the viewport
width - Width is how many pixels from X, NOT from 0
height - Height is how many pixels from Y, NOT from 0
viewportID -
Method Detail

getHeight

public int getHeight()
Returns:
Returns the height.

setHeight

public void setHeight(int height)
Parameters:
height - The height of the viewport. This is not a coordinate, it is how high to make it from y. Remember, Y gets larger as it goes up the screen

getWidth

public int getWidth()
Returns:
Returns the width.

setWidth

public void setWidth(int width)
Parameters:
width - The width of the viewport. This is not a coordinate, it is how wide to make it from x

getX

public int getX()
Returns:
Returns the x coordinate of the bottom left corner of the viewport

setX

public void setX(int x)
Sets the x coordinate of the bottom left corner of the viewport. The bottom left corner is 0, and X gets larger as it mvoes right

Parameters:
x -

getY

public int getY()
Returns:
Returns the y coordinate of the bottom left corner of the viewport. The upper bottom corner is 0, and Y gets larger as it goes up the screen

setY

public void setY(int y)
Sets the y coordinate of the bottom left corner of the viewport

Parameters:
y -

getFarClipPlane

public double getFarClipPlane()
Returns:
Returns the farClipPlane. This is how far the scene will be drawn away from the cameara. Defaults to 100

setFarClipPlane

public void setFarClipPlane(double farClipPlane)
Sets the far clipping plane. The large the value, the farther away you will be able to see. However, too large of a value can hurt performance.

Parameters:
farClipPlane - The farClipPlane to set.

getFovY

public double getFovY()
Returns:
Returns the fovY. This is how many degrees you can see in the Y dir

setFovY

public void setFovY(double fovY)
Sets how many degress you can see in the Y dir.

Parameters:
fovY - The fovY to set.

getNearClipPlane

public double getNearClipPlane()
Returns:
Returns the nearClipPlane.

setNearClipPlane

public void setNearClipPlane(double nearClipPlane)
Sets the near clipping plane. The smaller the value, the closer you will be able to see objects to the camera.Defaults to 0.1;

Parameters:
nearClipPlane - The nearClipPlane to set.

lookAt

public static void lookAt(E3DVector3F position,
                          E3DVector3F forward,
                          E3DVector3F up,
                          E3DVector3F right)
Deprecated.  

This does what gluLookAt does, only a little faster because it doens't need to renormalise things

Parameters:
position -
forward -
up -
right -

switchToViewport

public void switchToViewport()

getWorld

public E3DWorld getWorld()
Returns:
Returns the world that the viewport needs to display

setWorld

public void setWorld(E3DWorld world)
Parameters:
world - The world to set for the viewport to display. This can be null if it shouldn't render a world.

getViewportID

public java.lang.String getViewportID()

setCameraActor

public void setCameraActor(E3DActor cameraActor)
This is the actor that the viewport uses as the camera. If this is the primarySoundViewport, the listener position will automatically be set to match this actor.

Parameters:
cameraActor -

getCameraActor

public E3DActor getCameraActor()
Gets the actor the camera is using as its camera

Returns:

getMode

public int getMode()
Gets what mode the viewport is in. Orthographic or perspective

Returns:

switchToOrthographicMode

public void switchToOrthographicMode(double left,
                                     double right,
                                     double top,
                                     double bottom,
                                     double near,
                                     double far)
Switch this viewport to orthographic rendering. Ortho rendering doesn't give the illusion of perspective.

Parameters:
left - How far left to render of the viewport's camera actor
right - How right left to render of the viewport's camera actor
top - How far above to render of the viewport's camera actor
bottom - How far below to render of the viewport's camera actor
near - How close of objects to render by the camera
far - How far away to render objects from the camera

switchToPerspectiveMode

public void switchToPerspectiveMode(double fovY,
                                    double farClipPlane,
                                    double nearClipPlane)
Switch this viewport to perspective rendering. Perspective is a standard 3d rendering that simulates what our eyes see.

Parameters:
fovY - The field of view angle in degress in the Y direciton. 45 is a standard value. Too high makes things look fisheyed.
farClipPlane - This specifies the maximum distance that objects can be from the camera and still be rendered
nearClipPlane - Specifies the minimum distance that objects can be from the camera and still be rendered

setOrthoBounds

public void setOrthoBounds(double left,
                           double right,
                           double top,
                           double bottom,
                           double near,
                           double far)
set all the boundaries for the ortho view mode in one method

Parameters:
left -
right -
top -
bottom -
near -
far -

setOrthoZoom

public void setOrthoZoom(double zoomScalar)
This makes the current ortho view zoom out(positive # greater than 1), or zoom in (positive number > 0.0 and < 1.0). 1 will reset it to the original zoom. Negative numbers and 0 are not allowed and will be converted to 1 The actual ortho bounds are not modified, this is a scalar multiplied to them at runtime.


getOrthoZoom

public double getOrthoZoom()
Gets what the current ortho zoom factor is


getBottom

public double getBottom()
How far below the camera to render in Ortho Mode

Returns:

setBottom

public void setBottom(double bottom)
Set how far below the camera to render in Ortho Mode

Returns:

getLeft

public double getLeft()
How far left of the camera to render in Ortho Mode

Returns:

setLeft

public void setLeft(double left)
Set how far left of the camera to render in Ortho Mode

Parameters:
left -

getRight

public double getRight()
How far right of the camera to render in Ortho Mode


setRight

public void setRight(double right)
Set how far right of the camera to render in Ortho Mode


getTop

public double getTop()
How far above the camera to render in Ortho Mode


setTop

public void setTop(double top)
Set how far above the camera to render in Ortho Mode


getViewportPrinter

public E3DViewportPrinter getViewportPrinter()

setViewportPrinter

public void setViewportPrinter(E3DViewportPrinter viewportPrinter)

recalcProjectionViewMatrix

public void recalcProjectionViewMatrix()

recalcModelViewMatrix

public void recalcModelViewMatrix()

recalcViewportMatrix

public void recalcViewportMatrix()

projectPoint

public E3DVector3F projectPoint(E3DVector3F point3D)
Projecting a point converts a point in 3D worldspace to 2D screen coordinates (x, y). Z of the projected point is a value between 0 and 1 which is where its at between the near and far clip plane

Returns:

unprojectPoint

public E3DVector3F unprojectPoint(E3DVector3F point2D)
Unprojecting takes a 2D point that is in screen coordinate space (x, y) and returns its 3d counterpart in world corodinate space. Z in the point passed in gives the position between the near and far clip plane (value between 0 and 1)

Parameters:
point2D -
Returns:

getImageMap

public java.util.HashMap getImageMap()

setImageMap

public void setImageMap(E3DSortedRenderableMap imageMap)

addImage

public void addImage(E3DImage image)
Add a 2D image to the viewport

Parameters:
image -

removeImage

public void removeImage(java.lang.String imageID)
Remove a 2D image from the viewport by imageID

Parameters:
imageID -

render

public void render()
Specified by:
render in class E3DRenderable

addExternalRenderable

public void addExternalRenderable(E3DRenderable renderableItem,
                                  int timeoutFrames)
This adds an E3DRenderable item to the ExternalRenderable list. All E3DRenderables in this list will be rendered after the main rendering hierarchy is rendered (world, actors, particles, etc) but before any 2D static images or text (so the text/images will be on top of external renderables) Each item on the list will be rendered for the # of frames passed in This is very useful for debugging (adding CMLines to the rendering loop to see direction vectors and things) It could even potentially be used to plug in your own rendering algorithm.

Parameters:
renderableItem - An E3DRenderable item that you want to render outside of the optimized rendering loop.
timeoutFrames - How many frames to render this renderable for or -1 for infinity

removeExternalRenderable

public void removeExternalRenderable(E3DRenderable renderableItem)
Remove an external renderable from the viewport even if its life hasn't expired

Parameters:
renderableItem -

getModelView

public java.nio.FloatBuffer getModelView()