jwo.landserf.gui3d
Class Camera

java.lang.Object
  extended by jwo.landserf.gui3d.Camera

public class Camera
extends Object

A 'camera' that can be moved within a 3D space. Allows different movement types such as hovering and flying. Camera has a 3d location, a direction of view, field of view and a speed. Note that all coordinates are in rendering space, usually around a volume with origin at (0,0,0) and dimensions of +-10.

Version:
2.3, 2nd August, 2006.
Author:
Jo Wood

Constructor Summary
Camera()
          Creates a new camera for transforming a 3d view.
 
Method Summary
 void addCameraListener(CameraListener cameraListener)
          Adds a camera listener to be informed when camera properties change.
 void changeView(float deltaX, float deltaY)
          Changes the camera view.
 void doRoute(float[][] routeCoords)
          Moves the camera along the route defined by the given collection of coordinates.
 float getDistanceSq()
          Reports the current squared distance from the origin.
 float getForwardSpeed()
          Reports the current camera speed in direction of travel.
 float[] getForwardView()
          Reports the 3d view direction vector.
 float getFOV()
          Reports the camera field of view.
 float getHeading()
          Reports the current heading of the camera.
 float getPitch()
          Reports the current pitch of the camera.
 float[] getPosition()
          Reports the current position of the camera.
 float getRotationStyle()
          Reports the rotation style of the camera.
 void move(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu)
          Calculates the new camera position based on movement type and speed.
 void raise(javax.media.opengl.GL gl, float z)
          Raises camera by a given amount.
 void removeCameraListener(CameraListener cameraListener)
          Removes the given camera listener.
 void reset()
          Sets the camera position, orientation, field of view and speed to their default values.
 void setAspectRatio(float aspectRatio)
          Sets the aspect ratio of the camera view.
 void setForwardSpeed(float speed)
          Sets a new camera speed in direction of travel.
 void setFOV(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, float fov)
          Sets the camera's field of view.
 void setLateralSpeed(float speed)
          Sets a new lateral camera speed (for rotation).
 void setLoop(boolean isLooping)
          Allows a route to be looped if set to true.
 void setMoveCamera(boolean move)
          Controls the changing camera view.
 void setMoveContinuously(boolean isMoving)
          Controls whether the camera moves continuously or not.
 void setPosition(javax.media.opengl.GL gl, javax.media.opengl.glu.GLU glu, float x, float y, float z, float heading, float pitch, float fov)
          Explicitly sets the position and direction of the camera.
 void setRotationStyle(float bankingCoeff)
          Sets the rotation style of the camera.
 void setVerticalDisplacement(float heightChange)
          Sets the vertical displacement of the camera.
 void stopRoute()
          Stops the replay of a route.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Camera

public Camera()
Creates a new camera for transforming a 3d view. Camera is assumed to operate in a space where objects are centred around (x,y,z) = (0,0,0) and scaled around -10 <=x <= 10, -10 <=y < 10, 0 <= z <= -10. The space appears 'upside down' with W boundary being -negative, S boundary being positive and max height being negative.

Method Detail

reset

public void reset()
Sets the camera position, orientation, field of view and speed to their default values.


move

public void move(javax.media.opengl.GL gl,
                 javax.media.opengl.glu.GLU glu)
Calculates the new camera position based on movement type and speed.

Parameters:
gl - OpenGL pipeline.
glu - OpenGL utilities pipeline.

changeView

public void changeView(float deltaX,
                       float deltaY)
Changes the camera view. The type of change will depend on the movement mode. If set to movement, camera speed will be updated, otherwise camera will be rotated.

Parameters:
deltaX - Controls the lateral speed if moving, or the amount of roll and yaw if rotating. Typically controlled by a movement of mouse or controller in the X-direction.
deltaY - Controls the forward speed if moving, or the amount of pitching. Typically controlled by a movement of mouse or controller in the Y-direction.

setPosition

public void setPosition(javax.media.opengl.GL gl,
                        javax.media.opengl.glu.GLU glu,
                        float x,
                        float y,
                        float z,
                        float heading,
                        float pitch,
                        float fov)
Explicitly sets the position and direction of the camera.

Parameters:
gl - OpenGL pipeline.
glu - GL Utilities.
x - X coordinate of camera position in rendering space.
y - Y coordinate of camera position in rendering space.
z - Elevation of camera position in rendering space.
heading - Azimuthal direction of camera view in degrees clockwise from north.
pitch - Pitch of camera view in degrees, where negative is down, 0 horizontal, positive up.
fov - Field of view.

raise

public void raise(javax.media.opengl.GL gl,
                  float z)
Raises camera by a given amount. Negative values indicate downward movement.

Parameters:
gl - OpenGL pipeline.
z - Amount by which to raise camera (render coordinates).

doRoute

public void doRoute(float[][] routeCoords)
Moves the camera along the route defined by the given collection of coordinates. The camera can repeat this trajectory in a loop if setLoop() is set to true. The automatic trajectory can be stopped at any time with a call to stopRoute().

Parameters:
routeCoords - An array of route coordinates. Each row in the array is an array holding {x,y,z,heading,pitch}. (x,y,z) are in rendering coordinates, not geographic.

setLoop

public void setLoop(boolean isLooping)
Allows a route to be looped if set to true.

Parameters:
isLooping - Route will be repeated if true.

stopRoute

public void stopRoute()
Stops the replay of a route.


addCameraListener

public void addCameraListener(CameraListener cameraListener)
Adds a camera listener to be informed when camera properties change. Typically used to update a GUI with camera view and position.

Parameters:
cameraListener - Class listening for camera changes.

removeCameraListener

public void removeCameraListener(CameraListener cameraListener)
Removes the given camera listener.

Parameters:
cameraListener - Camera listener to be removed.

getFOV

public float getFOV()
Reports the camera field of view.

Returns:
Field of view.

setAspectRatio

public void setAspectRatio(float aspectRatio)
Sets the aspect ratio of the camera view. This should be called every time the drawable window changes aspect ratio.

Parameters:
aspectRatio - New aspect ratio.

setFOV

public void setFOV(javax.media.opengl.GL gl,
                   javax.media.opengl.glu.GLU glu,
                   float fov)
Sets the camera's field of view.

Parameters:
gl - OpenGL pipeline.
glu - GL Utilities.
fov - New field of view.

getPosition

public float[] getPosition()
Reports the current position of the camera. Rendering space is a volume with origin (0,0,0) at the centre of the view, and bounds at +10 along each axis.

Returns:
3d vector storing camera position in rendering space.

getDistanceSq

public float getDistanceSq()
Reports the current squared distance from the origin. Rendering space is a volume with origin (0,0,0) at the centre of the view, and bounds at +10 along each axis.

Returns:
Squared distance from the origin in rendering coordinates.

getForwardView

public float[] getForwardView()
Reports the 3d view direction vector.

Returns:
3d view direction.

getPitch

public float getPitch()
Reports the current pitch of the camera. This is a vertical angle in degrees where 0 indicates horizontal, -90 is pointing vertically down and 90 is vertically up.

Returns:
Pitch of camera.

getHeading

public float getHeading()
Reports the current heading of the camera. This is a horizontal angle in degrees where 0 indicates north, 90 is east etc. down and 90 is vertically up.

Returns:
Heading of camera.

setForwardSpeed

public void setForwardSpeed(float speed)
Sets a new camera speed in direction of travel.

Parameters:
speed - New camera speed.

getForwardSpeed

public float getForwardSpeed()
Reports the current camera speed in direction of travel.

Returns:
Current camera speed in direction of travel.

setLateralSpeed

public void setLateralSpeed(float speed)
Sets a new lateral camera speed (for rotation).

Parameters:
speed - New camera speed.

setMoveCamera

public void setMoveCamera(boolean move)
Controls the changing camera view. If on, camera can be moved in space, if off, camera can be rotated instead.

Parameters:
move - Camera will move if true, rotate if false.

setVerticalDisplacement

public void setVerticalDisplacement(float heightChange)
Sets the vertical displacement of the camera.

Parameters:
heightChange - Change in height in rendering coordinates.

setMoveContinuously

public void setMoveContinuously(boolean isMoving)
Controls whether the camera moves continuously or not. Can be used to simulate flying or driving behaviour. This take precedence over setMoveCamera() to allow flying cameras to move and rotate simultaneously.

Parameters:
isMoving - Camera will move continuously if true.

setRotationStyle

public void setRotationStyle(float bankingCoeff)
Sets the rotation style of the camera. If 0, there is no banking when camera changes direction in the azimuthal plane. If -10, steep banking into the azimuthal direction, +10 steep banking away from azimuthal direction.

Parameters:
bankingCoeff - Controls amount and direction of banking with rotation.

getRotationStyle

public float getRotationStyle()
Reports the rotation style of the camera. If 0, there is no banking when camera changes direction in the azimuthal plane. If -10, steep banking into the azimuthal direction, +10 steep banking away from azimuthal direction.

Returns:
Amount and direction of banking with rotation.


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009