org.xith3d.scenegraph
Class View

java.lang.Object
  extended by org.xith3d.scenegraph.SceneGraphObject
      extended by org.xith3d.scenegraph.View
All Implemented Interfaces:
org.jagatoo.datatypes.NamableObject, org.jagatoo.datatypes.NamedObject, Transformable

public class View
extends SceneGraphObject
implements Transformable

The View defines a Camera or an Eye to tell OpenGL of the perspective to render from.


Nested Class Summary
static class View.CameraMode
          Camera mode for a View.
static class View.ProjectionPolicy
          Projection policy to render from.
 
Field Summary
static float DEFAULT_BACK_CLIP_DISTANCE_PARALLEL
          The default back clip distance (far clip plane) for parallel projection mode.
static float DEFAULT_BACK_CLIP_DISTANCE_PERSPECTIVE
          The default back clip distance (far clip plane) for perspective projection mode.
static float DEFAULT_FIELD_OF_VIEW
          The default field of view (FOV)
static float DEFAULT_FRONT_CLIP_DISTANCE_PARALLEL
          The default front clip distance (near clip plane) for parallel projection mode.
static float DEFAULT_FRONT_CLIP_DISTANCE_PERSPECTIVE
          The default front clip distance (near clip plane) for perspective projection mode.
static View.ProjectionPolicy PARALLEL_PROJECTION
          Render the scene in parallel projection mode
static View.ProjectionPolicy PERSPECTIVE_PROJECTION
          Render the scene in perspective projection mode
 
Fields inherited from class org.xith3d.scenegraph.SceneGraphObject
XITH3D_USERDATAKEY_OLDUSERDATA
 
Constructor Summary
View()
          Constructs a new View.
View(float eyePositionX, float eyePositionY, float eyePositionZ, float viewFocusX, float viewFocusY, float viewFocusZ, float vecUpX, float vecUpY, float vecUpZ)
          Creates a new View.
View(org.openmali.vecmath2.Tuple3f eyePosition, org.openmali.vecmath2.Tuple3f viewFocus, org.openmali.vecmath2.Tuple3f vecUp)
          Creates a new View.
 
Method Summary
 void addCanvas3D(Canvas3D canvas3D)
          Adds a Canvas3D to this view.
 void addCanvas3D(Canvas3D canvas, int index)
          Adds a Canvas3D at the specified index.
 Transform3D calculatePerspective(float viewportWidth, float viewportHeight)
           
 Transform3D calculatePerspective(org.openmali.types.twodee.Sized2iRO viewport)
           
 PointLight getAttachedLight()
           
 float getBackClipDistance()
           
 Canvas3D getCanvas3D(int index)
           
 java.util.List<Canvas3D> getCanvas3Ds()
           
 org.openmali.vecmath2.Tuple2f getCenterOfView()
           
 org.openmali.vecmath2.Vector3f getFacingDirection()
          Calculates and returns the direction, the view faces.
<T extends org.openmali.vecmath2.Tuple3f>
T
getFacingDirection(T direction)
          Calculates the direction, the view faces and fills the values into the given Tuple3f.
 float getFieldOfView()
           
 float getFrontClipDistance()
           
 org.openmali.spatial.bodies.Frustum getFrustum(float viewportWidth, float viewportHeight)
          Calculates and returns the View's frustum.
 org.openmali.spatial.bodies.Frustum getFrustum(org.openmali.types.twodee.Sized2iRO viewport)
          Calculates and returns the View's frustum.
 Transform3D getModelViewTransform(boolean forceRecomputation)
          Gets model-view transform for the NORMAL camera mode.
 Transform3D getModelViewTransform(View.CameraMode mode, boolean forceRecomputation)
          Gets model-view transform adjusting it depending on the camera mode.
 org.openmali.vecmath2.Point3f getPosition()
          Retrieves and returns the View's position from its Transform3D.
 void getPosition(org.openmali.vecmath2.Tuple3f position)
          Retrieves the View's position from its Transform3D and writes it into position.
 Transform3D getProjection()
           
 View.ProjectionPolicy getProjectionPolicy()
           
 org.openmali.vecmath2.Vector3f getRightDirection()
          Calculates and returns the direction to the right.
<T extends org.openmali.vecmath2.Tuple3f>
T
getRightDirection(T direction)
          Calculates the direction to the right and fills the values into the given Tuple3f.
 float getScreenScale()
           
 float getSoundActivationRadius()
           
 Transform3D getTransform()
          Gets the transform for this object.
 void getTransform(Transform3D transform)
          Gets the transform for this object.
 org.openmali.vecmath2.Vector3f getUpDirection()
          Calculates and returns the direction heading up.
<T extends org.openmali.vecmath2.Tuple3f>
T
getUpDirection(T direction)
          Calculates the direction heading up and fills the values into the given Tuple3f.
 int indexOfCanvas3D(Canvas3D canvas)
           
 void lookAlong(float eyePositionX, float eyePositionY, float eyePositionZ, float viewDirectionX, float viewDirectionY, float viewDirectionZ)
          Helping function that specifies the position and orientation of a view matrix.
 void lookAlong(float eyePositionX, float eyePositionY, float eyePositionZ, float viewDirectionX, float viewDirectionY, float viewDirectionZ, float vecUpX, float vecUpY, float vecUpZ)
          Helping function that specifies the position and orientation of a view matrix.
 void lookAlong(org.openmali.vecmath2.Tuple3f eyePosition, org.openmali.vecmath2.Tuple3f viewDirection)
          Helping function that specifies the position and orientation of a view matrix.
 void lookAlong(org.openmali.vecmath2.Tuple3f eyePosition, org.openmali.vecmath2.Tuple3f viewDirection, org.openmali.vecmath2.Tuple3f vecUp)
          Helping function that specifies the position and orientation of a view matrix.
 void lookAt(float eyePositionX, float eyePositionY, float eyePositionZ, float viewFocusX, float viewFocusY, float viewFocusZ, float vecUpX, float vecUpY, float vecUpZ)
          Helper function that specifies the position and orientation of a view matrix.
 void lookAt(org.openmali.vecmath2.Tuple3f viewFocus)
          Helper function that specifies the position and orientation of a view matrix.
 void lookAt(org.openmali.vecmath2.Tuple3f eyePosition, org.openmali.vecmath2.Tuple3f viewFocus, org.openmali.vecmath2.Tuple3f vecUp)
          Helper function that specifies the position and orientation of a view matrix.
 int numCanvas3Ds()
           
 void removeCanvas3D(Canvas3D canvas)
           
 Canvas3D removeCanvas3D(int index)
           
 void setAttachedLight(PointLight light)
          Attaches a PointLight/SpotLight to this View (or detaches if for null).
 void setBackClipDistance(float value)
          Sets the back clip distance (far clip plane) for this View.
 void setCenterOfView(org.openmali.vecmath2.Tuple2f cov)
          Sets the center of the View.
 void setFacingDirection(org.openmali.vecmath2.Vector3f direction)
          Sets the direction in which the view looks.
 void setFieldOfView(float value)
          Sets the field of view (viewing angle).
 void setFrontClipDistance(float value)
          Sets the front clip distance (near clip plane) for this View.
 void setPosition(float posX, float posY, float posZ)
          Repositions the TransformNode
 void setPosition(org.openmali.vecmath2.Tuple3f position)
          Repositions the TransformNode
 void setProjection(Transform3D customProjection)
          Sets the custom projection transform.
 void setProjectionPolicy(View.ProjectionPolicy policy)
          Sets the projection policy.
 void setScreenScale(float screenScale)
          Sets the screen scale.
 void setSoundActivationRadius(float radius)
          Set the sound activation radius.
 void setTransform(Transform3D transform)
          Sets the transform for this object.
 
Methods inherited from class org.xith3d.scenegraph.SceneGraphObject
getName, getUserData, getUserData, getUserDataMap, isLive, setLive, setName, setUserData, setUserData, setUserDataRecursive, setUserDataRecursive, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xith3d.scenegraph.Transformable
getName, setName
 

Field Detail

PARALLEL_PROJECTION

public static final View.ProjectionPolicy PARALLEL_PROJECTION
Render the scene in parallel projection mode


PERSPECTIVE_PROJECTION

public static final View.ProjectionPolicy PERSPECTIVE_PROJECTION
Render the scene in perspective projection mode


DEFAULT_FIELD_OF_VIEW

public static final float DEFAULT_FIELD_OF_VIEW
The default field of view (FOV)


DEFAULT_FRONT_CLIP_DISTANCE_PERSPECTIVE

public static final float DEFAULT_FRONT_CLIP_DISTANCE_PERSPECTIVE
The default front clip distance (near clip plane) for perspective projection mode.

See Also:
Constant Field Values

DEFAULT_FRONT_CLIP_DISTANCE_PARALLEL

public static final float DEFAULT_FRONT_CLIP_DISTANCE_PARALLEL
The default front clip distance (near clip plane) for parallel projection mode.

See Also:
Constant Field Values

DEFAULT_BACK_CLIP_DISTANCE_PERSPECTIVE

public static final float DEFAULT_BACK_CLIP_DISTANCE_PERSPECTIVE
The default back clip distance (far clip plane) for perspective projection mode.

See Also:
Constant Field Values

DEFAULT_BACK_CLIP_DISTANCE_PARALLEL

public static final float DEFAULT_BACK_CLIP_DISTANCE_PARALLEL
The default back clip distance (far clip plane) for parallel projection mode.

See Also:
Constant Field Values
Constructor Detail

View

public View(float eyePositionX,
            float eyePositionY,
            float eyePositionZ,
            float viewFocusX,
            float viewFocusY,
            float viewFocusZ,
            float vecUpX,
            float vecUpY,
            float vecUpZ)
Creates a new View.

Parameters:
eyePositionX - the center of the eye
eyePositionY - the center of the eye
eyePositionZ - the center of the eye
viewFocusX - the point the view looks at
viewFocusY - the point the view looks at
viewFocusZ - the point the view looks at
vecUpX - the vector pointing up
vecUpY - the vector pointing up
vecUpZ - the vector pointing up

View

public View(org.openmali.vecmath2.Tuple3f eyePosition,
            org.openmali.vecmath2.Tuple3f viewFocus,
            org.openmali.vecmath2.Tuple3f vecUp)
Creates a new View.

Parameters:
eyePosition - the environment's view's location
viewFocus - the environment's view's center (where to look at)
vecUp - the environment's view's normal which is pointing up

View

public View()
Constructs a new View.

Method Detail

setAttachedLight

public final void setAttachedLight(PointLight light)
Attaches a PointLight/SpotLight to this View (or detaches if for null).

Parameters:
light -

getAttachedLight

public final PointLight getAttachedLight()
Returns:
the View-attached PointLight/SpotLight.

setProjectionPolicy

public final void setProjectionPolicy(View.ProjectionPolicy policy)
Sets the projection policy.


getProjectionPolicy

public final View.ProjectionPolicy getProjectionPolicy()
Returns:
the projection policy.

setCenterOfView

public final void setCenterOfView(org.openmali.vecmath2.Tuple2f cov)
Sets the center of the View.

Parameters:
cov - values range from 1 (left) to -1 (right) a value of null sets the center to (0|0) - the default

getCenterOfView

public final org.openmali.vecmath2.Tuple2f getCenterOfView()
Returns:
the center of this View - values range from 1 (left) to -1 (right)

setScreenScale

public final void setScreenScale(float screenScale)
Sets the screen scale.


getScreenScale

public final float getScreenScale()
Returns:
the screen scale.

setFrontClipDistance

public final void setFrontClipDistance(float value)
Sets the front clip distance (near clip plane) for this View.


getFrontClipDistance

public final float getFrontClipDistance()
Returns:
the front clip distance (near clip plane) for this View.

setBackClipDistance

public final void setBackClipDistance(float value)
Sets the back clip distance (far clip plane) for this View.


getBackClipDistance

public final float getBackClipDistance()
Returns:
the back clip distance (far clip plane) for this View.

setFieldOfView

public final void setFieldOfView(float value)
Sets the field of view (viewing angle).


getFieldOfView

public final float getFieldOfView()
Returns:
the field of view (viewing angle).

setSoundActivationRadius

public final void setSoundActivationRadius(float radius)
Set the sound activation radius.
(Sound Nodes, which are farer from the point of view than this radius aren't heard.)

Parameters:
radius - the new sound activation radius

getSoundActivationRadius

public final float getSoundActivationRadius()
Returns:
the sound activation radius.
(Sound Nodes, which are farer from the point of view than this radius aren't heard.)

setTransform

public final void setTransform(Transform3D transform)
Sets the transform for this object.

Specified by:
setTransform in interface Transformable

getTransform

public final Transform3D getTransform()
Gets the transform for this object.

Specified by:
getTransform in interface Transformable

getTransform

public final void getTransform(Transform3D transform)
Gets the transform for this object.

Specified by:
getTransform in interface Transformable

setPosition

public void setPosition(float posX,
                        float posY,
                        float posZ)
Repositions the TransformNode

Specified by:
setPosition in interface Transformable
Parameters:
posX - the new x-position
posY - the new y-position
posZ - the new z-position

setPosition

public final void setPosition(org.openmali.vecmath2.Tuple3f position)
Repositions the TransformNode

Specified by:
setPosition in interface Transformable
Parameters:
position - the new position

getPosition

public final void getPosition(org.openmali.vecmath2.Tuple3f position)
Retrieves the View's position from its Transform3D and writes it into position.

Specified by:
getPosition in interface Transformable
Parameters:
position - the tuple to write the positional data into.

getPosition

public final org.openmali.vecmath2.Point3f getPosition()
Retrieves and returns the View's position from its Transform3D.

Specified by:
getPosition in interface Transformable

lookAt

public final void lookAt(float eyePositionX,
                         float eyePositionY,
                         float eyePositionZ,
                         float viewFocusX,
                         float viewFocusY,
                         float viewFocusZ,
                         float vecUpX,
                         float vecUpY,
                         float vecUpZ)
Helper function that specifies the position and orientation of a view matrix.

Parameters:
eyePositionX - the center of the eye
eyePositionY - the center of the eye
eyePositionZ - the center of the eye
viewFocusX - the point the view looks at
viewFocusY - the point the view looks at
viewFocusZ - the point the view looks at
vecUpX - the vector pointing up
vecUpY - the vector pointing up
vecUpZ - the vector pointing up

lookAt

public final void lookAt(org.openmali.vecmath2.Tuple3f eyePosition,
                         org.openmali.vecmath2.Tuple3f viewFocus,
                         org.openmali.vecmath2.Tuple3f vecUp)
Helper function that specifies the position and orientation of a view matrix.

Parameters:
eyePosition - the center of the eye
viewFocus - the point the view looks at
vecUp - the vector pointing up

lookAt

public final void lookAt(org.openmali.vecmath2.Tuple3f viewFocus)
Helper function that specifies the position and orientation of a view matrix.

Parameters:
viewFocus - the point the view looks at

lookAlong

public final void lookAlong(float eyePositionX,
                            float eyePositionY,
                            float eyePositionZ,
                            float viewDirectionX,
                            float viewDirectionY,
                            float viewDirectionZ,
                            float vecUpX,
                            float vecUpY,
                            float vecUpZ)
Helping function that specifies the position and orientation of a view matrix.

Parameters:
eyePositionX - the center of the eye
eyePositionY - the center of the eye
eyePositionZ - the center of the eye
viewDirectionX - the direction the view looks along
viewDirectionY - the direction the view looks along
viewDirectionZ - the direction the view looks along
vecUpX - the vector pointing up
vecUpY - the vector pointing up
vecUpZ - the vector pointing up

lookAlong

public final void lookAlong(org.openmali.vecmath2.Tuple3f eyePosition,
                            org.openmali.vecmath2.Tuple3f viewDirection,
                            org.openmali.vecmath2.Tuple3f vecUp)
Helping function that specifies the position and orientation of a view matrix.

Parameters:
eyePosition - the center of the eye
viewDirection - the direction the view looks along
vecUp - the vector pointing up

lookAlong

public final void lookAlong(float eyePositionX,
                            float eyePositionY,
                            float eyePositionZ,
                            float viewDirectionX,
                            float viewDirectionY,
                            float viewDirectionZ)
Helping function that specifies the position and orientation of a view matrix.

This method assumes Y-up.

Parameters:
eyePositionX - the center of the eye
eyePositionY - the center of the eye
eyePositionZ - the center of the eye
viewDirectionX - the direction the view looks along
viewDirectionY - the direction the view looks along
viewDirectionZ - the direction the view looks along

lookAlong

public final void lookAlong(org.openmali.vecmath2.Tuple3f eyePosition,
                            org.openmali.vecmath2.Tuple3f viewDirection)
Helping function that specifies the position and orientation of a view matrix.

This method assumes Y-up.

Parameters:
eyePosition - the center of the eye
viewDirection - the direction the view looks along

setFacingDirection

public final void setFacingDirection(org.openmali.vecmath2.Vector3f direction)
Sets the direction in which the view looks.

Parameters:
direction -

getFacingDirection

public final <T extends org.openmali.vecmath2.Tuple3f> T getFacingDirection(T direction)
Calculates the direction, the view faces and fills the values into the given Tuple3f.

Parameters:
direction - the Tuple3f to be filled up with the result

getFacingDirection

public final org.openmali.vecmath2.Vector3f getFacingDirection()
Calculates and returns the direction, the view faces.


getRightDirection

public final <T extends org.openmali.vecmath2.Tuple3f> T getRightDirection(T direction)
Calculates the direction to the right and fills the values into the given Tuple3f.

Parameters:
direction - the Tuple3f to be filled up with the result

getRightDirection

public final org.openmali.vecmath2.Vector3f getRightDirection()
Calculates and returns the direction to the right.


getUpDirection

public final <T extends org.openmali.vecmath2.Tuple3f> T getUpDirection(T direction)
Calculates the direction heading up and fills the values into the given Tuple3f.

Parameters:
direction - the Tuple3f to be filled up with the result

getUpDirection

public final org.openmali.vecmath2.Vector3f getUpDirection()
Calculates and returns the direction heading up.


getModelViewTransform

public final Transform3D getModelViewTransform(View.CameraMode mode,
                                               boolean forceRecomputation)
Gets model-view transform adjusting it depending on the camera mode.

Parameters:
mode - VIEW_NORMAL will return the standard view, VIEW_FIXED_POSITION will return only the rotational component of the standard view (the position is left as the identity), VIEW_FIXED returns the identity matrix.
forceRecomputation - if true, the model-view-transform is guaranteed to be recalculated

getModelViewTransform

public final Transform3D getModelViewTransform(boolean forceRecomputation)
Gets model-view transform for the NORMAL camera mode.

Parameters:
forceRecomputation - if true, the model-view-transform is guaranteed to be recalculated

calculatePerspective

public Transform3D calculatePerspective(float viewportWidth,
                                        float viewportHeight)

calculatePerspective

public final Transform3D calculatePerspective(org.openmali.types.twodee.Sized2iRO viewport)

setProjection

public void setProjection(Transform3D customProjection)
Sets the custom projection transform. This also executes setProjectionPolicy( ( customProjection == null ) ? ProjectionPolicy.PERSPECTIVE_PROJECTION : ProjectionPolicy.PERSPECTIVE_PROJECTION ).

Parameters:
customProjection -

getProjection

public final Transform3D getProjection()
Returns:
the projection Transform3D. calculatePerspective must be called before the result of this method is valid, if projection policy is not custom.

getFrustum

public final org.openmali.spatial.bodies.Frustum getFrustum(float viewportWidth,
                                                            float viewportHeight)
Calculates and returns the View's frustum.

Parameters:
viewportWidth - the canvas width the take for calculation
viewportHeight - the canvas height the take for calculation
Returns:
the View's frustum

getFrustum

public final org.openmali.spatial.bodies.Frustum getFrustum(org.openmali.types.twodee.Sized2iRO viewport)
Calculates and returns the View's frustum.

Parameters:
viewport - the viewport size the take for calculation
Returns:
the View's frustum

addCanvas3D

public void addCanvas3D(Canvas3D canvas3D)
Adds a Canvas3D to this view.

Parameters:
canvas3D - the canvas to be added

addCanvas3D

public final void addCanvas3D(Canvas3D canvas,
                              int index)
Adds a Canvas3D at the specified index.

Parameters:
canvas - the Canvas3D to add
index - the new index of the Canvas3D

removeCanvas3D

public final Canvas3D removeCanvas3D(int index)

removeCanvas3D

public void removeCanvas3D(Canvas3D canvas)

getCanvas3D

public final Canvas3D getCanvas3D(int index)

indexOfCanvas3D

public final int indexOfCanvas3D(Canvas3D canvas)

numCanvas3Ds

public final int numCanvas3Ds()

getCanvas3Ds

public final java.util.List<Canvas3D> getCanvas3Ds()
Returns:
a read-only List of all Canvas3Ds registered to this View.