File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
src/Externals/spire/arc-ball Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ void ArcBall::drag(const glm::vec2& msc)
6060 glm::vec3 mVSphereNow = mouseOnSphere ((mScreenToTCS * glm::vec4 (msc, 0.0 , 1.0 )).xyz ());
6161
6262 // Construct a quaternion from two points on the unit sphere.
63- glm:: quat mQDrag = quatFromUnitSphere (mVSphereDown , mVSphereNow );
63+ glm::quat mQDrag = quatFromUnitSphere (mVSphereDown , mVSphereNow );
6464 mQNow = mQDrag * mQDown ;
6565 if (glm::dot (mVSphereDown , mVSphereNow ) < 0.0 )
6666 beginDrag (msc);
@@ -77,9 +77,14 @@ void ArcBall::setLocationOnSphere(glm::vec3 location, glm::vec3 up)
7777glm::quat ArcBall::quatFromUnitSphere (const glm::vec3& from, const glm::vec3& to)
7878{
7979 glm::vec3 axis = glm::normalize (glm::cross (from, to));
80+
81+ // Give arbitrary non-zero vector because no rotation
82+ if (std::isnan (axis[0 ]))
83+ axis = from;
84+
8085 float angle = std::acos (glm::dot (from, to));
8186
82- if (angle <= 0.00001 )
87+ if (angle <= 0.00001 || std::isnan (angle) )
8388 return glm::quat (1.0 , 0.0 , 0.0 , 0.0 );
8489
8590 return glm::angleAxis (angle, axis);
You can’t perform that action at this time.
0 commit comments