title: cameranode rotate as iOS device moving
body: <p>It's 360 degree video player project. </p>
  
  <p>I add a cameranode(<code>SCNNode</code>) to a rootnode, the cameranode was put at the center(0,0,0) of the <code>SCNSphere</code>, It can play video by now. </p>
  
  <p>Now I have to use devicemotion. I need to rotate the camera when device moves. Not just rotate a certain angle. (Not just device move, When I'm holding a device, my moving regard as the device moving. because I found if I use <code>deviceMotion.attitude.roll</code>, the cameranode only moves when device moves by itself, not when I circle around with device)</p>
  
  <p>When device is located in (x1,y1,z1) position, the cameranode would rotate as the device moving, and when the device located in (x1,y1,z1) position again, the view should be as same as the last we left.</p>
  
  <p>Here's what I've done:</p>
  
  <pre><code>if (self.motionManager.gyroAvailable) {
          self.motionManager.gyroUpdateInterval = 1.0/60.0;
          [self.motionManager startGyroUpdatesToQueue:self.queue withHandler:^(CMGyroData *gyroData, NSError *error){
              if (error) {
                  [self.motionManager stopGyroUpdates];
                  NSLog(@"Gyroscope encountered error:%@",error);
              }else {
                  CGFloat tempX = 0;
                  CGFloat tempY = 0;
                  CGFloat tempZ = 0;
                  if ((fabs(gyroData.rotationRate.y)/60) &gt; 0.002) {
                      tempY = gyroData.rotationRate.y/60;
                  }
                  tempX = gyroData.rotationRate.x/60;
                  tempZ = gyroData.rotationRate.z/60;
                  [self.cameraNode runAction:[SCNAction rotateByX:-tempY y:tempX z:tempZ duration:0]];
              }
          }];
      }else {
          NSLog(@"This device has no gyroscope");
      }
  </code></pre>
  
  <p>The math could be wrong, I don't know why would I divide 60, but it seems the nearest value I need when I use <code>[self.cameraNode runAction:[SCNAction rotateByX:-tempY y:tempX z:tempZ duration:0]];</code></p>
  
  <p>Here's the problem?</p>
  
  <ol>
  <li>which data should I use? </li>
  </ol>
  
  <p><code>CMGyroData</code> or <code>CMDeviceMotion</code>. If use <code>CMDeviceMotion</code>, which specific value should I use? <code>deviceMotion.attitude</code>, <code>deviceMotion.attitude.quaternion</code>, <code>deviceMotion.gravity</code></p>
  
  <ol start="2">
  <li>which is the right method to rotate a cameranode? There are many methods, I'm not sure.</li>
  </ol>
  
  <p><code>+ (SCNAction *)rotateByX:(CGFloat)xAngle y:(CGFloat)yAngle z:(CGFloat)zAngle duration:(NSTimeInterval)duration;</code></p>
  
  <p><code>+ (SCNAction *)rotateToX:(CGFloat)xAngle y:(CGFloat)yAngle z:(CGFloat)zAngle duration:(NSTimeInterval)duration;</code></p>