From 4de5fa3b2e7760c693b3561b33c5c09d46688d2a Mon Sep 17 00:00:00 2001 From: ffreyer Date: Mon, 13 Mar 2023 00:15:11 +0100 Subject: [PATCH] switch back rotation order to avoid change in upvector --- src/camera/camera3d.jl | 6 ++++-- test/events.jl | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/camera/camera3d.jl b/src/camera/camera3d.jl index ff449803b9f..4c3ad8cd28d 100644 --- a/src/camera/camera3d.jl +++ b/src/camera/camera3d.jl @@ -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 @@ -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)) diff --git a/test/events.jl b/test/events.jl index 657242025b8..464fa170627 100644 --- a/test/events.jl +++ b/test/events.jl @@ -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)