3

I'm aware of the existence of SCNLookAtConstraint in SceneKit. This method, however, is not what I'm looking for.

What I need is able to point the camera at any given moment to a point (not a node) in space.

Having a X, Y, Z in world coordinates, I need the camera to rotate so that it points towards this point.

The points will change over time (meaning different points are being passed to a method, I need to 'jump' from one to the other).

I'd rather skip calculating eulerAngles, some solutions I have seen are based on trig functions and cos(angle) in the denominator. The user is basically free to rotate by dragging the cameraNode.

Any method I'm missing for this in SceneKit?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
David Homes
  • 2,725
  • 8
  • 33
  • 53

2 Answers2

3

It seems to me that using a node as the target is the simplest way to go. If you create an empty node (no geometry or camera or light) it won't be visible, and you'll be able to use the highest available abstractions that the framework offers you. Move the node from point to point, with animation or with abrupt jumps.

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
3

The GLKMatrix4 methods may be of interest here, specifically GLKMatrix4MakeLookAt.

Given an eye position (camera), a position you wish to look at, and an up vector you will be able to create a transformation matrix (as a GLKMatrix4). The SceneKit function SCNMatrix4FromGLKMatrix4 will then translate this to a SCNMatrix4 that you can set as the transform of your camera node.

TBH, I would probably go with Hal's solution.

lock
  • 2,861
  • 1
  • 13
  • 20