# Wanted: simple example/explanation of setOrientation

Let’s say I want a directional light illuminating a scene from a certain position. Define an ofLight object, apply the setDirectional() method and define the light source’s position using the setOrientation(const ofQuaternion &q) from the super class ofNode.

I would deeply appreciate an example of quaternion usage to specify the direction of the light source. There are several different constructors in ofQuaternion.h which show alternative formats for building one. One example might be a source coming from a direction defined by a 45-deg rotation around the z-axis (from x-axis towards y-axis) followed by a 45-deg rotation out of the x-y plane towards the z-axis. How would the arguments to setOrientation() look?

Thanks for thoughts brief or deep!

setOrientation (http://openframeworks.cc/documentation/3d/ofNode/#show_setOrientation) can take as argument a vector or a quaternion. Both of them define a rotation. When you pass a vector, the rotation is specified in euler angles. When you pass a quaternion, the rotation is defined as a quaternion. They are 2 different ways to define rotations. Quaternions are more difficult to use, but they help you solving complex problem, I would suggest you this article http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/, it has a simple intro and then it goes more deep into it.

Now, back to your problem, there are different ways to do this. Probably, the easiest solution is to tell your light where to look at, using this method
http://openframeworks.cc/documentation/3d/ofNode/#show_lookAt

``````light.lookAt(yourObject.getGlobalPosition());
``````

Another way is to create a quaternion, and pass it as argument to your setDirection method.
You could create a quaternion from an euler angle, that is easier to think about, for example

``````glm::vec3 rotationEuler = glm::vec3(45, 90, 0); //rotate 45 deg on x, then 90 on y
glm::quat quaternion = glm::quat(rotationEuler);
yourLight.setDirection(quat);
``````

If you want to go for this method, my suggestion is to think where your light is, call `light.draw`, it draws the axis that help you to visualize the actual orientation of the light. The red one is x, the green one is y and the z one is blue. Think about where the object that you want to illuminate is, on which axis do you have to rotate your light to point in the direction of the object? how many degrees should it rotate?

Also, `ofNode` is really handy, in examples/3d/ there is `ofNodeExample`. Have a look at that one

1 Like

edapx: Thanks so much for your very thorough response. I especially appreciate the multiple approaches to study the issue and apply different solutions. I will follow up on your suggestions starting with the openGL tutorial.

Footnote: I’ve seen in some examples the small sphere denoting a light source and/or orientation. The short, RGB-colored axes clearly imply the status of a rotated scene. Your next-to-last paragraph revealed what I should have figured out: RGB maps, in order, to XYZ axes. (Forehead slap.)