-
How to convert an orientation to a vector? (for a more realistic lens flare)
short version:
How can I convert a layer/light’s orientation into a vector, so I can use vector math on it?
long version:
I’ve got a spotlight in a comp, and as it moves around, sometimes it’s pointing toward the camera, sometimes it turns away. Trapcode Lux lets us see the beam, and I’m using VC Optical Flares to show us the “light source”.
In real life, a lens flare will be brighter if a light is pointing at the camera, and less bright if it’s pointing away. So I’m trying to find a way to calculate the difference in angles between the spotlight orientations and an imaginary line joining the camera and the light. Then, depending on the size of the light cone, I can attenuate the flare brightness.
So far I’ve worked out:
– vector maths seems to be the way to do this, rather than trig
– angle between two vectors can be done with Dan’s helpful snippet of code below
– my first vector is simply (light.position – camera.position)
– the other vector needs to come from the light orientation. But my light is animated with Orientation values rather than a point of interest, as the animation is actually generated in Blender. I could do a hacky thing where I just parent a Null to the light as a sort of reverse-engineered-point-of-interest, but it’s … hacky.So I need to convert the light’s orientation into a (normalisable) vector. How do I do this? Thanks!
angle = radiansToDegrees( Math.acos( dot( normalize(vector1), normalize(vector2) ) ) );