flatland it

This commit is contained in:
Joe Ardent 2023-02-22 13:46:43 -08:00
parent efb55e5197
commit a4189342e0
6 changed files with 49 additions and 46 deletions

View file

@ -43,7 +43,9 @@ pub(super) fn gravity(
mut rapier_config: ResMut<RapierConfiguration>, mut rapier_config: ResMut<RapierConfiguration>,
) { ) {
let (xform, mut forces) = query.single_mut(); let (xform, mut forces) = query.single_mut();
rapier_config.gravity = xform.translation.normalize() * -settings.gravity; // flatland
//rapier_config.gravity = xform.translation.normalize() * -settings.gravity;
rapier_config.gravity = Vec3::Y * -settings.gravity;
forces.force = Vec3::ZERO; forces.force = Vec3::ZERO;
forces.torque = Vec3::ZERO; forces.torque = Vec3::ZERO;
} }
@ -83,7 +85,9 @@ pub(super) fn falling_cat(
#[cfg(feature = "inspector")] mut debug_instant: ResMut<ActionDebugInstant>, #[cfg(feature = "inspector")] mut debug_instant: ResMut<ActionDebugInstant>,
) { ) {
let (xform, mut forces, mut control_vars) = bike_query.single_mut(); let (xform, mut forces, mut control_vars) = bike_query.single_mut();
let world_up = xform.translation.normalize(); //let world_up = xform.translation.normalize();
// flatland
let world_up = Vec3::Y;
let rot = Quat::from_axis_angle(xform.back(), lean.lean); let rot = Quat::from_axis_angle(xform.back(), lean.lean);
let target_up = rotate_point(&world_up, &rot).normalize(); let target_up = rotate_point(&world_up, &rot).normalize();

View file

@ -24,6 +24,10 @@ pub(super) fn spawn_cyberbike(
let right = xform.right() * 350.0; let right = xform.right() * 350.0;
xform.translation += right; xform.translation += right;
// flatland
let altitude = 10.0;
let xform = Transform::from_translation(Vec3::Y * altitude);
let damping = Damping { let damping = Damping {
angular_damping: 2.0, angular_damping: 2.0,
linear_damping: 0.1, linear_damping: 0.1,

View file

@ -65,7 +65,7 @@ fn follow_cyberbike(
offset: Res<DebugCamOffset>, offset: Res<DebugCamOffset>,
) { ) {
let bike_xform = *query.p0().single(); let bike_xform = *query.p0().single();
let up = bike_xform.translation.normalize(); let up = Vec3::Y;
for (mut cam_xform, cam_type) in query.p1().iter_mut() { for (mut cam_xform, cam_type) in query.p1().iter_mut() {
match *cam_type { match *cam_type {

View file

@ -9,7 +9,7 @@ use crate::{lights::AnimateCyberLightWireframe, planet::CyberPlanet};
pub const BISEXY_COLOR: Color = Color::hsla(292.0, 0.9, 0.60, 1.1); pub const BISEXY_COLOR: Color = Color::hsla(292.0, 0.9, 0.60, 1.1);
fn wireframe_planet( fn _wireframe_planet(
mut commands: Commands, mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut polylines: ResMut<Assets<Polyline>>, mut polylines: ResMut<Assets<Polyline>>,
@ -57,7 +57,7 @@ fn wireframe_planet(
}); });
} }
fn wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) { fn _wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) {
let chance = 0.005; let chance = 0.005;
let rng = &mut thread_rng(); let rng = &mut thread_rng();
@ -74,17 +74,20 @@ fn wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) {
pub struct CyberGlamorPlugin; pub struct CyberGlamorPlugin;
impl Plugin for CyberGlamorPlugin { impl Plugin for CyberGlamorPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
#[cfg(feature = "inspector")] app.insert_resource(ClearColor(Color::rgb(0.408, 0.6236, 0.925)));
{ {
use bevy_rapier3d::render::{ use bevy_rapier3d::render::{
DebugRenderMode, DebugRenderStyle, RapierDebugRenderPlugin, DebugRenderMode, DebugRenderStyle, RapierDebugRenderPlugin,
}; };
let style = DebugRenderStyle { let style = DebugRenderStyle {
multibody_joint_anchor_color: Color::GREEN.as_rgba_f32(), multibody_joint_anchor_color: Color::GREEN.as_rgba_f32(),
multibody_joint_separation_color: Color::GOLD.as_rgba_f32(),
..Default::default() ..Default::default()
}; };
let mode = DebugRenderMode::CONTACTS let mode = DebugRenderMode::CONTACTS
| DebugRenderMode::SOLVER_CONTACTS | DebugRenderMode::SOLVER_CONTACTS
| DebugRenderMode::COLLIDER_SHAPES
| DebugRenderMode::JOINTS | DebugRenderMode::JOINTS
| DebugRenderMode::RIGID_BODY_AXES; | DebugRenderMode::RIGID_BODY_AXES;
@ -97,9 +100,5 @@ impl Plugin for CyberGlamorPlugin {
app.add_plugin(rplugin); app.add_plugin(rplugin);
} }
app.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
.add_system(wireframify_lights)
.add_plugin(PolylinePlugin);
} }
} }

View file

@ -9,8 +9,8 @@ pub const LIGHT_RANGE: f32 = 90.0;
#[derive(Component)] #[derive(Component)]
struct AnimatedCyberLight { struct AnimatedCyberLight {
axis: Vec3, _axis: Vec3,
rate: f32, _rate: f32,
} }
#[derive(Component, Default)] #[derive(Component, Default)]
@ -18,7 +18,7 @@ pub(crate) struct AnimateCyberLightWireframe {
pub wired: bool, pub wired: bool,
} }
fn spawn_moving_lights( fn _spawn_moving_lights(
mut commands: Commands, mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
@ -27,13 +27,13 @@ fn spawn_moving_lights(
// spawn orbiting bisexual lights // spawn orbiting bisexual lights
for _ in 0..655 { for _ in 0..655 {
// mechanics // mechanics
let axis = crate::random_unit_vec(rng); let _axis = crate::random_unit_vec(rng);
let angle = rng.gen_range(0.0..TAU); let angle = rng.gen_range(0.0..TAU);
let rate: f32 = rng.gen_range(7.0..10.0); let _rate: f32 = rng.gen_range(7.0..10.0);
let rate = rate.to_radians(); let _rate = _rate.to_radians();
let rotation = Quat::from_axis_angle(axis, angle); let rotation = Quat::from_axis_angle(_axis, angle);
let altitude = PLANET_RADIUS + rng.gen_range(8.0..20.0); let altitude = PLANET_RADIUS + rng.gen_range(8.0..20.0);
let perp = axis.any_orthonormal_vector(); let perp = _axis.any_orthonormal_vector();
let translation = perp * altitude; let translation = perp * altitude;
let transform = Transform::from_translation(translation); let transform = Transform::from_translation(translation);
@ -59,7 +59,7 @@ fn spawn_moving_lights(
}; };
commands commands
// first, spawn an entity with a transform we can rotate // first, spawn an entity with a transform we can rotate
.spawn((AnimatedCyberLight { axis, rate },)) .spawn((AnimatedCyberLight { _axis, _rate },))
.insert(sbundle) .insert(sbundle)
.with_children(|parent| { .with_children(|parent| {
parent parent
@ -122,7 +122,7 @@ fn spawn_static_lights(
// up light // up light
commands commands
.spawn(PointLightBundle { .spawn(PointLightBundle {
transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0), transform: Transform::from_xyz(20.0, 100.0, 20.0),
point_light: pink_light, point_light: pink_light,
..Default::default() ..Default::default()
}) })
@ -143,7 +143,7 @@ fn spawn_static_lights(
// down light // down light
commands commands
.spawn(PointLightBundle { .spawn(PointLightBundle {
transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.0), transform: Transform::from_xyz(-20.0, 100.0, -20.0),
point_light: blue_light, point_light: blue_light,
..Default::default() ..Default::default()
}) })
@ -163,20 +163,20 @@ fn spawn_static_lights(
}); });
} }
fn orbit_lights(time: Res<Time>, mut query: Query<(&mut Transform, &AnimatedCyberLight)>) { fn _orbit_lights(time: Res<Time>, mut query: Query<(&mut Transform, &AnimatedCyberLight)>) {
let dt = time.delta_seconds(); let dt = time.delta_seconds();
for (mut transform, light) in query.iter_mut() { for (mut transform, light) in query.iter_mut() {
let AnimatedCyberLight { axis, rate } = *light; let AnimatedCyberLight { _axis, _rate } = *light;
let theta = rate * dt; let theta = _rate * dt;
transform.rotation *= Quat::from_axis_angle(axis, theta); transform.rotation *= Quat::from_axis_angle(_axis, theta);
} }
} }
pub struct CyberSpaceLightsPlugin; pub struct CyberSpaceLightsPlugin;
impl Plugin for CyberSpaceLightsPlugin { impl Plugin for CyberSpaceLightsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_startup_system(spawn_static_lights) app.add_startup_system(spawn_static_lights);
.add_startup_system(spawn_moving_lights) //.add_startup_system(spawn_moving_lights)
.add_system(orbit_lights); //.add_system(orbit_lights);
} }
} }

View file

@ -1,15 +1,9 @@
use bevy::{ use bevy::prelude::{shape::Plane, *};
prelude::{shape::Icosphere, *},
render::mesh::Indices,
};
use bevy_rapier3d::prelude::*; use bevy_rapier3d::prelude::*;
use hexasphere::shapes::IcoSphere;
use noise::{HybridMulti, NoiseFn, SuperSimplex};
use wgpu::PrimitiveTopology;
use crate::Label; use crate::Label;
pub const PLANET_RADIUS: f32 = 6000.0; pub const PLANET_RADIUS: f32 = 600.0;
#[derive(Component)] #[derive(Component)]
pub struct CyberPlanet; pub struct CyberPlanet;
@ -19,23 +13,23 @@ fn spawn_planet(
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
let color = Color::rgb(0.2, 0.1, 0.2); let color = Color::rgba(0.7, 0.7, 0.8, 0.3);
let isphere = Icosphere { let plane = Plane {
radius: PLANET_RADIUS, size: PLANET_RADIUS,
subdivisions: 88,
}; };
//let (mesh, shape) = gen_planet(plane);
let (mesh, shape) = gen_planet(isphere); let mesh = Mesh::from(plane);
let shape = Collider::from_bevy_mesh(&mesh, &ComputedColliderShape::TriMesh).unwrap();
let pbody = (RigidBody::Fixed, Ccd { enabled: true }); let pbody = (RigidBody::Fixed, Ccd { enabled: true });
let pcollide = ( let pcollide = (
shape, shape,
Friction { Friction {
coefficient: 1.2, coefficient: 0.8,
..Default::default() ..Default::default()
}, },
Restitution::new(0.8), Restitution::new(0.0),
); );
commands commands
@ -67,7 +61,8 @@ impl Plugin for CyberPlanetPlugin {
// utils // utils
//--------------------------------------------------------------------- //---------------------------------------------------------------------
fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) { /*
fn gen_planet(sphere: Plane) -> (Mesh, Collider) {
// straight-up stolen from Bevy's impl of Mesh from Icosphere, so I can do the // straight-up stolen from Bevy's impl of Mesh from Icosphere, so I can do the
// displacement before normals are calculated. // displacement before normals are calculated.
let generated = IcoSphere::new(sphere.subdivisions, |point| { let generated = IcoSphere::new(sphere.subdivisions, |point| {
@ -86,7 +81,7 @@ fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) {
.raw_points() .raw_points()
.iter() .iter()
.map(|&p| { .map(|&p| {
let disp = noise.get(p.as_dvec3().into()) as f32 * 0.04; let disp = noise.get(p.as_dvec3().into()) as f32 * 0.05;
let pt = p + (p.normalize() * disp); let pt = p + (p.normalize() * disp);
pt.into() pt.into()
}) })
@ -120,3 +115,4 @@ fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) {
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs); mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
(mesh, shape) (mesh, shape)
} }
*/