flatland it
This commit is contained in:
parent
efb55e5197
commit
a4189342e0
6 changed files with 49 additions and 46 deletions
|
@ -43,7 +43,9 @@ pub(super) fn gravity(
|
|||
mut rapier_config: ResMut<RapierConfiguration>,
|
||||
) {
|
||||
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.torque = Vec3::ZERO;
|
||||
}
|
||||
|
@ -83,7 +85,9 @@ 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();
|
||||
//let world_up = xform.translation.normalize();
|
||||
// flatland
|
||||
let world_up = Vec3::Y;
|
||||
let rot = Quat::from_axis_angle(xform.back(), lean.lean);
|
||||
let target_up = rotate_point(&world_up, &rot).normalize();
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@ 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 = bike_xform.translation.normalize();
|
||||
let up = Vec3::Y;
|
||||
|
||||
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,17 +74,20 @@ fn wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) {
|
|||
pub struct CyberGlamorPlugin;
|
||||
impl Plugin for CyberGlamorPlugin {
|
||||
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::{
|
||||
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;
|
||||
|
||||
|
@ -97,9 +100,5 @@ 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(0.0, PLANET_RADIUS + 30.0, 0.0),
|
||||
transform: Transform::from_xyz(20.0, 100.0, 20.0),
|
||||
point_light: pink_light,
|
||||
..Default::default()
|
||||
})
|
||||
|
@ -143,7 +143,7 @@ fn spawn_static_lights(
|
|||
// down light
|
||||
commands
|
||||
.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,
|
||||
..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,15 +1,9 @@
|
|||
use bevy::{
|
||||
prelude::{shape::Icosphere, *},
|
||||
render::mesh::Indices,
|
||||
};
|
||||
use bevy::prelude::{shape::Plane, *};
|
||||
use bevy_rapier3d::prelude::*;
|
||||
use hexasphere::shapes::IcoSphere;
|
||||
use noise::{HybridMulti, NoiseFn, SuperSimplex};
|
||||
use wgpu::PrimitiveTopology;
|
||||
|
||||
use crate::Label;
|
||||
|
||||
pub const PLANET_RADIUS: f32 = 6000.0;
|
||||
pub const PLANET_RADIUS: f32 = 600.0;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct CyberPlanet;
|
||||
|
@ -19,23 +13,23 @@ fn spawn_planet(
|
|||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
let color = Color::rgb(0.2, 0.1, 0.2);
|
||||
let isphere = Icosphere {
|
||||
radius: PLANET_RADIUS,
|
||||
subdivisions: 88,
|
||||
let color = Color::rgba(0.7, 0.7, 0.8, 0.3);
|
||||
let plane = Plane {
|
||||
size: PLANET_RADIUS,
|
||||
};
|
||||
|
||||
let (mesh, shape) = gen_planet(isphere);
|
||||
//let (mesh, shape) = gen_planet(plane);
|
||||
let mesh = Mesh::from(plane);
|
||||
let shape = Collider::from_bevy_mesh(&mesh, &ComputedColliderShape::TriMesh).unwrap();
|
||||
|
||||
let pbody = (RigidBody::Fixed, Ccd { enabled: true });
|
||||
|
||||
let pcollide = (
|
||||
shape,
|
||||
Friction {
|
||||
coefficient: 1.2,
|
||||
coefficient: 0.8,
|
||||
..Default::default()
|
||||
},
|
||||
Restitution::new(0.8),
|
||||
Restitution::new(0.0),
|
||||
);
|
||||
|
||||
commands
|
||||
|
@ -67,7 +61,8 @@ impl Plugin for CyberPlanetPlugin {
|
|||
// 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
|
||||
// displacement before normals are calculated.
|
||||
let generated = IcoSphere::new(sphere.subdivisions, |point| {
|
||||
|
@ -86,7 +81,7 @@ fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) {
|
|||
.raw_points()
|
||||
.iter()
|
||||
.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);
|
||||
pt.into()
|
||||
})
|
||||
|
@ -120,3 +115,4 @@ fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) {
|
|||
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
|
||||
(mesh, shape)
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue