Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在OpenGL iOS中基于设备位置设置CMRotationMatrix_Ios_Opengl Es_Accelerometer_Core Motion - Fatal编程技术网

如何在OpenGL iOS中基于设备位置设置CMRotationMatrix

如何在OpenGL iOS中基于设备位置设置CMRotationMatrix,ios,opengl-es,accelerometer,core-motion,Ios,Opengl Es,Accelerometer,Core Motion,我正在开发一个带有coremotion功能的OpenGL对象,它将在设备移动时旋转对象。我用设备运动的cmrotationmatrix来计算旋转。 它对设备的移动效果很好,当设备平放在桌子上时也会显示为直线。但如果我在开始时改变设备的角度,它会显示为弯曲。因此,可以使对象在设备的任何角度显示为直线。如果有人找到解决方案,请回复 CMDeviceMotion *deviceMotion = self.motionManager.deviceMotion; float deviceOrien

我正在开发一个带有coremotion功能的OpenGL对象,它将在设备移动时旋转对象。我用设备运动的cmrotationmatrix来计算旋转。 它对设备的移动效果很好,当设备平放在桌子上时也会显示为直线。但如果我在开始时改变设备的角度,它会显示为弯曲。因此,可以使对象在设备的任何角度显示为直线。如果有人找到解决方案,请回复

  CMDeviceMotion *deviceMotion = self.motionManager.deviceMotion;
  float deviceOrientationRadians = 0.0f;
  deviceOrientationRadians = M_PI_2;
  GLKMatrix4 baseRotation = 
      GLKMatrix4MakeRotation(deviceOrientationRadians, 0.0f, 0.0f, 1.0f);
  CMRotationMatrix a = deviceMotion.attitude.rotationMatrix;
  deviceMotionAttitudeMatrix
    = GLKMatrix4Make(a.m11, a.m21, a.m31, 0.0f,
                     a.m12, a.m22, a.m32, 0.0f,
                     a.m13, a.m23, a.m33, 0.0f,
                     0.0f,  0.0f,  0.0f,  1.0f);

   deviceMotionAttitudeMatrix = 
      GLKMatrix4Multiply(baseRotation, deviceMotionAttitudeMatrix);

你所说的弯曲是什么意思?实际上物体位于侧面,这意味着我可以看到侧面视图而不是正面视图。如果想看到正面,我必须将设备平放在桌子上,或者我必须触摸并旋转。