fn daylight_cycle(
    mut sky_mat: ResMut<AtmosphereMat>,
    mut query: Query<(&mut Transform, &mut DirectionalLight), With<Sun>>,
    time: Res<Time>,
) {
    let mut pos = sky_mat.sun_position;
    let t = time.time_since_startup().as_millis() as f32 / 5000.0;
    pos.x = t.sin();
    pos.z = t.cos();
    pos.y = t.sin() * 0.5;
    sky_mat.sun_position = pos;

    if let Some((mut light_trans, mut directional)) = query.single_mut().into() {
        light_trans.rotation = Transform::from_translation(pos)
            .looking_at(Vec3::ZERO, Vec3::Y)
            .rotation;
        directional.illuminance = pos.y.max(0.0).powf(2.0) * 100000.0;
    }
}
// We can edit the SkyMaterial resource and it will be updated automatically, as long as ZephyrPlugin.dynamic is true
We can edit the SkyMaterial resource and it will be updated automatically, as long as ZephyrPlugin.dynamic is true
We can edit the SkyMaterial resource and it will be updated automatically as long as ZephyrPlugin . dynamic is true
fn daylight_cycle(
    mut sky_mat: ResMut<AtmosphereMat>,
    mut query: Query<(&mut Transform, &mut DirectionalLight), With<Sun>>,
    time: Res<Time>,
) {
    let mut pos = sky_mat.sun_position;
    let t = time.time_since_startup().as_millis() as f32 / 5000.0;
    pos.x = t.sin();
    pos.z = t.cos();
    pos.y = t.sin() * 0.5;
    sky_mat.sun_position = pos;
    if let Some((mut light_trans, mut directional)) = query.single_mut().into() {
        light_trans.rotation = Transform::from_translation(pos)
            .looking_at(Vec3::ZERO, Vec3::Y)
            .rotation;
        directional.illuminance = pos.y.max(0.0).powf(2.0) * 100000.0;
    }
}
fn daylight_cycle ( mut sky_mat : ResMut < AtmosphereMat > , mut query : Query < ( & mut Transform , & mut DirectionalLight ) , With < Sun > > , time : Res < Time > , ) { let mut pos = sky_mat . sun_position ; let t = time . time_since_startup ( ) . as_millis ( ) as f32 / 5000.0 ; pos . x = t . sin ( ) ; pos . z = t . cos ( ) ; pos . y = t . sin ( ) * 0.5 ; sky_mat . sun_position = pos ; if let Some ( ( mut light_trans , mut directional ) ) = query . single_mut ( ) . into ( ) { light_trans . rotation = Transform :: from_translation ( pos ) . looking_at ( Vec3 :: ZERO , Vec3 :: Y ) . rotation ; directional . illuminance = pos . y . max ( 0.0 ) . powf ( 2.0 ) * 100000.0 ; } }
We can edit the SkyMaterial resource and it will be updated automatically, as long as ZephyrPlugin.dynamic is true
We can edit the SkyMaterial resource and it will be updated automatically as long as ZephyrPlugin . dynamic is true
sky_mat
ResMut<AtmosphereMat>
query
Query<(&mut Transform, &mut DirectionalLight), With<Sun>>
time
Res<Time>
sky_mat
ResMut<AtmosphereMat>
query
Query<(&mut Transform, &mut DirectionalLight), With<Sun>>
time
Res<Time>