parent
87d9d737d6
commit
4e6fab5952
6 changed files with 46 additions and 49 deletions
|
@ -43,9 +43,7 @@ pub(super) fn gravity(
|
|||
mut rapier_config: ResMut<RapierConfiguration>,
|
||||
) {
|
||||
let (xform, mut forces) = query.single_mut();
|
||||
// flatland
|
||||
//rapier_config.gravity = xform.translation.normalize() * -settings.gravity;
|
||||
rapier_config.gravity = Vec3::Y * -settings.gravity;
|
||||
rapier_config.gravity = xform.translation.normalize() * -settings.gravity;
|
||||
forces.force = Vec3::ZERO;
|
||||
forces.torque = Vec3::ZERO;
|
||||
}
|
||||
|
@ -85,9 +83,7 @@ pub(super) fn falling_cat(
|
|||
#[cfg(feature = "inspector")] mut debug_instant: ResMut<ActionDebugInstant>,
|
||||
) {
|
||||
let (xform, mut forces, mut control_vars) = bike_query.single_mut();
|
||||
//let world_up = xform.translation.normalize();
|
||||
// flatland
|
||||
let world_up = Vec3::Y;
|
||||
let world_up = xform.translation.normalize();
|
||||
let rot = Quat::from_axis_angle(xform.back(), lean.lean);
|
||||
let target_up = rotate_point(&world_up, &rot).normalize();
|
||||
|
||||
|
|
|
@ -24,10 +24,6 @@ pub(super) fn spawn_cyberbike(
|
|||
let right = xform.right() * 350.0;
|
||||
xform.translation += right;
|
||||
|
||||
// flatland
|
||||
let altitude = 10.0;
|
||||
let xform = Transform::from_translation(Vec3::Y * altitude);
|
||||
|
||||
let damping = Damping {
|
||||
angular_damping: 2.0,
|
||||
linear_damping: 0.1,
|
||||
|
|
|
@ -65,7 +65,7 @@ fn follow_cyberbike(
|
|||
offset: Res<DebugCamOffset>,
|
||||
) {
|
||||
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() {
|
||||
match *cam_type {
|
||||
|
|
|
@ -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);
|
||||
|
||||
fn _wireframe_planet(
|
||||
fn wireframe_planet(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
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 rng = &mut thread_rng();
|
||||
|
@ -74,20 +74,17 @@ fn _wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) {
|
|||
pub struct CyberGlamorPlugin;
|
||||
impl Plugin for CyberGlamorPlugin {
|
||||
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::{
|
||||
DebugRenderMode, DebugRenderStyle, RapierDebugRenderPlugin,
|
||||
};
|
||||
let style = DebugRenderStyle {
|
||||
multibody_joint_anchor_color: Color::GREEN.as_rgba_f32(),
|
||||
multibody_joint_separation_color: Color::GOLD.as_rgba_f32(),
|
||||
..Default::default()
|
||||
};
|
||||
let mode = DebugRenderMode::CONTACTS
|
||||
| DebugRenderMode::SOLVER_CONTACTS
|
||||
| DebugRenderMode::COLLIDER_SHAPES
|
||||
| DebugRenderMode::JOINTS
|
||||
| DebugRenderMode::RIGID_BODY_AXES;
|
||||
|
||||
|
@ -100,5 +97,9 @@ impl Plugin for CyberGlamorPlugin {
|
|||
|
||||
app.add_plugin(rplugin);
|
||||
}
|
||||
|
||||
app.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet)
|
||||
.add_system(wireframify_lights)
|
||||
.add_plugin(PolylinePlugin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ pub const LIGHT_RANGE: f32 = 90.0;
|
|||
|
||||
#[derive(Component)]
|
||||
struct AnimatedCyberLight {
|
||||
_axis: Vec3,
|
||||
_rate: f32,
|
||||
axis: Vec3,
|
||||
rate: f32,
|
||||
}
|
||||
|
||||
#[derive(Component, Default)]
|
||||
|
@ -18,7 +18,7 @@ pub(crate) struct AnimateCyberLightWireframe {
|
|||
pub wired: bool,
|
||||
}
|
||||
|
||||
fn _spawn_moving_lights(
|
||||
fn spawn_moving_lights(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
|
@ -27,13 +27,13 @@ fn _spawn_moving_lights(
|
|||
// spawn orbiting bisexual lights
|
||||
for _ in 0..655 {
|
||||
// mechanics
|
||||
let _axis = crate::random_unit_vec(rng);
|
||||
let axis = crate::random_unit_vec(rng);
|
||||
let angle = rng.gen_range(0.0..TAU);
|
||||
let _rate: f32 = rng.gen_range(7.0..10.0);
|
||||
let _rate = _rate.to_radians();
|
||||
let rotation = Quat::from_axis_angle(_axis, angle);
|
||||
let rate: f32 = rng.gen_range(7.0..10.0);
|
||||
let rate = rate.to_radians();
|
||||
let rotation = Quat::from_axis_angle(axis, angle);
|
||||
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 transform = Transform::from_translation(translation);
|
||||
|
||||
|
@ -59,7 +59,7 @@ fn _spawn_moving_lights(
|
|||
};
|
||||
commands
|
||||
// first, spawn an entity with a transform we can rotate
|
||||
.spawn((AnimatedCyberLight { _axis, _rate },))
|
||||
.spawn((AnimatedCyberLight { axis, rate },))
|
||||
.insert(sbundle)
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
|
@ -122,7 +122,7 @@ fn spawn_static_lights(
|
|||
// up light
|
||||
commands
|
||||
.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,
|
||||
..Default::default()
|
||||
})
|
||||
|
@ -143,7 +143,7 @@ fn spawn_static_lights(
|
|||
// down light
|
||||
commands
|
||||
.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,
|
||||
..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();
|
||||
for (mut transform, light) in query.iter_mut() {
|
||||
let AnimatedCyberLight { _axis, _rate } = *light;
|
||||
let theta = _rate * dt;
|
||||
transform.rotation *= Quat::from_axis_angle(_axis, theta);
|
||||
let AnimatedCyberLight { axis, rate } = *light;
|
||||
let theta = rate * dt;
|
||||
transform.rotation *= Quat::from_axis_angle(axis, theta);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CyberSpaceLightsPlugin;
|
||||
impl Plugin for CyberSpaceLightsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_startup_system(spawn_static_lights);
|
||||
//.add_startup_system(spawn_moving_lights)
|
||||
//.add_system(orbit_lights);
|
||||
app.add_startup_system(spawn_static_lights)
|
||||
.add_startup_system(spawn_moving_lights)
|
||||
.add_system(orbit_lights);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
use bevy::prelude::{shape::Plane, *};
|
||||
use bevy::{
|
||||
prelude::{shape::Icosphere, *},
|
||||
render::mesh::Indices,
|
||||
};
|
||||
use bevy_rapier3d::prelude::*;
|
||||
use hexasphere::shapes::IcoSphere;
|
||||
use noise::{HybridMulti, NoiseFn, SuperSimplex};
|
||||
use wgpu::PrimitiveTopology;
|
||||
|
||||
use crate::Label;
|
||||
|
||||
pub const PLANET_RADIUS: f32 = 600.0;
|
||||
pub const PLANET_RADIUS: f32 = 6000.0;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct CyberPlanet;
|
||||
|
@ -13,23 +19,23 @@ fn spawn_planet(
|
|||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let color = Color::rgba(0.7, 0.7, 0.8, 0.3);
|
||||
let plane = Plane {
|
||||
size: PLANET_RADIUS,
|
||||
let color = Color::rgb(0.2, 0.1, 0.2);
|
||||
let isphere = Icosphere {
|
||||
radius: PLANET_RADIUS,
|
||||
subdivisions: 88,
|
||||
};
|
||||
//let (mesh, shape) = gen_planet(plane);
|
||||
let mesh = Mesh::from(plane);
|
||||
let shape = Collider::from_bevy_mesh(&mesh, &ComputedColliderShape::TriMesh).unwrap();
|
||||
|
||||
let (mesh, shape) = gen_planet(isphere);
|
||||
|
||||
let pbody = (RigidBody::Fixed, Ccd { enabled: true });
|
||||
|
||||
let pcollide = (
|
||||
shape,
|
||||
Friction {
|
||||
coefficient: 0.8,
|
||||
coefficient: 1.2,
|
||||
..Default::default()
|
||||
},
|
||||
Restitution::new(0.0),
|
||||
Restitution::new(0.8),
|
||||
);
|
||||
|
||||
commands
|
||||
|
@ -61,8 +67,7 @@ impl Plugin for CyberPlanetPlugin {
|
|||
// utils
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
fn gen_planet(sphere: Plane) -> (Mesh, Collider) {
|
||||
fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) {
|
||||
// straight-up stolen from Bevy's impl of Mesh from Icosphere, so I can do the
|
||||
// displacement before normals are calculated.
|
||||
let generated = IcoSphere::new(sphere.subdivisions, |point| {
|
||||
|
@ -81,7 +86,7 @@ fn gen_planet(sphere: Plane) -> (Mesh, Collider) {
|
|||
.raw_points()
|
||||
.iter()
|
||||
.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);
|
||||
pt.into()
|
||||
})
|
||||
|
@ -115,4 +120,3 @@ fn gen_planet(sphere: Plane) -> (Mesh, Collider) {
|
|||
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
|
||||
(mesh, shape)
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue