Skip to content

Commit 7b2bbd1

Browse files
committed
fix an unrelated bug with turntable views aligned to vertical
1 parent 502c80c commit 7b2bbd1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/view.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ void processRotate(glm::vec2 startP, glm::vec2 endP) {
173173
float delTheta = 2.0 * dragDelta.x * moveScale;
174174
float delPhi = 2.0 * dragDelta.y * moveScale;
175175

176+
// Disallow rotations that would almost align the vertical axis
177+
glm::vec3 verticalAxis = getUpVec();
178+
float lim = 0.01f; // controls how close to vertical the view can get
179+
if (glm::dot(frameLookDir, verticalAxis) > 1.0 - lim) {
180+
delPhi = std::min(delPhi, 0.0f);
181+
}
182+
if (glm::dot(frameLookDir, verticalAxis) < -1.0 + lim) {
183+
delPhi = std::max(delPhi, 0.0f);
184+
}
185+
176186
// Translate to center
177187
viewMat = glm::translate(viewMat, view::viewCenter);
178188

0 commit comments

Comments
 (0)