add point light and use turkey model for toid
This commit is contained in:
parent
7d9651bca0
commit
3bf90ce674
2 changed files with 35 additions and 11 deletions
20
src/lib.rs
20
src/lib.rs
|
@ -1,6 +1,10 @@
|
|||
use argh::FromArgs;
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
prelude::{
|
||||
BuildChildren, ButtonInput, Camera, ChildBuild, Color, Commands, Component, Deref,
|
||||
DerefMut, Entity, Gizmos, Handle, KeyCode, Quat, Query, Res, ResMut, Resource, Scene,
|
||||
SceneRoot, Time, Transform, Vec3, Visibility, With,
|
||||
},
|
||||
utils::{HashMap, HashSet},
|
||||
};
|
||||
use bevy_spatial::{kdtree::KDTree3, SpatialAccess};
|
||||
|
@ -8,12 +12,12 @@ use bevy_spatial::{kdtree::KDTree3, SpatialAccess};
|
|||
pub type NNTree = KDTree3<Toid>;
|
||||
|
||||
// toid stuff
|
||||
const SPEED: f32 = 15.0;
|
||||
const SPEED: f32 = 12.0;
|
||||
const SPEED_DIFF_RANGE: f32 = 0.1; // +/- 10%
|
||||
const MAX_DELTA_V: f32 = std::f32::consts::PI * 2.0; // basically 360 degrees/sec
|
||||
|
||||
// how far from origin before really wanting to come back
|
||||
const RADIUS: f32 = 50.0;
|
||||
const RADIUS: f32 = 30.0;
|
||||
|
||||
// how close to try to stay to your buddies
|
||||
const BUDDY_RADIUS: f32 = SPEED;
|
||||
|
@ -56,7 +60,7 @@ pub fn turkey_time(
|
|||
) -> Entity {
|
||||
let speed_diff = r.gen_range(-SPEED_DIFF_RANGE..=SPEED_DIFF_RANGE);
|
||||
let speed = SPEED + (SPEED * speed_diff);
|
||||
let vel = unit_vec(r) * speed;
|
||||
let dir = unit_vec(r) * speed;
|
||||
let buddies = r.gen_range(6..=8);
|
||||
let x = r.gen_range(-10.0..=10.0);
|
||||
let z = r.gen_range(-10.0..=10.0);
|
||||
|
@ -64,12 +68,16 @@ pub fn turkey_time(
|
|||
let pos = Vec3::new(x, MIN_ALTITUDE + y, z);
|
||||
let xform = Transform::from_translation(pos);
|
||||
let spatial_bundle = (xform, Visibility::Visible);
|
||||
|
||||
let boid_rot = Quat::from_axis_angle(Vec3::Y, -90.0f32.to_radians());
|
||||
|
||||
commands
|
||||
.spawn(spatial_bundle)
|
||||
.insert((Velocity(vel), Buddies::default(), Toid { speed, buddies }))
|
||||
.insert((Velocity(dir), Buddies::default(), Toid { speed, buddies }))
|
||||
.with_children(|t| {
|
||||
t.spawn(SceneRoot(scene.to_owned()))
|
||||
.insert(Transform::default());
|
||||
.insert(Transform::from_rotation(boid_rot));
|
||||
//.insert(Transform::default());
|
||||
})
|
||||
.id()
|
||||
}
|
||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -10,7 +10,14 @@ use bevy_spatial::{AutomaticUpdate, TransformMode};
|
|||
fn main() {
|
||||
let config: audubon::Config = argh::from_env();
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
resolution: (1920.0, 1080.0).into(),
|
||||
..Default::default()
|
||||
}),
|
||||
close_when_requested: true,
|
||||
..Default::default()
|
||||
}))
|
||||
.add_plugins((
|
||||
AutomaticUpdate::<Toid>::new()
|
||||
.with_transform(TransformMode::GlobalTransform)
|
||||
|
@ -44,8 +51,6 @@ fn setup(
|
|||
config: Res<Config>,
|
||||
models: Res<AssetServer>,
|
||||
) {
|
||||
let rand = &mut rand::thread_rng();
|
||||
|
||||
let camera = commands
|
||||
.spawn((
|
||||
Transform::from_xyz(0., 5.0, 25.).looking_at(Vec3::new(0.0, 5.0, 0.0), Vec3::Y),
|
||||
|
@ -53,15 +58,26 @@ fn setup(
|
|||
Visibility::Hidden,
|
||||
))
|
||||
.id();
|
||||
// plane
|
||||
// ground plane
|
||||
commands
|
||||
.spawn(Mesh3d(
|
||||
meshes.add(Mesh::from(Plane3d::default().mesh().size(500.0, 500.0))),
|
||||
))
|
||||
.insert(MeshMaterial3d(materials.add(Color::srgb(0.3, 1.0, 0.3))));
|
||||
|
||||
let toid_model = models.load("models/toid3.glb#Scene0");
|
||||
// point light
|
||||
commands.spawn((
|
||||
Transform::from_xyz(0.0, 50.0, 0.0),
|
||||
PointLight {
|
||||
intensity: 8_000_000.0,
|
||||
range: 100.0,
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
|
||||
let toid_model = models.load("models/boid.glb#Scene0");
|
||||
let rand = &mut rand::thread_rng();
|
||||
for _ in 0..config.toids {
|
||||
let _ = turkey_time(&mut commands, &toid_model, rand);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue