0
\$\begingroup\$

I am working on getting my directional lights to match the sun in my atmospheric scattering shader.

I have a float that ranges from 0 to 6.28 (TwoPi). How would I calculate a vector3 from this angle?

The reason I need an angle is because my light angle is created like this:

LookAt(new Vector3(100, 100, 100), Vector3.Zero, Vector3.Forward);

Thanks.

\$\endgroup\$
1
\$\begingroup\$

The angle is an angle in 2D plane, correct? Then you need simple trigonometry:

Vector3 myVector = new Vector3(Math.cos(angleFloat), Math.sin(angleFloat), 0);

Look at this image. In your case, V = 1. If you need vector in different plane, just switch the axes.

Vector math

Note: The code is in Java, but whatever language you use, it should be very similar.

\$\endgroup\$
2
  • \$\begingroup\$ If I needed to calculate the third element, it would be using Cos, right? \$\endgroup\$
    – carlturtle
    Jul 8 '13 at 7:39
  • 2
    \$\begingroup\$ To non-ambiguously define a vector in 3D space you need 2 variables (like latitude, longitude). So unless you know around which axis this angle is you need more information to define the vector. \$\endgroup\$
    – Roy T.
    Jul 8 '13 at 11:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .