SceneKit – How to rotate a light?

Viewed 102

I am learning SceneKit. And I have a simple scene with a single shape and a light.

Here is the light code:

let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light?.castsShadow = true
lightNode.light?.type = .directional
lightNode.light?.intensity = 1000
lightNode.position = SCNVector3(x: -6, y: 0, z: 30)
lightNode.rotation = SCNVector4(x: 0, y: 0, z: 1.0, w: 3.14 / 2)
scene.rootNode.addChildNode(lightNode)

It produces the following result: enter image description here

When I comment/uncomment lightNode.rotation the result remains the same. However I expect, that this circle highlight at the center of the shape changes or disappears.

1 Answers

You are rotating the directional light around the z-axis and it will have no effect, because your light source is directed along the -Z axis by default. Try rotating your Sun light source around the x-axis or y-axis.

lightNode.rotation = SCNVector4(x: 1, y: 0, z: 0, w: -.pi / 15)

P. S.

There is no sense in using .position for Sun light. For this type of light, only orientation matters.

Related