From 83af546e631f71f17cf81764513f3c87482c1a24 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 23 Feb 2022 17:38:24 -0800 Subject: [PATCH] Disable CCD, embiggen world, increase FoV. --- src/action.rs | 44 ++++++++++++++++++++++---------------------- src/camera.rs | 5 +++++ src/geometry.rs | 8 ++++---- src/main.rs | 7 ++++++- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/action.rs b/src/action.rs index ef29ece..266f82f 100644 --- a/src/action.rs +++ b/src/action.rs @@ -2,7 +2,8 @@ use bevy::{ prelude::*, render::mesh::{Indices, VertexAttributeValues}, }; -use bevy_rapier3d::{na::Vector3, prelude::*}; +#[allow(unused_imports)] +use bevy_rapier3d::{na::Vector3, physics::PhysicsSystems::StepWorld, prelude::*}; use crate::{ geometry::{CyberBike, CyberSphere, PLANET_RADIUS}, @@ -39,8 +40,6 @@ fn setup_colliders( let vertices = mesh.attribute(Mesh::ATTRIBUTE_POSITION).unwrap(); if let VertexAttributeValues::Float32x3(verts) = vertices { if let Some(Indices::U32(indices)) = mesh.indices() { - //let vertices: Vec = verts.iter().map(|v| - // Vec3::from_slice(v)).collect(); let mut idxs = Vec::new(); for idx in indices.chunks_exact(3) { idxs.push([idx[0], idx[1], idx[2]]); @@ -50,20 +49,19 @@ fn setup_colliders( .map(|p| Point::from_slice(p)) .collect::>>(); - shape = ColliderShape::convex_decomposition(&vertices, &idxs); + shape = ColliderShape::trimesh(vertices, idxs); } } - // ok, now attach shit let pbody = RigidBodyBundle { body_type: RigidBodyType::Static.into(), - ccd: RigidBodyCcd { - ccd_enabled: true, - ccd_max_dist: PLANET_RADIUS * 1.1, - ccd_thickness: 0.4, - ..Default::default() - } - .into(), + // ccd: RigidBodyCcd { + // ccd_enabled: true, + // ccd_max_dist: PLANET_RADIUS * 1.1, + // ccd_thickness: 0.1, + // ..Default::default() + // } + // .into(), ..Default::default() }; let pcollide = ColliderBundle { @@ -90,18 +88,20 @@ fn setup_colliders( fn setup_bike_collider(bike: Entity, xform: &Transform, commands: &mut Commands) { let mut bbody = RigidBodyBundle::default(); bbody.damping.angular_damping = 0.8; - bbody.damping.linear_damping = 0.5; + bbody.damping.linear_damping = 0.4; bbody.forces = RigidBodyForces { torque: Vec3::ZERO.into(), ..Default::default() } .into(); - bbody.ccd = RigidBodyCcd { - ccd_enabled: true, - ccd_max_dist: 2.4, - ..Default::default() - } - .into(); + + // bbody.ccd = RigidBodyCcd { + // ccd_enabled: false, + // ccd_max_dist: 2.4, + // ..Default::default() + // } + // .into(); + let isometry = Isometry::from_parts(xform.translation.into(), xform.rotation.into()); bbody.position = isometry.into(); // collider @@ -112,10 +112,10 @@ fn setup_bike_collider(bike: Entity, xform: &Transform, commands: &mut Commands) ); let bcollide = ColliderBundle { shape: shape.into(), - mass_properties: ColliderMassProps::Density(0.4).into(), + mass_properties: ColliderMassProps::Density(0.6).into(), material: ColliderMaterial { friction: 0.0, - restitution: 0.01, + restitution: 0.0, ..Default::default() } .into(), @@ -129,7 +129,7 @@ fn setup_bike_collider(bike: Entity, xform: &Transform, commands: &mut Commands) } fn gravity(xform: Query<&Transform, With>, mut config: ResMut) { - let gravity = xform.single().translation.normalize() * -6.0; + let gravity = xform.single().translation.normalize() * -7.80; config.gravity = gravity.into(); } diff --git a/src/camera.rs b/src/camera.rs index c084d87..a9f5a66 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -14,10 +14,15 @@ const MAX_PITCH: f32 = 1.48353; pub struct CyberCam; fn setup_cybercam(mut commands: Commands) { + let projection = PerspectiveProjection { + fov: std::f32::consts::FRAC_PI_3, + ..Default::default() + }; commands .spawn_bundle(PerspectiveCameraBundle { transform: Transform::from_xyz(SPAWN_ALTITUDE + CAM_DIST, 0.0, 0.0) .looking_at(Vec3::ZERO, Vec3::Y), + perspective_projection: projection, ..Default::default() }) .insert(CyberCam); diff --git a/src/geometry.rs b/src/geometry.rs index a5db388..5413516 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -8,7 +8,7 @@ use wgpu::PrimitiveTopology; use crate::Label; -pub const PLANET_RADIUS: f32 = 1200.0; +pub const PLANET_RADIUS: f32 = 5000.0; pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.095; #[derive(Component, Debug)] @@ -25,7 +25,7 @@ fn spawn_giant_sphere( let color = Color::DARK_GRAY; let isphere = shape::Icosphere { radius: PLANET_RADIUS, - subdivisions: 26, + subdivisions: 40, }; let pmesh = gen_planet(isphere); @@ -37,7 +37,7 @@ fn spawn_giant_sphere( base_color: color, metallic: 0.1, perceptual_roughness: 0.3, - alpha_mode: AlphaMode::Blend, + alpha_mode: AlphaMode::Opaque, ..Default::default() }), @@ -95,7 +95,7 @@ fn gen_planet(sphere: Icosphere) -> Mesh { .raw_points() .iter() .map(|&p| { - let disp = noise.get(p.as_dvec3().into()) as f32 * 0.09; + let disp = noise.get(p.as_dvec3().into()) as f32 * 0.05; let pt = p + disp; pt.into() }) diff --git a/src/main.rs b/src/main.rs index 1a469be..892da6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,13 +12,18 @@ use cyber_rider::{ const MOVEMENT_SETTINGS: MovementSettings = MovementSettings { sensitivity: 10.0, // default: 1.0 - accel: 10.0, // default: 40.0 + accel: 30.0, // default: 40.0 }; fn main() { let mut app = App::new(); app.insert_resource(Msaa { samples: 4 }) .insert_resource(ClearColor(Color::rgb(0.07, 0.001, 0.02))) + .insert_resource(WindowDescriptor { + width: 2560.0, + height: 1440.0, + ..Default::default() + }) .insert_resource(MOVEMENT_SETTINGS) .add_plugins(DefaultPlugins) .add_plugin(CyberGeomPlugin)