mayakraft / Panorama

Spherical panorama view, iOS
MIT License
649 stars 135 forks source link

Prevent head tilt and scene jitter #41

Open Ketucalibur opened 8 years ago

Ketucalibur commented 8 years ago

Hello, thanks for your great codes.

I uncomment the following codes to prevent head tilt: GLKQuaternion q = GLKQuaternionFromTwoVectors(touchVector, nowVector); //_offsetMatrix = GLKMatrix4Multiply(_offsetMatrix, GLKMatrix4MakeWithQuaternion(q)); // in progress for preventHeadTilt GLKMatrix4 mat = GLKMatrix4Multiply(_offsetMatrix, GLKMatrix4MakeWithQuaternion(q)); _offsetMatrix = GLKMatrix4MakeLookAt(0, 0, 0, -mat.m02, -mat.m12, -mat.m22, 0, 1, 0);

when I pan around the scene directly up or down(i.e. abs(mat.m02) is close to 1), the scene will shake. I try to solve this problem by changing the codes as following: if (fabs(mat.m02) < 0.8) { _offsetMatrix = GLKMatrix4MakeLookAt(0, 0, 0, -mat.m02, -mat.m12, -mat.m22, 0, 1, 0); }

but I think this solution is ugly, and I want to know how to avoid scene jitter more effectively?

Thanks a lot

chrismerron commented 8 years ago

I removed the jitter by removing the first _offsetMatrix assignment: GLKVector3 nowVector = [self vectorFromScreenLocation:[sender locationInView:sender.view] inAttitude:_offsetMatrix]; GLKQuaternion q = GLKQuaternionFromTwoVectors(touchVector, nowVector); // in progress for preventHeadTilt GLKMatrix4 mat = GLKMatrix4Multiply(_offsetMatrix, GLKMatrix4MakeWithQuaternion(q)); _offsetMatrix = GLKMatrix4MakeLookAt(0, 0, 0, -mat.m02, -mat.m12, -mat.m22, 0, 1, 0);

However, when you pan to the bottom of the image it goes a little crazy. Do you have any idea Robby? Awesome piece of work by the way, great implementation of the panoramic view :)