2021-11-06 05:32:55 +00:00
|
|
|
use bevy::prelude::*;
|
2022-01-03 07:35:59 +00:00
|
|
|
use cyber_rider::flycam::{MovementSettings, PlayerPlugin, PLANET_RADIUS};
|
2022-01-07 07:58:38 +00:00
|
|
|
use heron::prelude::*;
|
2021-11-06 05:32:55 +00:00
|
|
|
|
2022-01-07 07:58:38 +00:00
|
|
|
const LIGHT_RANGE: f32 = PLANET_RADIUS * 0.6;
|
2022-01-03 07:35:59 +00:00
|
|
|
const LIGHT_DIST: f32 = PLANET_RADIUS * 1.2;
|
2021-11-06 05:32:55 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-12-20 07:11:23 +00:00
|
|
|
App::new()
|
2021-11-06 05:32:55 +00:00
|
|
|
.insert_resource(Msaa { samples: 4 })
|
|
|
|
.add_plugins(DefaultPlugins)
|
|
|
|
.add_plugin(PlayerPlugin)
|
2022-01-07 07:58:38 +00:00
|
|
|
.add_plugin(PhysicsPlugin::default())
|
2021-11-06 05:32:55 +00:00
|
|
|
.insert_resource(MovementSettings {
|
2022-01-03 07:35:59 +00:00
|
|
|
sensitivity: 0.3, // default: 1.0
|
2021-12-25 02:07:09 +00:00
|
|
|
accel: 20.0, // default: 40.0
|
2022-01-07 08:45:05 +00:00
|
|
|
drag: 0.01, // default: 0.0005
|
2021-12-25 02:07:09 +00:00
|
|
|
gravity: 10.0, // default: 10.0
|
2021-11-06 05:32:55 +00:00
|
|
|
})
|
2021-12-20 07:11:23 +00:00
|
|
|
.add_startup_system(setup.label("world"))
|
|
|
|
.add_startup_system(disable_cursor.after("world"))
|
|
|
|
.add_system(animate_lights)
|
|
|
|
.add_system(bevy::input::system::exit_on_esc_system)
|
2021-11-06 05:32:55 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-12-20 07:11:23 +00:00
|
|
|
fn disable_cursor(mut windows: ResMut<Windows>) {
|
|
|
|
let window = windows.get_primary_mut().unwrap();
|
|
|
|
window.set_cursor_lock_mode(false);
|
|
|
|
window.set_cursor_visibility(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
struct Animate;
|
|
|
|
|
2021-11-06 05:32:55 +00:00
|
|
|
fn setup(
|
|
|
|
mut commands: Commands,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
) {
|
2021-12-20 07:11:23 +00:00
|
|
|
let red_light = PointLight {
|
2022-01-07 07:58:38 +00:00
|
|
|
intensity: 1_000.0,
|
2021-12-20 07:11:23 +00:00
|
|
|
range: LIGHT_RANGE,
|
2021-11-08 07:58:43 +00:00
|
|
|
color: Color::RED,
|
2022-01-07 08:45:05 +00:00
|
|
|
radius: 10.0,
|
2021-11-08 07:58:43 +00:00
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2021-12-20 07:11:23 +00:00
|
|
|
let blue_light = PointLight {
|
2022-01-07 07:58:38 +00:00
|
|
|
intensity: 1_000.0,
|
2021-12-20 07:11:23 +00:00
|
|
|
range: LIGHT_RANGE,
|
2021-11-08 07:58:43 +00:00
|
|
|
color: Color::BLUE,
|
2022-01-07 08:45:05 +00:00
|
|
|
radius: 10.0,
|
2021-11-08 07:58:43 +00:00
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2021-12-20 07:11:23 +00:00
|
|
|
let purple_light = PointLight {
|
2022-01-07 07:58:38 +00:00
|
|
|
intensity: 1_000.0,
|
2021-12-20 07:11:23 +00:00
|
|
|
range: LIGHT_RANGE,
|
2021-11-08 07:58:43 +00:00
|
|
|
color: Color::PURPLE,
|
2022-01-07 08:45:05 +00:00
|
|
|
radius: 10.0,
|
2021-11-08 07:58:43 +00:00
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2021-12-25 02:07:09 +00:00
|
|
|
commands.insert_resource(AmbientLight {
|
2022-01-03 07:35:59 +00:00
|
|
|
color: Color::WHITE,
|
2022-01-07 08:45:05 +00:00
|
|
|
brightness: 0.32,
|
2021-12-25 02:07:09 +00:00
|
|
|
});
|
|
|
|
|
2021-11-08 07:58:43 +00:00
|
|
|
// world
|
2022-01-07 07:58:38 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(PbrBundle {
|
|
|
|
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
|
|
|
radius: PLANET_RADIUS,
|
|
|
|
subdivisions: 6,
|
|
|
|
})),
|
|
|
|
material: materials.add(StandardMaterial {
|
|
|
|
base_color: Color::GRAY,
|
|
|
|
metallic: 0.7,
|
|
|
|
perceptual_roughness: 0.5,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
2021-11-08 07:58:43 +00:00
|
|
|
|
2022-01-07 07:58:38 +00:00
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.insert(RigidBody::Static)
|
|
|
|
.insert(CollisionShape::Sphere {
|
|
|
|
radius: PLANET_RADIUS,
|
|
|
|
});
|
2022-01-03 07:35:59 +00:00
|
|
|
|
2021-11-08 07:58:43 +00:00
|
|
|
// east light
|
2021-12-20 07:11:23 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(PointLightBundle {
|
|
|
|
transform: Transform::from_xyz(LIGHT_DIST, 0.0, 0.0),
|
|
|
|
point_light: purple_light,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.with_children(|builder| {
|
|
|
|
builder.spawn_bundle(PbrBundle {
|
|
|
|
mesh: meshes.add(Mesh::from(shape::UVSphere {
|
|
|
|
radius: 10.0,
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
material: materials.add(StandardMaterial {
|
|
|
|
base_color: Color::PURPLE,
|
|
|
|
emissive: Color::rgba_linear(50.0, 0.0, 50.0, 0.0),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.insert(Animate);
|
|
|
|
|
2021-11-08 07:58:43 +00:00
|
|
|
// west light
|
2021-12-20 07:11:23 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(PointLightBundle {
|
|
|
|
transform: Transform::from_xyz(-LIGHT_DIST, 0.0, 0.0),
|
|
|
|
point_light: purple_light,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.with_children(|builder| {
|
|
|
|
builder.spawn_bundle(PbrBundle {
|
|
|
|
mesh: meshes.add(Mesh::from(shape::UVSphere {
|
|
|
|
radius: 10.0,
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
material: materials.add(StandardMaterial {
|
|
|
|
base_color: Color::PURPLE,
|
|
|
|
emissive: Color::rgba_linear(50.0, 0.0, 50.0, 0.0),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.insert(Animate);
|
2021-11-08 07:58:43 +00:00
|
|
|
// north light
|
2021-12-20 07:11:23 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(PointLightBundle {
|
|
|
|
transform: Transform::from_xyz(0.0, 0.0, LIGHT_DIST),
|
|
|
|
point_light: purple_light,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.with_children(|builder| {
|
|
|
|
builder.spawn_bundle(PbrBundle {
|
|
|
|
mesh: meshes.add(Mesh::from(shape::UVSphere {
|
|
|
|
radius: 10.0,
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
material: materials.add(StandardMaterial {
|
|
|
|
base_color: Color::PURPLE,
|
|
|
|
emissive: Color::rgba_linear(50.0, 0.0, 50.0, 0.0),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.insert(Animate);
|
2021-11-08 07:58:43 +00:00
|
|
|
// south light
|
2021-12-20 07:11:23 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(PointLightBundle {
|
|
|
|
transform: Transform::from_xyz(0.0, 0.0, -LIGHT_DIST),
|
|
|
|
point_light: purple_light,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.with_children(|builder| {
|
|
|
|
builder.spawn_bundle(PbrBundle {
|
|
|
|
mesh: meshes.add(Mesh::from(shape::UVSphere {
|
|
|
|
radius: 10.0,
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
material: materials.add(StandardMaterial {
|
|
|
|
base_color: Color::PURPLE,
|
|
|
|
emissive: Color::rgba_linear(50.0, 0.0, 50.0, 0.0),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.insert(Animate);
|
2021-11-08 07:58:43 +00:00
|
|
|
// up light
|
2021-12-20 07:11:23 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(PointLightBundle {
|
|
|
|
transform: Transform::from_xyz(0.0, LIGHT_DIST, 0.0),
|
|
|
|
point_light: red_light,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.with_children(|builder| {
|
|
|
|
builder.spawn_bundle(PbrBundle {
|
|
|
|
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
|
|
|
radius: 10.0,
|
|
|
|
subdivisions: 2,
|
|
|
|
})),
|
|
|
|
material: materials.add(StandardMaterial {
|
|
|
|
base_color: Color::RED,
|
|
|
|
emissive: Color::rgba_linear(100.0, 0.0, 0.0, 0.0),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
});
|
2021-11-08 07:58:43 +00:00
|
|
|
// down light
|
2021-12-20 07:11:23 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(PointLightBundle {
|
|
|
|
transform: Transform::from_xyz(0.0, -LIGHT_DIST, 0.0),
|
|
|
|
point_light: blue_light,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.with_children(|builder| {
|
|
|
|
builder.spawn_bundle(PbrBundle {
|
|
|
|
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
|
|
|
radius: 10.0,
|
|
|
|
subdivisions: 2,
|
|
|
|
})),
|
|
|
|
material: materials.add(StandardMaterial {
|
|
|
|
base_color: Color::BLUE,
|
|
|
|
emissive: Color::rgba_linear(0.0, 0.0, 100.0, 0.0),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
});
|
|
|
|
});
|
2021-11-08 07:58:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-07 08:45:05 +00:00
|
|
|
fn animate_lights(
|
|
|
|
time: Res<Time>,
|
|
|
|
mut query: Query<&mut Transform, (With<PointLight>, With<Animate>)>,
|
|
|
|
) {
|
|
|
|
let dt = time.delta_seconds();
|
2021-11-08 07:58:43 +00:00
|
|
|
for mut transform in query.iter_mut() {
|
|
|
|
let translation = &transform.translation;
|
|
|
|
let x = translation.x;
|
2021-12-20 07:11:23 +00:00
|
|
|
let y = translation.y;
|
|
|
|
let z = if translation.z.abs() < 0.1 {
|
|
|
|
translation.z + 0.15
|
2021-11-08 07:58:43 +00:00
|
|
|
} else {
|
2021-12-20 07:11:23 +00:00
|
|
|
translation.z
|
2021-11-08 07:58:43 +00:00
|
|
|
};
|
|
|
|
|
2021-12-20 07:11:23 +00:00
|
|
|
// 10 degrees == 0.174533 radians
|
2022-01-07 08:45:05 +00:00
|
|
|
let anim_rate = 0.174533 * dt;
|
2021-12-20 07:11:23 +00:00
|
|
|
let theta = z.atan2(x) + anim_rate;
|
|
|
|
let x_new = LIGHT_DIST * theta.cos();
|
|
|
|
let z_new = LIGHT_DIST * theta.sin();
|
2021-11-08 07:58:43 +00:00
|
|
|
|
2021-12-20 07:11:23 +00:00
|
|
|
*transform = Transform::from_xyz(x_new, y, z_new);
|
2021-11-08 07:58:43 +00:00
|
|
|
}
|
2021-11-06 05:32:55 +00:00
|
|
|
}
|