Skip to content

Commit

Permalink
switch back rotation order to avoid change in upvector
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Mar 12, 2023
1 parent 11313dc commit 4de5fa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/camera/camera3d.jl
Expand Up @@ -537,8 +537,10 @@ function _rotate_cam!(scene, cam::Camera3D, angles::VecTypes, from_mouse=false)
rotation = Quaternionf(0, 0, 0, 1)
if !xor(fix_x, fix_y, fix_z)
# if there are more or less than one restriction apply all rotations
rotation *= qrotation(x_axis, angles[1])
# Note that the y rotation needs to happen first here so that
# fixed_axis = true actually keeps the the axis fixed.
rotation *= qrotation(y_axis, angles[2])
rotation *= qrotation(x_axis, angles[1])
rotation *= qrotation(z_axis, angles[3])
else
# apply world space restrictions
Expand All @@ -557,8 +559,8 @@ function _rotate_cam!(scene, cam::Camera3D, angles::VecTypes, from_mouse=false)
)
else
# restrict total quaternion rotation to one axis
rotation *= qrotation(x_axis, angles[1])
rotation *= qrotation(y_axis, angles[2])
rotation *= qrotation(x_axis, angles[1])
rotation *= qrotation(z_axis, angles[3])
# the first three components are related to rotations around the x/y/z-axis
rotation = Quaternionf(rotation.data .* (fix_x, fix_y, fix_z, 1))
Expand Down
8 changes: 4 additions & 4 deletions test/events.jl
Expand Up @@ -218,15 +218,15 @@ Base.:(==)(l::Or, r::Or) = l.left == r.left && l.right == r.right
# 2) Outside scene, in drag
e.mouseposition[] = (1000, 450)
@test cc.lookat[] Vec3f(0)
@test cc.eyeposition[] Vec3f(0.7128954, -4.1037745, 3.106576)
@test cc.upvector[] Vec3f(0.82216865, -0.17919835, 0.54030234)
@test cc.eyeposition[] Vec3f(-2.8912058, -3.8524969, -1.9491514)
@test cc.upvector[] Vec3f(-0.5050875, -0.6730229, 0.5403024)

# 3) not in drag
e.mousebutton[] = MouseButtonEvent(Mouse.left, Mouse.release)
e.mouseposition[] = (400, 250)
@test cc.lookat[] Vec3f(0)
@test cc.eyeposition[] Vec3f(0.7128954, -4.1037745, 3.106576)
@test cc.upvector[] Vec3f(0.82216865, -0.17919835, 0.54030234)
@test cc.eyeposition[] Vec3f(-2.8912058, -3.8524969, -1.9491514)
@test cc.upvector[] Vec3f(-0.5050875, -0.6730229, 0.5403024)



Expand Down

0 comments on commit 4de5fa3

Please sign in to comment.