tweaking asteroids

This commit is contained in:
yuni 2024-04-02 05:41:12 +02:00
parent e3e67b0c6f
commit 0e18067024

View file

@ -14,7 +14,7 @@ const STARS_MAX_MAGNITUDE: f32 = 5.5;
const CENTER_WORLD_ON_PLAYER: bool = true;
const ASTEROID_SPAWN_STEP: f64 = 500.0;
const ASTEROID_VIEW_RADIUS: f64 = 1000.0;
const ASTEROID_VIEW_RADIUS: f64 = 3000.0;
const ASSET_ASTEROID1: &str = "models/asteroid.glb#Scene0";
const ASSET_ASTEROID2: &str = "models/asteroid2.glb#Scene0";
@ -193,6 +193,7 @@ fn spawn_despawn_asteroids(
(player.z / ASTEROID_SPAWN_STEP).round() as i64,
);
let mut spawned = 0;
let mut spawned_near = 0;
let mut despawned = 0;
// Parameters
@ -245,31 +246,37 @@ fn spawn_despawn_asteroids(
}
// generate some deterministic pseudorandom numbers seeded with the origin coordinates
let rand_s = (4.0*((origin.x+origin.y+origin.z) as f64).sin()
+ 3.0*((origin.x+origin.y+origin.z) as f64).cos()).abs() % 1.0;
let size: f32 = (rand_s + 1e-6).powf(-0.5) as f32; // -> between ~1 and 1000
if rand_s > 0.7 {
let dist = player_cell.as_dvec3().distance(origin.as_dvec3());
if dist > 4.0 {
continue;
}
spawned_near += 1;
}
let rand_x = (4.0*((origin.x+origin.y) as f64).sin()
+ 3.0*((origin.y+origin.z) as f64).cos()) % 1.0;
let rand_y = (4.0*((origin.y+origin.z) as f64).sin()
+ 3.0*((origin.z+origin.x) as f64).cos()) % 1.0;
let rand_z = (4.0*((origin.z+origin.x) as f64).sin()
+ 3.0*((origin.x+origin.y) as f64).cos()) % 1.0;
let rand_s = (4.0*((origin.x+origin.y+origin.z) as f64).sin()
+ 3.0*((origin.x+origin.y+origin.z) as f64).cos()).abs() % 1.0;
let rand_z = (40.0*((origin.z+origin.x) as f64).sin()
+ 30.0*((origin.x+origin.y) as f64).cos()) % 1.0;
let rand_c = (8.0*((origin.x+origin.z) as f64).sin()
+ 4.0*((origin.x+origin.z) as f64).cos()).abs() % 1.0;
let class = if rand_c < 0.5 { 0 } else { 1 };
//if player_cell.as_dvec3().distance(origin.as_dvec3()) > asteroid.viewdistance
//let max_viewdist = ASTEROID_VIEW_RADIUS / ASTEROID_SPAWN_STEP;
let size: f32 = (rand_s + 1e-6).powf(-0.5) as f32; // -> between ~1 and 1000
let wobble = ASTEROID_SPAWN_STEP * 0.3;
let pos = DVec3::new(
origin.x as f64 * ASTEROID_SPAWN_STEP + wobble * rand_x,
origin.y as f64 * ASTEROID_SPAWN_STEP + wobble * rand_y,
origin.z as f64 * ASTEROID_SPAWN_STEP + wobble * rand_z,
origin.x as f64 * ASTEROID_SPAWN_STEP + wobble * rand_x * 2.0 - 1.0,
origin.y as f64 * ASTEROID_SPAWN_STEP + wobble * rand_y * 2.0 - 1.0,
origin.z as f64 * ASTEROID_SPAWN_STEP + wobble * rand_z * 2.0 - 1.0,
);
dbg!(pos);
// Spawn
dbg!(pos, origin, size);
let mut entity_commands = commands.spawn((
actor::Actor::default(),
RigidBody::Dynamic,
@ -301,7 +308,7 @@ fn spawn_despawn_asteroids(
}
}
if spawned != 0 || despawned != 0 {
log.notice(format!("spawned: {spawned}, despawned: {despawned}"));
log.notice(format!("spawned: {spawned} (near: {spawned_near}), despawned: {despawned}"));
}
}