     @_frustum
 
     
-  _dirVec = vec3.create()
-  _dirRightVec = vec3.create()
-  _dirUpVec = vec3.create()
-  _dirQuat = quat4.create()
+  _dirVec = GLMatrix.vec3.create()
+  _dirRightVec = GLMatrix.vec3.create()
+  _dirUpVec = GLMatrix.vec3.create()
+  _dirQuat = GLMatrix.quat.create()
   @define 'direction',
     get: ->
       @validate() unless @isValid()
       @_viewVector
     set: (dir) ->
-      vec = vec3.set dir, _dirVec
-      vec3.normalize vec
+      vec = GLMatrix.vec3.copy _dirVec, dir
+      GLMatrix.vec3.normalize vec, vec
       if @_fixedYaw
         # FIXME why am I negating? Can't remember...
-        vec3.negate vec
-        right = vec3.normalize vec3.cross @_fixedYawAxis, vec, _dirRightVec
-        up    = vec3.normalize vec3.cross vec, right, _dirUpVec
-        quat4.fromAxes vec, right, up, @rotation
+        GLMatrix.vec3.negate vec, vec
+        right = GLMatrix.vec3.normalize _dirRightVec, GLMatrix.vec3.cross _dirRightVec, @_fixedYawAxis, vec
+        up    = GLMatrix.vec3.normalize _dirUpVec,    GLMatrix.vec3.cross _dirUpVec,    vec, right
+        GLMatrix.quat.setAxes @rotation, vec, right, up
       else
-        rotquat = vec3.rotationTo @direction, vec, _dirQuat
-        quat4.multiply rotquat, @rotation, @rotation
-      quat4.normalize @rotation
+        rotquat = GLMatrix.rotationTo _dirQuat, @direction, vec
+        GLMatrix.quat.multiply @rotation, rotquat, @rotation
+      GLMatrix.quat.normalize @rotation, @rotation
       @invalidate()
       @fireEvent 'updated'
     

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


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