Re-enable the cyberplanet and stuff.

This reverts commit a4189342e0.
This commit is contained in:
Joe Ardent 2023-02-22 17:10:36 -08:00
parent 87d9d737d6
commit 4e6fab5952
6 changed files with 46 additions and 49 deletions

View File

@ -43,9 +43,7 @@ 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();
// flatland rapier_config.gravity = xform.translation.normalize() * -settings.gravity;
//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;
} }
@ -85,9 +83,7 @@ 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,10 +24,6 @@ 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 = Vec3::Y; let up = bike_xform.translation.normalize();
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,20 +74,17 @@ 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) {
app.insert_resource(ClearColor(Color::rgb(0.408, 0.6236, 0.925))); #[cfg(feature = "inspector")]
{ {
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;
@ -100,5 +97,9 @@ 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(20.0, 100.0, 20.0), transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.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(-20.0, 100.0, -20.0), transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.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,9 +1,15 @@
use bevy::prelude::{shape::Plane, *}; use bevy::{
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 = 600.0; pub const PLANET_RADIUS: f32 = 6000.0;
#[derive(Component)] #[derive(Component)]
pub struct CyberPlanet; pub struct CyberPlanet;
@ -13,23 +19,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::rgba(0.7, 0.7, 0.8, 0.3); let color = Color::rgb(0.2, 0.1, 0.2);
let plane = Plane { let isphere = Icosphere {
size: PLANET_RADIUS, radius: PLANET_RADIUS,
subdivisions: 88,
}; };
//let (mesh, shape) = gen_planet(plane);
let mesh = Mesh::from(plane); let (mesh, shape) = gen_planet(isphere);
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: 0.8, coefficient: 1.2,
..Default::default() ..Default::default()
}, },
Restitution::new(0.0), Restitution::new(0.8),
); );
commands commands
@ -61,8 +67,7 @@ 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| {
@ -81,7 +86,7 @@ fn gen_planet(sphere: Plane) -> (Mesh, Collider) {
.raw_points() .raw_points()
.iter() .iter()
.map(|&p| { .map(|&p| {
let disp = noise.get(p.as_dvec3().into()) as f32 * 0.05; let disp = noise.get(p.as_dvec3().into()) as f32 * 0.04;
let pt = p + (p.normalize() * disp); let pt = p + (p.normalize() * disp);
pt.into() pt.into()
}) })
@ -115,4 +120,3 @@ fn gen_planet(sphere: Plane) -> (Mesh, Collider) {
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs); mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
(mesh, shape) (mesh, shape)
} }
*/