simogl.camera
Class Camera

java.lang.Object
  extended by simogl.camera.Camera

public class Camera
extends java.lang.Object

This class represents the camera. It is pretend to move the camera through the world, but actually the world is moved, when a method to move the camera is called. The camera always stays at the same position. By pressing the specified key, the camera can be switched into an orthographic viewing mode (2D mode).

Author:
Frank Bruns

Constructor Summary
Camera(float x, float y, float z, float heightOverGround, float angle, float near, float far)
          Creates a camera object.
 
Method Summary
 float getAspectRatio()
          Returns the current aspect ratio of the camera (as used in gluPerspective()-method)
 java.util.ArrayList<Triangle> getCollisionTrigs()
          Returns the triangle(s) the camera is actually over
 float getFarPlane()
          Returns the far plane of camera
 float getHeightOverGround()
          Returns the height at that the camera hovers over the ground
 float getNearPlane()
          Returns the near plane of the camera
 Point3D getPosition()
          Returns the current position of the camera as a Point3D object.
 float getRotX()
          Returns the x-rotation of the camera
 float getRotY()
          Returns the y-rotation of the camera
 float getViewingAngle()
          Returns the viewing angle of the camera (as used in gluPerspective()-method)
 boolean isInFreeLook()
          Returns whether the 3D cam is in free look mode or attached to the ground.
 void moveBackward(float amount, long elapsedTime)
          Moves the cam backward by the specified amount
 void moveDown(float amount, long elapsedTime)
          Moves the cam down by the specified amount
 void moveForward(float amount, long elapsedTime)
          Moves the cam forward by the specified amount
 void moveLeft(float amount, long elapsedTime)
          Moves the cam left by the specified amount
 void moveRight(float amount, long elapsedTime)
          Moves the cam right by the specified amount
 void moveUp(float amount, long elapsedTime)
          Moves the cam up by the specified amount
 void rotateDown(float amount, long elapsedTime)
          Rotates the cam down by the specified degrees
 void rotateLeft(float amount, long elapsedTime)
          Rotates the cam left by the specified degrees
 void rotateRight(float amount, long elapsedTime)
          Rotates the cam right by the specified degrees
 void rotateUp(float amount, long elapsedTime)
          Rotates the cam up by the specified degrees
 void setCamPosition(float x, float y, float z)
          Sets the position of the camera
 void setFarPlane(float far)
          Sets the far plane of the camera to the specified value
 void SetHeightOverGround(float height)
           
 void setMouseSensitivity(float sensitivity)
          Sets the mouse sensitivity.
 void setNearPlane(float near)
          Sets the near plane of the camera to the specified value
 void setViewingAngle(float angle)
          Sets the viewing angle of the camera to the specified value.
 void setX(float x)
          Sets the x-coordinate of the camera's position
 void setY(float y)
          Sets the y-coordinate of the camera's position
 void setZ(float z)
          Sets the z-coordinate of the camera's position
 void switchProjectionMode()
          Switches camera from projection mode to ortho mode, or vice versa.
 void toggleFreeLook()
          Switches the movement mode of the camera from planar to free look and vice versa.
 void use(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, float aspect)
          Applies the camera with its current properties.
 void zoomIn2D(float amount)
          Zooms the camera in by the specified amount, if in 2D camera mode
 void zoomOut2D(float amount)
          Zooms the camera out by the specified amount, if in 2D camera mode
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Camera

public Camera(float x,
              float y,
              float z,
              float heightOverGround,
              float angle,
              float near,
              float far)
Creates a camera object. The camera will initially be located at the specified coordinates and be able to look the specified amount of units down the negative z-axis (viewing range).

Parameters:
x - x-coordinate
y - y-coordinate
z - z-coordinate
heightOverGround - specifies the height at that the camera ought to hover over the ground when not in free look mode
angle - the viewing angle of the camera (45f is a good value)
near - the near plane of the camera
far - far plane of the camera
Method Detail

setCamPosition

public void setCamPosition(float x,
                           float y,
                           float z)
Sets the position of the camera

Parameters:
x - x-coordinate
y - y-coordinate
z - z-coordinate

setX

public void setX(float x)
Sets the x-coordinate of the camera's position

Parameters:
x - x-coordinate

setY

public void setY(float y)
Sets the y-coordinate of the camera's position

Parameters:
y - y-coordinate

setZ

public void setZ(float z)
Sets the z-coordinate of the camera's position

Parameters:
z - z-coordinate

getPosition

public Point3D getPosition()
Returns the current position of the camera as a Point3D object.

Note: Don't use the returned object's methods to perform changes on the camera's position. They will have no effect on the camera. Use the camera's setX/Y/Z()- or setCamPosition()-methods to perform position changes.

Returns:
camera position

getRotX

public float getRotX()
Returns the x-rotation of the camera

Returns:
x-rotation of the camera

getRotY

public float getRotY()
Returns the y-rotation of the camera

Returns:
y-rotation of the camera

use

public void use(javax.media.opengl.GL gl,
                javax.media.opengl.glu.GLU glu,
                float aspect)
Applies the camera with its current properties. This method must be called and must be called within the GLEventListener's display()-method.

Parameters:
gl -
glu -
aspect - apect ratio of the display window

setMouseSensitivity

public void setMouseSensitivity(float sensitivity)
Sets the mouse sensitivity. I recommend to use values between 0.01f and 2.0f. But feel free to try some values that are a little greater than that.

Parameters:
sensitivity -

moveForward

public void moveForward(float amount,
                        long elapsedTime)
Moves the cam forward by the specified amount

Parameters:
amount - amount of movement
elapsedTime - time between two frames

moveBackward

public void moveBackward(float amount,
                         long elapsedTime)
Moves the cam backward by the specified amount

Parameters:
amount - amount of movemente
elapsedTime - time between two frames

moveLeft

public void moveLeft(float amount,
                     long elapsedTime)
Moves the cam left by the specified amount

Parameters:
amount - amount of movement
elapsedTime - time between two frames

moveRight

public void moveRight(float amount,
                      long elapsedTime)
Moves the cam right by the specified amount

Parameters:
amount - amount of movement
elapsedTime - time between two frames

moveUp

public void moveUp(float amount,
                   long elapsedTime)
Moves the cam up by the specified amount

Parameters:
amount - amount of movement
elapsedTime - time between two frames

moveDown

public void moveDown(float amount,
                     long elapsedTime)
Moves the cam down by the specified amount

Parameters:
amount - amount of movement
elapsedTime - time between two frames

rotateUp

public void rotateUp(float amount,
                     long elapsedTime)
Rotates the cam up by the specified degrees

Parameters:
amount - amount of movement
elapsedTime - time between two frames

rotateDown

public void rotateDown(float amount,
                       long elapsedTime)
Rotates the cam down by the specified degrees

Parameters:
amount - amount of movement
elapsedTime - time between two frames

rotateLeft

public void rotateLeft(float amount,
                       long elapsedTime)
Rotates the cam left by the specified degrees

Parameters:
amount - amount of movement
elapsedTime - time between two frames

rotateRight

public void rotateRight(float amount,
                        long elapsedTime)
Rotates the cam right by the specified degrees

Parameters:
amount - amount of movement
elapsedTime - time between two frames

switchProjectionMode

public void switchProjectionMode()
Switches camera from projection mode to ortho mode, or vice versa.


zoomIn2D

public void zoomIn2D(float amount)
Zooms the camera in by the specified amount, if in 2D camera mode

Parameters:
amount - amount of zoom

zoomOut2D

public void zoomOut2D(float amount)
Zooms the camera out by the specified amount, if in 2D camera mode

Parameters:
amount - amount of zoom

SetHeightOverGround

public void SetHeightOverGround(float height)

getHeightOverGround

public float getHeightOverGround()
Returns the height at that the camera hovers over the ground

Returns:
height at that the camera hovers over the ground

getFarPlane

public float getFarPlane()
Returns the far plane of camera

Returns:
far plane of the camera

setFarPlane

public void setFarPlane(float far)
Sets the far plane of the camera to the specified value

Parameters:
far - far plane of the camera

getNearPlane

public float getNearPlane()
Returns the near plane of the camera

Returns:
near plane of the camera

setNearPlane

public void setNearPlane(float near)
Sets the near plane of the camera to the specified value

Parameters:
near - near plane of the camera

getAspectRatio

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

Returns:
current aspect ratio of the camera

getViewingAngle

public float getViewingAngle()
Returns the viewing angle of the camera (as used in gluPerspective()-method)

Returns:
viewing angle of the camera

setViewingAngle

public void setViewingAngle(float angle)
Sets the viewing angle of the camera to the specified value. Usually 45f is a good value.

Parameters:
angle - viewing angle for the camera

toggleFreeLook

public void toggleFreeLook()
Switches the movement mode of the camera from planar to free look and vice versa.


isInFreeLook

public boolean isInFreeLook()
Returns whether the 3D cam is in free look mode or attached to the ground.

Returns:
is cam in free look mode? --> yes = true, no = false

getCollisionTrigs

public java.util.ArrayList<Triangle> getCollisionTrigs()
Returns the triangle(s) the camera is actually over

Returns:
triangle(s) on which the camera is over