     
     view = vec3.scale @direction, forward
     right = vec3.scale @right, strafe
-    vec3.set @position, dest
+    GLMatrix.vec3.copy dest, @position
     vec3.add view, dest, dest
     vec3.add right, dest, dest
     return dest


class Jax.Camera
  @include Jax.EventEmitter
  LOCAL_VIEW  = vec3.create [0, 0,-1]
  LOCAL_RIGHT = vec3.create [1, 0, 0]
  LOCAL_UP    = vec3.create [0, 1, 0]
  
  constructor: (options) ->
    @rotation = quat4.identity()
    @_position = vec3.create()
    @matrices =
      mv:  mat4.identity()
      imv: mat4.identity()
      p:   mat4.identity()
      n:   mat3.identity()
    @reset()
    @setFixedYawAxis true, vec3.UNIT_Y
    
    @_isValid = false
    @_viewVector = vec3.create()
    @_upVector   = vec3.create()
    @_rightVector= vec3.create()
    
    if options
      @_position = options.position if options.position
      @direction = options.direction if options.direction

  recalculateMatrices: ->
    @validate() unless @isValid()
    @_stale = false
    GLMatrix.mat4.fromRotationTranslation @matrices.mv, @rotation, @position
    GLMatrix.mat4.invert @matrices.imv, @matrices.mv
    GLMatrix.mat3.fromMat4 @matrices.n, @matrices.imv
    GLMatrix.mat3.transpose @matrices.n, @matrices.n
    @fireEvent 'matrixUpdated'
  
  validate: () ->
    @_isValid = true
    @_viewVector  = GLMatrix.vec3.transformQuat @_viewVector,  LOCAL_VIEW,  @rotation
    @_rightVector = GLMatrix.vec3.transformQuat @_rightVector, LOCAL_RIGHT, @rotation
    @_upVector    = GLMatrix.vec3.transformQuat @_upVector,    LOCAL_UP,    @rotation
    
  setFixedYawAxis: (useFixedYaw, axis) ->
    @_fixedYaw = useFixedYaw
