sunDirection property
Vector3
get
sunDirection
Evaluates the normalized sun direction vector looking towards the sun in the sky.
Implementation
vm.Vector3 get sunDirection {
// Solar angle: 0h = -pi, 6h = -pi/2, 12h = 0, 18h = pi/2, 24h = pi
final solarAngle = (timeOfDay / 24.0) * 2 * math.pi - math.pi;
final latRad = latitude * math.pi / 180.0;
final elevation = math.cos(solarAngle) * math.cos(latRad);
final x = math.sin(solarAngle) * math.cos(latRad);
final z = math.cos(solarAngle) * math.sin(latRad);
final y = elevation;
final dir = vm.Vector3(x, y, z);
return dir.length2 > 0 ? dir.normalized() : vm.Vector3(0, 1, 0);
}