I'm getting accelerometer data 10x/second from an external device and I want to have that be reflected on a 3-D SceneKit model. That is, I want the model to rotate in response to the accelerometer data. The 3-D model is a .dae file built in SketchUp that I'm loading into the SceneKit scene.
I'm currently trying to make a rotation on the SceneKit scene's root node (here self
refers to a custom SCNView
class):
self.scene.rootNode.transform = CATransform3DMakeRotation(angle, x, y, z);
There's a couple problems with this:
- It's not rotating a specific amount along each axis, it's rotating a fixed amount along a certain vector. Is it possible to manipulate how many degrees a certain axis rotates by changing the relative vector values? Would it make sense to implement a transform with three
CATransform3DRotate
s, one for each axis? - It creates a new rotation every time instead of only rotating the difference in angles from the last reading. For example, if the accel data was
x: 60˚, y: 40˚, y: -30˚
last reading and is nowx: 65˚, y: 45˚, y: -35˚
, the model will rotate the full 65˚ along the x-axis, not just the 5˚ difference from last time (as it should). This seems easily fixable by subtracting the last reading from the current reading, but I'm not sure how the math works out with the rotation.