objective c - Constant Rotation of a SceneKit Model -


i'm getting accelerometer data 10x/second external device , want have reflected on 3-d scenekit model. is, want model rotate in response accelerometer data. 3-d model .dae file built in sketchup i'm loading scenekit scene.

i'm trying make rotation on scenekit scene's root node (here self refers custom scnview class):

self.scene.rootnode.transform = catransform3dmakerotation(angle, x, y, z);

there's couple problems this:

  • it's not rotating specific amount along each axis, it's rotating fixed amount along vector. possible manipulate how many degrees axis rotates changing relative vector values? make sense implement transform 3 catransform3drotates, 1 each axis?
  • it creates new rotation every time instead of rotating difference in angles last reading. example, if accel data x: 60˚, y: 40˚, y: -30˚ last reading , x: 65˚, y: 45˚, y: -35˚, model rotate full 65˚ along x-axis, not 5˚ difference last time (as should). seems fixable subtracting last reading current reading, i'm not sure how math works out rotation.

if you're getting accelerometer data euler angles (roll, pitch, yaw) already, perhaps should set on node eulerangles property.

also, transforming rootnode if scene isn't great idea — apply rotation whatever node contains model instead.


edit: question suggested had device orientation data in terms of euler angles. if don't have those, might consider using cmdevicemotion them.

even better, device attitude quaternion or rotation matrix , pass node's orientation or transform property. i'm not sure reference frame matches you'll need in app, can transform it.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -