Example #1
0
 function down (x, y, shift) {
   state.dragging = true
   mouseToSphere(x, y, state.clickPos)
   Quat.set(state.clickRot, state.currRot)
   updateCamera()
   if (shift) {
     Vec2.set2(state.clickPosWindow, x, y)
     Vec3.set(state.clickTarget, state.camera.target)
     const targetInViewSpace = Vec3.multMat4(Vec3.copy(state.clickTarget), state.camera.viewMatrix)
     state.panPlane = [targetInViewSpace, [0, 0, 1]]
     Ray.hitTestPlane(
       getViewRay(state.camera, state.clickPosWindow[0], state.clickPosWindow[1], state.width, state.height),
       state.panPlane[0],
       state.panPlane[1],
       state.clickPosPlane
     )
     Ray.hitTestPlane(
       getViewRay(state.camera, state.dragPosWindow[0], state.dragPosWindow[1], state.width, state.height),
       state.panPlane[0],
       state.panPlane[1],
       state.dragPosPlane
     )
   } else {
     state.panPlane = null
   }
 }
Example #2
0
 function move (x, y, shift) {
   if (!state.dragging) {
     return
   }
   if (shift && state.panPlane) {
     Vec2.set2(state.dragPosWindow, x, y)
     Ray.hitTestPlane(
       getViewRay(state.camera, state.clickPosWindow[0], state.clickPosWindow[1], state.width, state.height),
       state.panPlane[0],
       state.panPlane[1],
       state.clickPosPlane
     )
     Ray.hitTestPlane(
       getViewRay(state.camera, state.dragPosWindow[0], state.dragPosWindow[1], state.width, state.height),
       state.panPlane[0],
       state.panPlane[1],
       state.dragPosPlane
     )
     Mat4.set(state.invViewMatrix, state.camera.viewMatrix)
     Mat4.invert(state.invViewMatrix)
     Vec3.multMat4(Vec3.set(state.clickPosWorld, state.clickPosPlane), state.invViewMatrix)
     Vec3.multMat4(Vec3.set(state.dragPosWorld, state.dragPosPlane), state.invViewMatrix)
     const diffWorld = Vec3.sub(Vec3.copy(state.dragPosWorld), state.clickPosWorld)
     const target = Vec3.sub(Vec3.copy(state.clickTarget), diffWorld)
     state.camera({ target: target })
   } else {
     mouseToSphere(x, y, state.dragPos)
     Vec3.set(state.rotAxis, state.clickPos)
     Vec3.cross(state.rotAxis, state.dragPos)
     const theta = Vec3.dot(state.clickPos, state.dragPos)
     Quat.set4(state.dragRot, state.rotAxis[0], state.rotAxis[1], state.rotAxis[2], theta)
     Quat.set(state.currRot, state.dragRot)
     Quat.mult(state.currRot, state.clickRot)
     updateCamera()
   }
 }