Flight Club


flightclub.framework3d
Class CameraMan

java.lang.Object
  |
  +--flightclub.framework3d.CameraMan

public class CameraMan
extends java.lang.Object

This class implements camera functionality such as cutting smoothly between different camera subjects and mapping (x, y, z) onto the screen (y_, z_)). The projection from (x, y, z) onto the screen (y_, z_) is determined by two vectors, eye and focus.

Using these two vectors we calculate the rotation and translation needed to position the eye on the (+ve) x_ axis looking towards the focus at origin_. Given a point (x, y, z) we translate it and apply the rotation to get (x_, y_, z_). We then scale the y_ and z_ by 1/x_ to complete the perspective projection by forshortening y_ and z_ according to their distance from the camera.

See Also:
ModelViewer.createCameraMan(), ModelCanvas.paintModel()

Field Summary
static int CUT_LEN
           
protected  float depthOfVision
           
protected  float LENS_ANGLE_INVERSE
          This field tells us how far away from a 1 unit tall object must the camera be in order for it to fill the height of the screen.
protected  ModelViewer modelViewer
           
protected static float ZOOM_STEP
           
 
Constructor Summary
CameraMan(ModelViewer modelViewer)
          Creates a CameraMan.
 
Method Summary
 float getDistance()
           
 float[] getEye()
           
 float[] getFocus()
           
 float[][] getMatrix()
           
 void init()
          Sets the scale according to the canvas height.
 void pullIn()
          Move eye closer to the focus.
 void pullOut()
          Move eye further away from the focus.
 void rotate(float dtheta, float dz)
          Rotates the eye about the focus by dtheta (L/R) and moves the eye up or down by dz.
 void scaleToScreen(float[] v_)
          Scales the y_ and z_ co-ords so a 1 unit tall tree fills the screen height when viewed from a distance of LENS_ANGLE_INVERSE away.
 void setSubject(CameraSubject cameraSubject, boolean track)
          Sets the camera subject.
 void setSubjectNow(CameraSubject cameraSubject, boolean track)
          Sets the camera subject.
 void tick()
          Update camera position, only if we are mid cut or the subject is moving.
 java.lang.String toString()
          Returns a string that may be handy for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

modelViewer

protected ModelViewer modelViewer

depthOfVision

protected float depthOfVision

CUT_LEN

public static final int CUT_LEN
See Also:
Constant Field Values

LENS_ANGLE_INVERSE

protected float LENS_ANGLE_INVERSE
This field tells us how far away from a 1 unit tall object must the camera be in order for it to fill the height of the screen. Of course, we measure the lens angle in radians.


ZOOM_STEP

protected static final float ZOOM_STEP
See Also:
Constant Field Values
Constructor Detail

CameraMan

public CameraMan(ModelViewer modelViewer)
Creates a CameraMan.

Parameters:
modelViewer - an instance of ModelViewer.
Method Detail

init

public void init()
Sets the scale according to the canvas height. Do not call this method until the ModelCanvas knows how big it is.


tick

public void tick()
Update camera position, only if we are mid cut or the subject is moving.

See Also:
ModelViewer.tick(float, float)

setSubject

public void setSubject(CameraSubject cameraSubject,
                       boolean track)
Sets the camera subject. The camera will gradually move to its new position over CUT_LEN ticks.

Parameters:
cameraSubject - the subject to film.
track - if true then track the subject as it moves.

setSubjectNow

public void setSubjectNow(CameraSubject cameraSubject,
                          boolean track)
Sets the camera subject. The camera moves immediately to the new position defined by the subject.


getDistance

public float getDistance()

getMatrix

public float[][] getMatrix()

getFocus

public float[] getFocus()

getEye

public float[] getEye()

rotate

public void rotate(float dtheta,
                   float dz)
Rotates the eye about the focus by dtheta (L/R) and moves the eye up or down by dz.


scaleToScreen

public final void scaleToScreen(float[] v_)
Scales the y_ and z_ co-ords so a 1 unit tall tree fills the screen height when viewed from a distance of LENS_ANGLE_INVERSE away.

Also translates y_ and z_ so that (x_, 0, 0) appears center screen.

See Also:
Obj3d.transform()

pullIn

public void pullIn()
Move eye closer to the focus.


pullOut

public void pullOut()
Move eye further away from the focus.


toString

public java.lang.String toString()
Returns a string that may be handy for debugging.

Overrides:
toString in class java.lang.Object

Dan Burton <danb@dircon.co.uk> | latest update: 20 Sep 2002;