Constant SceneKit Model Rotation

I get accelerometer data 10 times per second from an external device, and I want this to be reflected in the SceneKit 3D model. That is, I want the model to rotate in response to the accelerometer data. The three-dimensional model is a .dae file created in SketchUp, which I upload to the SceneKit scene.

I'm currently trying to make a rotation at the root of the SceneKit node scene (here selfrefers to a custom class SCNView):

self.scene.rootNode.transform = CATransform3DMakeRotation(angle, x, y, z);

There are a couple of issues with this:

  • It does not rotate a certain amount along each axis, it rotates a fixed amount along a certain vector. Is it possible to manipulate how many degrees rotate on a certain axis by changing relative vector values? Does it make sense to implement a transformation with three CATransform3DRotates, one for each axis?
  • It creates a new rotation every time instead of rotating the difference in angles from the last reading. For example, if the acceleration data was the x: 60˚, y: 40˚, y: -30˚last read and now x: 65˚, y: 45˚, y: -35˚, the model will rotate the full 65˚ along the x axis, and not just the difference 5˚ from the last time (as it should). It seems easy to fix by subtracting the last reading from the current reading, but I'm not sure how the math works with rotation.
+4
1

(roll, pitch, yaw), , node eulerAngles.

, rootNode, , , node .


EDIT: , . , CMDeviceMotion, .

, quaternion node orientation transform. , , , .

+2

Source: https://habr.com/ru/post/1546066/


All Articles