Disable CCD, embiggen world, increase FoV.

This commit is contained in:
Joe Ardent 2022-02-23 17:38:24 -08:00
parent d36452569b
commit 83af546e63
4 changed files with 37 additions and 27 deletions

View file

@ -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<Vec3> = 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::<Vec<Point<_>>>();
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<CyberBike>>, mut config: ResMut<RapierConfiguration>) {
let gravity = xform.single().translation.normalize() * -6.0;
let gravity = xform.single().translation.normalize() * -7.80;
config.gravity = gravity.into();
}

View file

@ -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);

View file

@ -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()
})

View file

@ -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)