change world generations, enable mi[mapping in sampler, unlink movement speed from fps

This commit is contained in:
griffi-gh 2023-01-26 03:39:39 +01:00
parent fc6da8856d
commit dfdcc3e4b7
4 changed files with 16 additions and 8 deletions

View file

@ -1,7 +1,7 @@
use glam::{Vec3, Mat4, Quat, EulerRot, Vec2};
use shipyard::{Component, View, ViewMut, IntoIter, UniqueView, Workload, IntoWorkload};
use std::f32::consts::PI;
use crate::{transform::Transform, input::Inputs, settings::GameSettings};
use crate::{transform::Transform, input::Inputs, settings::GameSettings, DeltaTime};
#[derive(Component)]
pub struct FlyController;
@ -19,7 +19,7 @@ fn update_look(
controllers: View<FlyController>,
mut transforms: ViewMut<Transform>,
inputs: UniqueView<Inputs>,
settings: UniqueView<GameSettings>,
settings: UniqueView<GameSettings>
) {
let look = inputs.look * settings.mouse_sensitivity;
if look == Vec2::ZERO { return }
@ -29,7 +29,7 @@ fn update_look(
yaw -= look.x;
pitch -= look.y;
pitch = pitch.clamp(-MAX_PITCH, MAX_PITCH);
rotation = Quat::from_euler(EulerRot::YXZ, yaw, pitch, 0.);
rotation = Quat::from_euler(EulerRot::YXZ, yaw, pitch, 0.).normalize();
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
}
}
@ -37,9 +37,10 @@ fn update_look(
fn update_movement(
controllers: View<FlyController>,
mut transforms: ViewMut<Transform>,
inputs: UniqueView<Inputs>
inputs: UniqueView<Inputs>,
dt: UniqueView<DeltaTime>,
) {
let movement = inputs.movement;
let movement = inputs.movement * 30. * dt.0.as_secs_f32();
if movement == Vec2::ZERO { return }
for (_, mut transform) in (&controllers, &mut transforms).iter() {
let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();

View file

@ -9,7 +9,7 @@ pub struct GameSettings {
impl Default for GameSettings {
fn default() -> Self {
Self {
render_distance: 2,
render_distance: 5,
mouse_sensitivity: 0.01,
}
}

View file

@ -60,7 +60,7 @@ pub fn draw_world(
..Default::default()
};
let texture_sampler = Sampler(&texture.0, SamplerBehavior {
minify_filter: MinifySamplerFilter::Linear,
minify_filter: MinifySamplerFilter::LinearMipmapLinear,
magnify_filter: MagnifySamplerFilter::Nearest,
max_anisotropy: 8,
wrap_function: (SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp),

View file

@ -4,13 +4,20 @@ use super::{
block::Block
};
pub fn generate_world(_position: IVec3, _seed: u32) -> BlockData {
pub fn generate_world(position: IVec3, _seed: u32) -> BlockData {
let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]);
blocks[0][0][0] = Block::Stone;
blocks[1][0][0] = Block::Stone;
blocks[0][1][0] = Block::Stone;
blocks[0][2][0] = Block::Stone;
blocks[0][0][1] = Block::Stone;
if position.y == 0 {
for x in 0..CHUNK_SIZE {
for z in 0..CHUNK_SIZE {
blocks[x][0][z] = Block::Stone;
}
}
}
//TODO actual world generation
blocks
}