y25.graphics
Class Camera

java.lang.Object
  extended byy25.graphics.Camera

public class Camera
extends Object

Represents a camera in three dimensional space.


Field Summary
protected  Transform cameraToNDC
          The transform that transforms camera coordinates into (NDC) normalized device coordinates.
protected  float fov
          The field of view angle in degrees.
protected  float height
          The height of the view area in pixels.
static float maxFOV
          The maximal field of view angle in degrees.
static float minFOV
          The minimal field of view angle in degrees.
protected  Transform ndcToScreen
          The transform that transforms NDC coordinates into screen soordinates.
protected  Point3D target
          The point this camera looks at.
protected  float viewDistance
          The camera's distance from the target.
protected  float viewRotX
          The camera's rotation around the x-axis.
protected  float viewRotY
          The camera's rotation around the y-axis.
protected  float viewRotZ
          The camera's rotation around the z-axis.
protected  float width
          The width of the view area in pixels.
protected  float width_height
          The aspect ratio ( width / height ).
protected  Transform worldToCamera
          The transform that transforms world coordinates into camera coordinates.
protected  Transform worldToScreen
          A shortcut transform that transforms world coordinates directly into screen soordinates.
protected  float zFar
          The z-value of the far clipping plane.
protected  float zNear
          The z-value of the near clipping plane.
 
Constructor Summary
Camera()
          Creates a default camera.
 
Method Summary
 void activateHUD(GLAutoDrawable drawable)
          Activates a "Head Up Display" for the given drawable.
 void activateProjection(GLAutoDrawable drawable)
          Sets the passed drawable's OpenGL projection and modelview matrices to this camera's settings.
 void changePerspective(float angle)
          Increases or decreases the field of viwe by the given angle while keeping the viewing area as coherent as possible with the previous setting.
 void deactivateHUD(GLAutoDrawable drawable)
          Deactivates the "Head Up Display" and returns to the previous projection settings.
 float getAspectRatio()
          Returns the camaera's aspect ratio.
 float getFarClippingPlane()
          Returns the z-value of the far clipping plane.
 float getFOV()
          Returns the field of view of this camera in angles.
 Point3D getHUDCoordinates(GLAutoDrawable drawable, Point3D p)
          Returns the HUD-Coordinates of the passed point.
 float getNearClippingPlane()
          Returns the z-value of the near clipping plane.
 Point3D getPosition()
          Returns the position of the camera.
 float getRotationX()
          Returns the camera's rotation around the x-axis.
 float getRotationY()
          Returns the camera's rotation around the y-axis.
 float getRotationZ()
          Returns the camera's rotation around the z-axis.
 Point3D getScreenCoordinates(Point3D p)
          Returns the screen coordinates of the passed point.
 Point3D getTarget()
          Returns the viweing target of this camera.
 Vector3D getUpDirection()
          Returns the vector in three dimensional space that corresponds to the upward direction in the viewing plane.
 Vector3D getViewDirection()
          Returns the view direction of the camera.
 float getViewDistance()
          Returns the distance from this camera to the target.
 void rotate(float x, float y, float z)
          Rotates the camera by the passed angles in degrees.
 void setClippingPlanes(BoundingBox bb)
          Adjusts the clipping planes of this camera so that the content of the passed bounding box can be displayed correctly.
 void setClippingPlanes(float zN, float zF)
          Sets the near and far clipping planes to the specified values.
 void setFarClippingPlane(float far)
          Sets the far clipping plane of this camera.
 void setFOV(float f)
          Sets the field of view of this camera in angles.
 void setHeight(float h)
          Sets the hegiht of the camera's viewing plane in pixels.
 void setNearClippingPlane(float near)
          Sets the near clipping plane of this camera.
 void setPerspective(float angle)
          Sets the field of view of this camera while keeping the viewing area as coherent as possible with the previous setting.
 void setPosition(Point3D pos)
          Sets the position of this camera.
 void setRotation(float x, float y, float z)
          Sets the x,y,z rotation of this camera.
 void setTarget(float x, float y, float z)
          Sets the viewing target of this camera to the passed x,y,z coordinates.
 void setTarget(Point3D p)
          Sets the viewing target of this camera to the passed point.
 void setViewDistance(float viewDist)
          Sets the view distance of this camera to the target.
 void setWidth(float w)
          Sets the width of the camera's viewing plane in pixels.
 Vector3D toCamera(GLAutoDrawable drawable, Point3D from)
          Returns a vector that points to the camera.
 String toString()
           
 void zoom(float factor)
          Moves the camera with respect to it's viewing direction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

minFOV

public static float minFOV
The minimal field of view angle in degrees.


maxFOV

public static float maxFOV
The maximal field of view angle in degrees.


fov

protected float fov
The field of view angle in degrees.


width

protected float width
The width of the view area in pixels.


height

protected float height
The height of the view area in pixels.


width_height

protected float width_height
The aspect ratio ( width / height ).


zNear

protected float zNear
The z-value of the near clipping plane.


zFar

protected float zFar
The z-value of the far clipping plane.


target

protected Point3D target
The point this camera looks at.


viewRotX

protected float viewRotX
The camera's rotation around the x-axis. (target beeing the origin of the coordinate sysyem.)


viewRotY

protected float viewRotY
The camera's rotation around the y-axis. (target beeing the origin of the coordinate sysyem.)


viewRotZ

protected float viewRotZ
The camera's rotation around the z-axis. (target beeing the origin of the coordinate sysyem.)


viewDistance

protected float viewDistance
The camera's distance from the target.


worldToCamera

protected Transform worldToCamera
The transform that transforms world coordinates into camera coordinates.


cameraToNDC

protected Transform cameraToNDC
The transform that transforms camera coordinates into (NDC) normalized device coordinates.


ndcToScreen

protected Transform ndcToScreen
The transform that transforms NDC coordinates into screen soordinates.


worldToScreen

protected Transform worldToScreen
A shortcut transform that transforms world coordinates directly into screen soordinates.

Constructor Detail

Camera

public Camera()
Creates a default camera. The following settings are used:

Method Detail

activateProjection

public void activateProjection(GLAutoDrawable drawable)
Sets the passed drawable's OpenGL projection and modelview matrices to this camera's settings.

After calling this method, world geometry will be drawn as if viewed from this camera.


getScreenCoordinates

public Point3D getScreenCoordinates(Point3D p)
Returns the screen coordinates of the passed point.


activateHUD

public void activateHUD(GLAutoDrawable drawable)
Activates a "Head Up Display" for the given drawable.

After calling this method, coordinates retrieved via glRasterPos or getHUDCoordinates can be passed to glVertex and they will be rendered to the correct position.

Every call of this method has to be matched by a call to deactivateHUD.


deactivateHUD

public void deactivateHUD(GLAutoDrawable drawable)
Deactivates the "Head Up Display" and returns to the previous projection settings.

It is an error to call this method before activateHUD has been called. It is also an error not to match a call of activateHUD with a call to this method.


getHUDCoordinates

public Point3D getHUDCoordinates(GLAutoDrawable drawable,
                                 Point3D p)
Returns the HUD-Coordinates of the passed point.

If the passed point lies outside of the viewing area, null is returned.

Before using the retrieved coordinates to draw elements on the screen, activateHUD has to be called.


toCamera

public Vector3D toCamera(GLAutoDrawable drawable,
                         Point3D from)
Returns a vector that points to the camera.

Note that this method is different from calculating a vector from from to getPosition(), since the passed point from is interpreted with respect to the current OpenGL matrix stack. This makes it possible to make multiple calls to glTranslate, glScale, etc. and to then retrieve a vector to the camera without having to transform the local coordinates to world coordinates first.


getViewDirection

public Vector3D getViewDirection()
Returns the view direction of the camera.


getUpDirection

public Vector3D getUpDirection()
Returns the vector in three dimensional space that corresponds to the upward direction in the viewing plane.


setFOV

public void setFOV(float f)
Sets the field of view of this camera in angles.


getFOV

public float getFOV()
Returns the field of view of this camera in angles.


setWidth

public void setWidth(float w)
Sets the width of the camera's viewing plane in pixels.


setHeight

public void setHeight(float h)
Sets the hegiht of the camera's viewing plane in pixels.


getAspectRatio

public float getAspectRatio()
Returns the camaera's aspect ratio.


setClippingPlanes

public void setClippingPlanes(BoundingBox bb)
Adjusts the clipping planes of this camera so that the content of the passed bounding box can be displayed correctly.

If the passed bounding box is collapsed, this method has no effect.


setClippingPlanes

public void setClippingPlanes(float zN,
                              float zF)
Sets the near and far clipping planes to the specified values.


setNearClippingPlane

public void setNearClippingPlane(float near)
Sets the near clipping plane of this camera.


setFarClippingPlane

public void setFarClippingPlane(float far)
Sets the far clipping plane of this camera.


getNearClippingPlane

public float getNearClippingPlane()
Returns the z-value of the near clipping plane.


getFarClippingPlane

public float getFarClippingPlane()
Returns the z-value of the far clipping plane.


setPosition

public void setPosition(Point3D pos)
Sets the position of this camera.

The camera's target remains at the same place.


getPosition

public Point3D getPosition()
Returns the position of the camera.


setTarget

public void setTarget(float x,
                      float y,
                      float z)
Sets the viewing target of this camera to the passed x,y,z coordinates.


setTarget

public void setTarget(Point3D p)
Sets the viewing target of this camera to the passed point.


getTarget

public Point3D getTarget()
Returns the viweing target of this camera.


setRotation

public void setRotation(float x,
                        float y,
                        float z)
Sets the x,y,z rotation of this camera. (In this context, target is the center of the coordinate system that is used for rotation.)


getRotationX

public float getRotationX()
Returns the camera's rotation around the x-axis.


getRotationY

public float getRotationY()
Returns the camera's rotation around the y-axis.


getRotationZ

public float getRotationZ()
Returns the camera's rotation around the z-axis.


setViewDistance

public void setViewDistance(float viewDist)
Sets the view distance of this camera to the target.


getViewDistance

public float getViewDistance()
Returns the distance from this camera to the target.


rotate

public void rotate(float x,
                   float y,
                   float z)
Rotates the camera by the passed angles in degrees.


zoom

public void zoom(float factor)
Moves the camera with respect to it's viewing direction. A factor of 0.1 means getting 10 percent closer to the target, a factor of -0.1 means moving 10 percent farther away from the target.

A factor of greater than 1 is not allowed.


setPerspective

public void setPerspective(float angle)
Sets the field of view of this camera while keeping the viewing area as coherent as possible with the previous setting.

A value of 180 degrees for the parameter angle means an overly perspective projection, whereas a value of 0 degrees means an orthogonal view of the scene.


changePerspective

public void changePerspective(float angle)
Increases or decreases the field of viwe by the given angle while keeping the viewing area as coherent as possible with the previous setting.

When angle is positive, the 'perspectiveness' gets stronger. To compensate for the bigger field of view the camera moves closer to the target.

When angle is negative, the 'perspectiveness' gets waeker. To comensate for the smaller field of view the camera moves further away from the target.

Note that repeatedly calling this method with small angle-steps leads to the famous 'Hitchcock'-effect.

Parameters:
angle -

toString

public String toString()