Created
July 18, 2014 10:34
-
-
Save SimonDanisch/8be35b2ac9dd90e3fbac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function movecam{T}(state0::Rotatable{T}, state1::Rotatable{T}) | |
xangle = state0.xangle - state1.xangle #get the difference from the previous state | |
yangle = state0.yangle - state1.yangle | |
zoom = state0.zoom - state1.zoom | |
dir = state0.position - state1.lookat | |
right = unit(cross(dir, state1.up)) | |
xrotation = rotate2(deg2rad(xangle), state1.up) #rotation matrix around up | |
yrotation = rotate2(deg2rad(yangle), right) | |
zoomdir = unit(dir)*zoom #zoom just shortens the direction vector | |
pos1 = Vector3(yrotation * xrotation * [(state0.position-zoomdir)...]) | |
Rotatable(pos1, state1.lookat, state1.up, state1.xangle, state1.yangle, state1.zoom) | |
end | |
function rotate2{T}(angle::T, axis::Vector3{T}) | |
rotationmatrix(qrotation(convert(Array, axis), angle)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment