Skip to content

Commit

Permalink
chore: cleaning imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Sufhal committed Sep 21, 2024
1 parent 67aafe7 commit b6e0e93
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 48 deletions.
7 changes: 1 addition & 6 deletions src/modules/camera/camera.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use cgmath::*;
use winit::event::*;
use winit::dpi::PhysicalPosition;
use instant::Duration;
use winit::keyboard::KeyCode;
use std::f32::consts::FRAC_PI_2;

use crate::modules::core::{directional_light::{self, DirectionalLight}, object_3d::{GroundAttachable, Position, Translate}};
use crate::modules::core::{directional_light::DirectionalLight, object_3d::{GroundAttachable, Position, Translate}};

#[rustfmt::skip]
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
Expand Down
2 changes: 1 addition & 1 deletion src/modules/camera/free_camera_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl FreeCameraController {
boost: 1.0,
speed,
sensitivity,
enabled: true,
enabled: false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/camera/orbit_controller.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cgmath::{num_traits::Signed, Point3, Rad};
use winit::{dpi::PhysicalPosition, event::MouseScrollDelta};
use crate::modules::{core::{object_3d::GroundAttachable, raycaster::Raycaster}, terrain::terrain::Terrain};
use crate::modules::{core::object_3d::GroundAttachable, terrain::terrain::Terrain};

use super::camera::Camera;

Expand Down
3 changes: 2 additions & 1 deletion src/modules/character/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Character {
kind: CharacterKind,
pub objects: Vec<(String, String)>, // (Object ID, Object3DInstance ID)
pub position: [f32; 3],
#[allow(dead_code)]
direction: [f32; 3],
velocity: f32,
motions: MotionsGroups,
Expand Down Expand Up @@ -288,7 +289,7 @@ impl AdditiveTranslationWithScene for Character {
if let Some(object) = scene.get_mut(object_id) {
if let Some(object3d) = &mut object.object3d {
match object3d {
Object3D::Simple(simple) => todo!(),
Object3D::Simple(_simple) => todo!(),
Object3D::Skinned(skinned) => {
if let Some(instance) = skinned.get_instance(&instance_id) {
instance.additive_translation(&[x, y, z]);
Expand Down
33 changes: 3 additions & 30 deletions src/modules/core/directional_light.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cgmath::{perspective, Deg, EuclideanSpace, InnerSpace, Matrix4, Point3, SquareMatrix, Transform, Vector3, Vector4, Zero};
use crate::modules::{camera::camera::OPENGL_TO_WGPU_MATRIX, environment::sun::Sun, terrain::terrain::Terrain};
use cgmath::{perspective, Deg, InnerSpace, Matrix4, Point3, SquareMatrix, Transform, Vector3, Vector4, Zero};
use crate::modules::{camera::camera::OPENGL_TO_WGPU_MATRIX, terrain::terrain::Terrain};
use super::texture::Texture;

const SHADOW_MAP_SIZE: u32 = 8192;
Expand Down Expand Up @@ -81,7 +81,7 @@ impl DirectionalLight {
}
}

pub fn uniform_from_camera(&self, camera_view_proj: Matrix4<f32>) -> DirectionalLightUniform {
pub fn uniform_from_camera(&self, _camera_view_proj: Matrix4<f32>) -> DirectionalLightUniform {
DirectionalLightUniform {
view_proj: self.cascade_projections[0].into(),
..Default::default()
Expand Down Expand Up @@ -230,31 +230,4 @@ fn get_frustum_center(frustum_corners: &[Point3<f32>; 8]) -> Point3<f32> {
center.z /= 8.0;

center
}

const TEXEL_SCALE: f32 = 2.0 / SHADOW_MAP_SIZE as f32; // résolution de la shadow map de 1024px
const INV_TEXEL_SCALE: f32 = 1.0 / TEXEL_SCALE;

fn stabilize_cascade_center(center: Point3<f32>, cascade_view_projection: Matrix4<f32>) -> Point3<f32> {
// Projeter le nouveau centre en utilisant la projection précédente
let projected_center = cascade_view_projection * center.to_homogeneous();

// Diviser par w pour obtenir les coordonnées normalisées
let w = projected_center.w;

// Arrondir les coordonnées x et y à des valeurs de texels entiers
let x = ((projected_center.x / w) * INV_TEXEL_SCALE).floor() * TEXEL_SCALE;
let y = ((projected_center.y / w) * INV_TEXEL_SCALE).floor() * TEXEL_SCALE;
let z = projected_center.z / w;

// Re-projeter dans l'espace monde
let inv_cascade_view_projection = cascade_view_projection.invert().unwrap();
let corrected_center = inv_cascade_view_projection * Vector4::new(x, y, z, 1.0);

// Diviser par w pour obtenir les coordonnées 3D finales
Point3::new(
corrected_center.x / corrected_center.w,
corrected_center.y / corrected_center.w,
corrected_center.z / corrected_center.w
)
}
2 changes: 0 additions & 2 deletions src/modules/core/motions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use serde::{Deserialize, Serialize};
use crate::modules::{assets::assets::load_string, utils::functions::random_u8};

use super::skinning::{AnimationMixer, MixerState};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MotionsGroups {
pub groups: Vec<MotionsGroup>,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/environment/sun.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cgmath::{Angle, Deg, Matrix4, Quaternion, Rad, Rotation3, Vector3};
use cgmath::{Angle, Matrix4, Rad};
use crate::modules::{core::model::{CustomMesh, TransformUniform}, geometry::plane::Plane, state::State};
use super::{cycle::Cycle, environment::MsEnv, Position};

Expand Down
2 changes: 1 addition & 1 deletion src/modules/pipelines/common_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use wgpu::util::DeviceExt;
use crate::modules::{camera::camera::CameraUniform, core::{directional_light::{self, DirectionalLight, DirectionalLightUniform}, light::LightUniform}, environment::{cycle::CycleUniform, fog::FogUniform, sun::SunUniform}};
use crate::modules::{camera::camera::CameraUniform, core::{directional_light::{DirectionalLight, DirectionalLightUniform}, light::LightUniform}, environment::{cycle::CycleUniform, fog::FogUniform, sun::SunUniform}};

pub struct Buffers {
pub light: wgpu::Buffer,
Expand Down
9 changes: 4 additions & 5 deletions src/modules/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{char, iter};
use std::iter;
use cgmath::Rotation3;
use log::info;
use winit::keyboard::KeyCode;
Expand All @@ -12,16 +12,15 @@ use crate::modules::core::texture::{self, Texture};
use crate::modules::camera::camera;
use crate::modules::ui::ui::MetricData;
use crate::modules::utils::time_factory::TimeFragment;
use super::assets::gltf_loader::load_model_glb;
use super::camera::free_camera_controller::FreeCameraController;
use super::character::actor::Actor;
use super::character::character::{Character, CharacterKind, CharacterState, GetActor, NPCType, PCType, Sex};
use super::core::directional_light::{self, DirectionalLight};
use super::character::character::{Character, CharacterKind, CharacterState, GetActor, PCType, Sex};
use super::core::directional_light::DirectionalLight;
use super::core::object_3d::{Object3D, TranslateWithScene};
use super::core::scene;
use super::pipelines::clouds_pipeline::CloudsPipeline;
use super::pipelines::common_pipeline::CommonPipeline;
use super::pipelines::shadow_pipeline::{self, ShadowPipeline};
use super::pipelines::shadow_pipeline::ShadowPipeline;
use super::pipelines::simple_models_pipeline::SimpleModelPipeline;
use super::pipelines::skinned_models_pipeline::SkinnedModelPipeline;
use super::pipelines::sky_pipeline::SkyPipeline;
Expand Down

0 comments on commit b6e0e93

Please sign in to comment.