Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## de.rico.engine.camera
Class Camera

    java.lang.Object
      de.rico.engine.camera.Camera

    public class Camera

extends java.lang.Object

This class represents a camera and is making use of the sigleton design pattern. There can be only one camera object in the application, but that camera object can have several camera perspectives.

Author:
  Frank Bruns

Field Summary
`static float` | `NORMAL_FOV` Normal field of view (viewing angle)
`static float` | `SENSITIVITY` Normal (mouse-)rotation sensitivity factor

Method Summary
`void` | `addCameraPerspective(CameraPerspective setting, int id)` Adds a camera perspective (identified by the id) to the camera.
`void` | `addCameraPerspectives(java.util.LinkedHashMap<java.lang.Integer,CameraPerspective> perspectives)` Adds a map of camera perspectives to the camera.
`void` | `apply(javax.media.opengl.GL gl)` Applies the camera transformations to the scene.
`void` | `clearCameraPerspectives()` Removes all the camera perspectives from this camera.
`float` | `getAspectRatio()` Returns the current aspect ratio of the camera (as used in gluPerspective()-method)
`CameraPerspective` | `getCameraPerspective(int id)` Returns the camera perspective with the specified id, if available, else `null`
`java.util.LinkedList<java.lang.Integer>` | `getCameraPerspectiveIds()` Returns a list with ids of the camera perspectives.
`CameraPerspective` | `getCurrentCamPerspective()` Returns the current camera perspective object
`int` | `getCurrentCamPerspectiveId()` Returns the id of the current camera perspective.
`float` | `getFieldOfView()` Returns the field of view (viewing angle) of the camera (as used in gluPerspective()-method)
`ViewingFrustum` | `getFrustum()` Returns the viewing frustum couppled to the camera
`static Camera` | `getInstance()` Returns the only camera instance according to the singleton design pattern.
`Point3D` | `getPosition()` Returns the position of the camera (as a copy)
`Point3D` | `getRightVector()` Returns the right vector from the camera.
`float` | `getRotX()` Returns the rotation angle of the current camera perspective around the x-axis.
`float` | `getRotY()` Returns the rotation angle around the y-axis of the current camera perspective.
`float` | `getSensitivity()` Returns the current sensitivity factor (mouse-)rotations of the camera.
`Point3D` | `getUpVector()` Returns the up vector of the camera.
`CameraViewPort` | `getViewPort()` Returns the viewport of this camera
`Point3D` | `getViewVector()` Returns the view vector of the camera.
`void` | `init(CameraPerspective perspec, CameraViewPort viewport)` Initializes the camera.
`void` | `moveBackward(float dz)` Moves the camera into backward direction along the z-axis.
`void` | `moveBackward(float dz, long elapsedTime)` Moves the camera into backward direction along the z-axis in a framerate independent way.
`void` | `moveDown(float dy)` Moves the camera into down direction along the y-axis.
`void` | `moveDown(float dy, long elapsedTime)` Moves the camera into down direction along the y-axis in a framerate independent way.
`void` | `moveForeward(float dz)` Moves the camera into foreward direction along the z-axis.
`void` | `moveForeward(float dz, long elapsedTime)` Moves the camera into foreward direction along the z-axis in a framerate independent way.
`void` | `moveLeft(float dx)` Moves the camera to the left along the x-axis.
`void` | `moveLeft(float dx, long elapsedTime)` Moves the camera to the left along the x-axis in a framerate independent way.
`void` | `moveRight(float dx)` Moves the camera to the right along the x-axis.
`void` | `moveRight(float dx, long elapsedTime)` Moves the camera left along the x-axis in a framerate independent way.
`void` | `moveUp(float dy)` Moves the camera into up direction along the y-axis.
`void` | `moveUp(float dy, long elapsedTime)` Moves the camera into up direction along the y-axis in a framerate independent way.
`void` | `removeCameraPerspective(int id)` Remove the camera perspective that is refered to by the specified id.
`void` | `rotateDown(float rot)` Rotates the camera down around the x-axis.
`void` | `rotateLeft(float rot)` Rotates the camera to the left around the y-axis.
`void` | `rotateRight(float rot)` Rotates the camera to the right around the y-axis.
`void` | `rotateUp(float rot)` Rotates the camera up around the x-axis.
`void` | `setAspectRatio(float ratio)` Sets the window's aspect ratio
`void` | `setAttachedToLight(PositionalLightIface light)` Attaches a light object to the camera that implements the PositionalLightIface interface.
`void` | `setCameraViewPort(CameraViewPort viewport)` Sets the viewport of the camera to the specified viewport.
`void` | `setFieldOfView(float angle)` Sets the field of view (viewing angle) of the camera to the specified value.
`void` | `setPosition(Point3D pos)` Sets the position of the camera (current perspective)
`void` | `setRotX(float angleX)` Sets the x-axis rotation angle of the current camera perspective to the specified value.
`void` | `setRotY(float angleY)` Sets the y-axis rotation angle of the current camera perspective to the specified value.
`void` | `setSensitivity(float sensi)` Sets the sensitivity factor for the (mouse-)rotations of the camera.
`void` | `setToCameraPerspective(int id)` Sets which camera perspective shall be enabled

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### NORMAL_FOV

    public static final float NORMAL_FOV

  Normal field of view (viewing angle)

  See Also:
    Constant Field Values

### SENSITIVITY

    public static final float SENSITIVITY

  Normal (mouse-)rotation sensitivity factor

  See Also:
    Constant Field Values

Method Detail

### getInstance

    public static Camera getInstance()

  Returns the only camera instance according to the singleton design pattern.

  Returns:
    singleton camera instance

### init

    public void init(CameraPerspective perspec,
                     CameraViewPort viewport)

  Initializes the camera. The camera will initially be set up with the specified camera perspective. The camera is initialy using a standard field of view (viewing angle) of 45f, which is specified in the Camera.NORMAL_FOV constant, too. Note: This method needs to be called before using the camera.

  Parameters:
    `perspec` - initial camera perspective
    `viewport` - the viewport to use with the camera

### addCameraPerspective

    public void addCameraPerspective(CameraPerspective setting,
                                     int id)

  Adds a camera perspective (identified by the id) to the camera. The camera initially has one perspective which can be refered to by the id 0.

  Parameters:
    `setting` - further camera setting
    `id` - id for identifying the camera perspective

### addCameraPerspectives

    public void addCameraPerspectives(java.util.LinkedHashMap<java.lang.Integer,CameraPerspective> perspectives)

  Adds a map of camera perspectives to the camera.

  Parameters:
    `perspectives` - map of camera perspectives

### clearCameraPerspectives

    public void clearCameraPerspectives()

  Removes all the camera perspectives from this camera. A call to this method even removes the initial base cam perspective. Be careful with that, because the camera always needs to have a perspective with the id 0.
  So, if you call this method make sure you are going to add a perspective with the id 0 after that.

### removeCameraPerspective

    public void removeCameraPerspective(int id)

  Remove the camera perspective that is refered to by the specified id.

  Parameters:
    `id` - id of the camera perspective to remove

### getCameraPerspectiveIds

    public java.util.LinkedList<java.lang.Integer> getCameraPerspectiveIds()

  Returns a list with ids of the camera perspectives.

  Returns:
    list with ids of the camera perspectives

### setToCameraPerspective

    public void setToCameraPerspective(int id)

  Sets which camera perspective shall be enabled

  Parameters:
    `id` - id of the camera perspectve to enable, 0 is the original base camera perspective.

### getCurrentCamPerspectiveId

    public int getCurrentCamPerspectiveId()

  Returns the id of the current camera perspective.

  Returns:
    id of the current camera setting

### getCurrentCamPerspective

    public CameraPerspective getCurrentCamPerspective()

  Returns the current camera perspective object

  Returns:
    current camera perspective object

### getCameraPerspective

    public CameraPerspective getCameraPerspective(int id)

  Returns the camera perspective with the specified id, if available, else `null`

  Parameters:
    `id` - id of the camera perspective
  Returns:
    camera perspective with the specified id

### apply

    public void apply(javax.media.opengl.GL gl)

  Applies the camera transformations to the scene. Needs to be called withing the games draw() method, to get the correct GL context object.

  Parameters:
    `gl` -

### rotateUp

    public void rotateUp(float rot)

  Rotates the camera up around the x-axis. The camera can't rotate up more than 90° at all

  Parameters:
    `rot` - degree of rotation

### rotateDown

    public void rotateDown(float rot)

  Rotates the camera down around the x-axis. The camera can't rotate down more than 90° at all

  Parameters:
    `rot` - degree of rotation

### rotateLeft

    public void rotateLeft(float rot)

  Rotates the camera to the left around the y-axis.

  Parameters:
    `rot` - degree of rotation

### rotateRight

    public void rotateRight(float rot)

  Rotates the camera to the right around the y-axis.

  Parameters:
    `rot` - degree of rotation

### moveForeward

    public void moveForeward(float dz)

  Moves the camera into foreward direction along the z-axis. This method is not framerate independent by nature. To achieve framerate independency you will have to multiply your `dz` parameter by the elapsed time between two frames before passing it over to the method or just call the overloaded method method with the `elapsedTime` parameter.

  Parameters:
    `dz` - change in z direction

### moveForeward

    public void moveForeward(float dz,
                             long elapsedTime)

  Moves the camera into foreward direction along the z-axis in a framerate independent way.

  Parameters:
    `dz` - change in z direction
    `elapsedTime` - time between two frames

### moveBackward

    public void moveBackward(float dz)

  Moves the camera into backward direction along the z-axis. This method is not framerate independent by nature. To achieve framerate independency you will have to multiply your `dz` parameter by the elapsed time between two frames before passing it over to the method or just call the overloaded method method with the `elapsedTime` parameter.

  Parameters:
    `dz` - change in z direction

### moveBackward

    public void moveBackward(float dz,
                             long elapsedTime)

  Moves the camera into backward direction along the z-axis in a framerate independent way.

  Parameters:
    `dz` - change in z direction
    `elapsedTime` - time between two frames

### moveLeft

    public void moveLeft(float dx)

  Moves the camera to the left along the x-axis. This method is not framerate independent by nature. To achieve framerate independency you will have to multiply your `dx` parameter by the elapsed time between two frames before passing it over to the method or just call the overloaded method method with the `elapsedTime` parameter.

  Parameters:
    `dx` - change in x direction

### moveLeft

    public void moveLeft(float dx,
                         long elapsedTime)

  Moves the camera to the left along the x-axis in a framerate independent way.

  Parameters:
    `dx` - change in x direction
    `elapsedTime` - time between two frames

### moveRight

    public void moveRight(float dx)

  Moves the camera to the right along the x-axis. This method is not framerate independent by nature. To achieve framerate independency you will have to multiply your `dx` parameter by the elapsed time between two frames before passing it over to the method or just call the overloaded method method with the `elapsedTime` parameter.

  Parameters:
    `dx` - change in x direction

### moveRight

    public void moveRight(float dx,
                          long elapsedTime)

  Moves the camera left along the x-axis in a framerate independent way.

  Parameters:
    `dx` - change in x direction
    `elapsedTime` - time between two frames

### moveUp

    public void moveUp(float dy)

  Moves the camera into up direction along the y-axis. This method is not framerate independent by nature. To achieve framerate independency you will have to multiply your `dy` parameter by the elapsed time between two frames before passing it over to the method or just call the overloaded method method with the `elapsedTime` parameter.

  Parameters:
    `dy` - change in y direction

### moveUp

    public void moveUp(float dy,
                       long elapsedTime)

  Moves the camera into up direction along the y-axis in a framerate independent way.

  Parameters:
    `dy` - change in y direction
    `elapsedTime` - time between two frames

### moveDown

    public void moveDown(float dy)

  Moves the camera into down direction along the y-axis. This method is not framerate independent by nature. To achieve framerate independency you will have to multiply your `dy` parameter by the elapsed time between two frames before passing it over to the method or just call the overloaded method method with the `elapsedTime` parameter.

  Parameters:
    `dy` - change in y direction

### moveDown

    public void moveDown(float dy,
                         long elapsedTime)

  Moves the camera into down direction along the y-axis in a framerate independent way.

  Parameters:
    `dy` - change in y direction
    `elapsedTime` - time between two frames

### getRotX

    public float getRotX()

  Returns the rotation angle of the current camera perspective around the x-axis.

  Returns:
    x-axis rotation angle

### setRotX

    public void setRotX(float angleX)

  Sets the x-axis rotation angle of the current camera perspective to the specified value.

  Parameters:
    `angleX` - new x-axis rotation angle

### getRotY

    public float getRotY()

  Returns the rotation angle around the y-axis of the current camera perspective.

  Returns:
    y-axis rotation angle

### setRotY

    public void setRotY(float angleY)

  Sets the y-axis rotation angle of the current camera perspective to the specified value.

  Parameters:
    `angleY` - new y-axis rotation angle

### setSensitivity

    public void setSensitivity(float sensi)

  Sets the sensitivity factor for the (mouse-)rotations of the camera. The initial value is Camera.SENSITIVITY. Higher values speed up the rotations and lower values slow them down.

  Parameters:
    `sensi` - sensitivity factor for (mouse-)rotations

### getSensitivity

    public float getSensitivity()

  Returns the current sensitivity factor (mouse-)rotations of the camera.

  Returns:
    sensitivity factor

### getPosition

    public Point3D getPosition()

  Returns the position of the camera (as a copy)

  Returns:
    position of the camera

### setPosition

    public void setPosition(Point3D pos)

  Sets the position of the camera (current perspective)

  Parameters:
    `pos` - position to the the camera to

### setAttachedToLight

    public void setAttachedToLight(PositionalLightIface light)

  Attaches a light object to the camera that implements the PositionalLightIface interface.

  Parameters:
    `light` - positional light to attach (must have implemented the PositionalLightIface interface)

### setAspectRatio

    public void setAspectRatio(float ratio)

  Sets the window's aspect ratio

  Parameters:
    `ratio` - window aspect ration to use for the camera

### getViewPort

    public CameraViewPort getViewPort()

  Returns the viewport of this camera

  Returns:
    viewport of the camera

### setCameraViewPort

    public void setCameraViewPort(CameraViewPort viewport)

  Sets the viewport of the camera to the specified viewport.

  Parameters:
    `viewport` - new viewport for the camera

### getFrustum

    public ViewingFrustum getFrustum()

  Returns the viewing frustum couppled to the camera

  Returns:
    viewing frustum

### getAspectRatio

    public float getAspectRatio()

  Returns the current aspect ratio of the camera (as used in gluPerspective()-method)

  Returns:
    current aspect ratio of the camera

### getFieldOfView

    public float getFieldOfView()

  Returns the field of view (viewing angle) of the camera (as used in gluPerspective()-method)

  Returns:
    field of view (viewing angle) of the camera

### setFieldOfView

    public void setFieldOfView(float angle)

  Sets the field of view (viewing angle) of the camera to the specified value. Usually 45f is a good value, which also is defined in the Camera.NORMAL_FOV constant. Smaller values will zoom in the sceen and bigger values will zoom out.

  Parameters:
    `angle` - field of view (viewing angle) for the camera

### getViewVector

    public Point3D getViewVector()

  Returns the view vector of the camera.

  Returns:
    view vector

### getUpVector

    public Point3D getUpVector()

  Returns the up vector of the camera.

  Returns:
    up vector

### getRightVector

    public Point3D getRightVector()

  Returns the right vector from the camera.

  Returns:
    right vector

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD