edu.mines.jtk.sgl
Class TransformContext

java.lang.Object
  extended by edu.mines.jtk.sgl.TraversalContext
      extended by edu.mines.jtk.sgl.TransformContext
Direct Known Subclasses:
CullContext, DrawContext, PickContext

public class TransformContext
extends TraversalContext

A traversal context with coordinate transforms.

A transform context maintains transforms for converting coordinates among five different coordinate systems:

local
the local coordinate system for a node in the scene graph. Vertex coordinates for a node are specified in a local system, which may or may not be the same as the world coordinate system. Two nodes with the same local vertex coordinates (or even a single node) may appear in different locations, corresponding to different world coordinates.
world
the coordinate system for the world (root) node of the scene graph. A local-to-world transform puts all nodes in the same one world coordinate system. World coordinates are independent of any view of the world.
view
a right-handed coordinate system in which the eye or camera is located at the origin, looking down the negative z axis, with the positive y axis up and the positive x axis right. A world-to-view transform typically pushes the world away from the camera, down the negative z axis. As the name implies, view coordinates depend on the view.
cube
a left-handed, normalized coordinate system with six clipping planes. In this coordinate system, x = -1 and x = 1 correspond to the left and right planes, y = -1 and y = 1 correspond to the bottom and top planes, and z = -1 and z = 1 correspond to the near and far planes. A view-to-cube transform corresponds to a view's projection; e.g., perspective or orthographic.
pixel
typically, a right-handed coordinate system in which x and y coordinates are window coordinates. For a window with width w and height h, x = 0 and x = w-1 correspond to the leftmost and rightmost pixels, and y = 0 and y = h-1 correspond to the topmost and bottommost pixels. The pixel z (depth) coordinate is a floating point number, where z = 0.0 and z = 1.0 correspond to the near and far clipping planes. A cube-to-pixel transform typically depends on the dimensions of the window in which a scene is rendered.

When traversing the scenegraph, the world-to-view, view-to-cube, and cube-to-pixel transforms do not change. However, nodes that transform coordinates will push, modify, and pop the local-to-world transform, using the methods pushLocalToWorld(Matrix44) and popLocalToWorld().

Version:
2005.05.21
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
TransformContext(ViewCanvas canvas)
          Constructs a transform context for the specified view canvas.
 
Method Summary
 Matrix44 getCubeToLocal()
          Gets the cube-to-local transform.
 Matrix44 getCubeToPixel()
          Gets the cube-to-pixel transform.
 Matrix44 getCubeToView()
          Gets the cube-to-view transform.
 Matrix44 getCubeToWorld()
          Gets the cube-to-world transform.
 Matrix44 getLocalToCube()
          Gets the local-to-cube transform.
 Matrix44 getLocalToPixel()
          Gets the local-to-pixel transform.
 Matrix44 getLocalToView()
          Gets the local-to-view transform.
 Matrix44 getLocalToWorld()
          Gets the local-to-world transform.
 Matrix44 getPixelToCube()
          Gets the pixel-to-cube transform.
 Matrix44 getPixelToLocal()
          Gets the pixel-to-local transform.
 Matrix44 getPixelToView()
          Gets the pixel-to-view transform.
 Matrix44 getPixelToWorld()
          Gets the pixel-to-world transform.
 View getView()
          Gets the view for which this transform context was constructed.
 ViewCanvas getViewCanvas()
          Gets the canvas for which this transform context was constructed.
 Matrix44 getViewToCube()
          Gets the view-to-cube transform.
 Matrix44 getViewToLocal()
          Gets the view-to-local transform.
 Matrix44 getViewToPixel()
          Gets the view-to-pixel transform.
 Matrix44 getViewToWorld()
          Gets the view-to-world transform.
 World getWorld()
          Gets the world for which this transform context was constructed.
 Matrix44 getWorldToCube()
          Gets the world-to-cube transform.
 Matrix44 getWorldToLocal()
          Gets the world-to-local transform.
 Matrix44 getWorldToPixel()
          Gets the world-to-pixel transform.
 Matrix44 getWorldToView()
          Gets the world-to-view transform.
 void popLocalToWorld()
          Restores the most recently saved (pushed) local-to-world transform.
 void pushLocalToWorld(Matrix44 transform)
          Saves the local-to-world transform before appending a transform.
 
Methods inherited from class edu.mines.jtk.sgl.TraversalContext
countNodes, getNode, getNode, getNodes, popNode, pushNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransformContext

public TransformContext(ViewCanvas canvas)
Constructs a transform context for the specified view canvas. Gets its view-to-cube and cube-to-pixel transforms from the canvas. Gets its world-to-view transform from the view drawn on that canvas, and sets the local-to-world transform to the identity matrix.

Parameters:
canvas - the view canvas.
Method Detail

getViewCanvas

public ViewCanvas getViewCanvas()
Gets the canvas for which this transform context was constructed.

Returns:
the view canvas.

getView

public View getView()
Gets the view for which this transform context was constructed.

Returns:
the view.

getWorld

public World getWorld()
Gets the world for which this transform context was constructed.

Returns:
the world.

getLocalToWorld

public Matrix44 getLocalToWorld()
Gets the local-to-world transform.

Returns:
the local-to-world transform.

getWorldToLocal

public Matrix44 getWorldToLocal()
Gets the world-to-local transform.

Returns:
the world-to-local transform.

getLocalToView

public Matrix44 getLocalToView()
Gets the local-to-view transform.

Returns:
the local-to-view transform.

getViewToLocal

public Matrix44 getViewToLocal()
Gets the view-to-local transform.

Returns:
the view-to-local transform.

getLocalToCube

public Matrix44 getLocalToCube()
Gets the local-to-cube transform.

Returns:
the local-to-cube transform.

getCubeToLocal

public Matrix44 getCubeToLocal()
Gets the cube-to-local transform.

Returns:
the cube-to-local transform.

getLocalToPixel

public Matrix44 getLocalToPixel()
Gets the local-to-pixel transform.

Returns:
the local-to-pixel transform.

getPixelToLocal

public Matrix44 getPixelToLocal()
Gets the pixel-to-local transform.

Returns:
the pixel-to-local transform.

getWorldToView

public Matrix44 getWorldToView()
Gets the world-to-view transform.

Returns:
the world-to-view transform.

getViewToWorld

public Matrix44 getViewToWorld()
Gets the view-to-world transform.

Returns:
the view-to-world transform.

getWorldToCube

public Matrix44 getWorldToCube()
Gets the world-to-cube transform.

Returns:
the world-to-cube transform.

getCubeToWorld

public Matrix44 getCubeToWorld()
Gets the cube-to-world transform.

Returns:
the cube-to-world transform.

getWorldToPixel

public Matrix44 getWorldToPixel()
Gets the world-to-pixel transform.

Returns:
the world-to-pixel transform.

getPixelToWorld

public Matrix44 getPixelToWorld()
Gets the pixel-to-world transform.

Returns:
the pixel-to-world transform.

getViewToCube

public Matrix44 getViewToCube()
Gets the view-to-cube transform.

Returns:
the view-to-cube transform.

getCubeToView

public Matrix44 getCubeToView()
Gets the cube-to-view transform.

Returns:
the cube-to-view transform.

getViewToPixel

public Matrix44 getViewToPixel()
Gets the view-to-pixel transform.

Returns:
the view-to-pixel transform.

getPixelToView

public Matrix44 getPixelToView()
Gets the pixel-to-view transform.

Returns:
the pixel-to-view transform.

getCubeToPixel

public Matrix44 getCubeToPixel()
Gets the cube-to-pixel transform.

Returns:
the cube-to-pixel transform.

getPixelToCube

public Matrix44 getPixelToCube()
Gets the pixel-to-cube transform.

Returns:
the pixel-to-cube transform.

pushLocalToWorld

public void pushLocalToWorld(Matrix44 transform)
Saves the local-to-world transform before appending a transform. The specified transform matrix is post-multiplied with the current local-to-world transform, such that the specified transform is applied first when transforming local coordinates to world coordinates.

Parameters:
transform - the transform to append.

popLocalToWorld

public void popLocalToWorld()
Restores the most recently saved (pushed) local-to-world transform. Discards the current local-to-world transform.