implement config
This commit is contained in:
parent
3552491a9a
commit
9dec53d764
30
src/main.rs
30
src/main.rs
@ -65,10 +65,10 @@ fn perspective_rh(fov_x_slope: f32, fov_y_slope: f32, z_near: f32, z_far: f32) -
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
impl GraphicsCamera{
|
impl GraphicsCamera{
|
||||||
pub fn new(screen_size:glam::UVec2,fov_y:f32)->Self{
|
pub fn new(screen_size:glam::UVec2,fov:glam::Vec2)->Self{
|
||||||
Self{
|
Self{
|
||||||
screen_size,
|
screen_size,
|
||||||
fov: glam::vec2(fov_y*(screen_size.x as f32)/(screen_size.y as f32),fov_y),
|
fov,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn proj(&self)->glam::Mat4{
|
pub fn proj(&self)->glam::Mat4{
|
||||||
@ -78,10 +78,6 @@ impl GraphicsCamera{
|
|||||||
//f32 good enough for view matrix
|
//f32 good enough for view matrix
|
||||||
glam::Mat4::from_translation(pos) * glam::Mat4::from_euler(glam::EulerRot::YXZ, angles.x, angles.y, 0f32)
|
glam::Mat4::from_translation(pos) * glam::Mat4::from_euler(glam::EulerRot::YXZ, angles.x, angles.y, 0f32)
|
||||||
}
|
}
|
||||||
pub fn set_screen_size(&mut self,screen_size:glam::UVec2){
|
|
||||||
self.screen_size=screen_size;
|
|
||||||
self.fov.x=self.fov.y*(screen_size.x as f32)/(screen_size.y as f32);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_uniform_data(&self,(pos,angles): (glam::Vec3,glam::Vec2)) -> [f32; 16 * 4] {
|
pub fn to_uniform_data(&self,(pos,angles): (glam::Vec3,glam::Vec2)) -> [f32; 16 * 4] {
|
||||||
let proj=self.proj();
|
let proj=self.proj();
|
||||||
@ -115,12 +111,16 @@ impl GraphicsState{
|
|||||||
pub fn clear(&mut self){
|
pub fn clear(&mut self){
|
||||||
self.models.clear();
|
self.models.clear();
|
||||||
}
|
}
|
||||||
|
pub fn load_user_settings(&mut self,user_settings:&settings::UserSettings){
|
||||||
|
self.camera.fov=user_settings.calculate_fov(1.0,&self.camera.screen_size).as_vec2();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GlobalState{
|
pub struct GlobalState{
|
||||||
start_time: std::time::Instant,
|
start_time: std::time::Instant,
|
||||||
manual_mouse_lock:bool,
|
manual_mouse_lock:bool,
|
||||||
mouse:physics::MouseState,
|
mouse:physics::MouseState,
|
||||||
|
user_settings:settings::UserSettings,
|
||||||
graphics:GraphicsState,
|
graphics:GraphicsState,
|
||||||
physics_thread:worker::CompatWorker<TimedInstruction<InputInstruction>,physics::PhysicsOutputState,Box<dyn FnMut(TimedInstruction<InputInstruction>)->physics::PhysicsOutputState>>,
|
physics_thread:worker::CompatWorker<TimedInstruction<InputInstruction>,physics::PhysicsOutputState,Box<dyn FnMut(TimedInstruction<InputInstruction>)->physics::PhysicsOutputState>>,
|
||||||
}
|
}
|
||||||
@ -414,6 +414,8 @@ impl framework::Example for GlobalState {
|
|||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
//wee
|
||||||
|
let user_settings=settings::read_user_settings();
|
||||||
let mut indexed_models = Vec::new();
|
let mut indexed_models = Vec::new();
|
||||||
indexed_models.append(&mut model::generate_indexed_model_list_from_obj(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap(),*glam::Vec4::ONE.as_ref()));
|
indexed_models.append(&mut model::generate_indexed_model_list_from_obj(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap(),*glam::Vec4::ONE.as_ref()));
|
||||||
indexed_models.push(primitives::unit_sphere());
|
indexed_models.push(primitives::unit_sphere());
|
||||||
@ -753,7 +755,11 @@ impl framework::Example for GlobalState {
|
|||||||
|
|
||||||
let mut physics = physics::PhysicsState::default();
|
let mut physics = physics::PhysicsState::default();
|
||||||
|
|
||||||
let camera=GraphicsCamera::new(glam::uvec2(config.width,config.height), 1.0);
|
physics.load_user_settings(&user_settings);
|
||||||
|
|
||||||
|
let screen_size=glam::uvec2(config.width,config.height);
|
||||||
|
|
||||||
|
let camera=GraphicsCamera::new(screen_size,user_settings.calculate_fov(1.0,&screen_size).as_vec2());
|
||||||
let camera_uniforms = camera.to_uniform_data(physics.output().adjust_mouse(&physics.next_mouse));
|
let camera_uniforms = camera.to_uniform_data(physics.output().adjust_mouse(&physics.next_mouse));
|
||||||
let camera_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
let camera_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("Camera"),
|
label: Some("Camera"),
|
||||||
@ -788,7 +794,7 @@ impl framework::Example for GlobalState {
|
|||||||
|
|
||||||
let depth_view = Self::create_depth_texture(config, device);
|
let depth_view = Self::create_depth_texture(config, device);
|
||||||
|
|
||||||
let graphics=GraphicsState {
|
let mut graphics=GraphicsState {
|
||||||
pipelines:GraphicsPipelines{
|
pipelines:GraphicsPipelines{
|
||||||
skybox:sky_pipeline,
|
skybox:sky_pipeline,
|
||||||
model:model_pipeline
|
model:model_pipeline
|
||||||
@ -807,6 +813,8 @@ impl framework::Example for GlobalState {
|
|||||||
temp_squid_texture_view: squid_texture_view,
|
temp_squid_texture_view: squid_texture_view,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
graphics.load_user_settings(&user_settings);
|
||||||
|
|
||||||
let indexed_model_instances=model::IndexedModelInstances{
|
let indexed_model_instances=model::IndexedModelInstances{
|
||||||
textures:Vec::new(),
|
textures:Vec::new(),
|
||||||
models:indexed_models,
|
models:indexed_models,
|
||||||
@ -828,6 +836,7 @@ impl framework::Example for GlobalState {
|
|||||||
start_time:Instant::now(),
|
start_time:Instant::now(),
|
||||||
manual_mouse_lock:false,
|
manual_mouse_lock:false,
|
||||||
mouse:physics::MouseState::default(),
|
mouse:physics::MouseState::default(),
|
||||||
|
user_settings,
|
||||||
graphics,
|
graphics,
|
||||||
physics_thread,
|
physics_thread,
|
||||||
};
|
};
|
||||||
@ -889,9 +898,11 @@ impl framework::Example for GlobalState {
|
|||||||
time:physics.time,
|
time:physics.time,
|
||||||
instruction: PhysicsInstruction::Input(physics::PhysicsInputInstruction::Reset),
|
instruction: PhysicsInstruction::Input(physics::PhysicsInputInstruction::Reset),
|
||||||
});
|
});
|
||||||
|
physics.load_user_settings(&self.user_settings);
|
||||||
physics.generate_models(&indexed_model_instances);
|
physics.generate_models(&indexed_model_instances);
|
||||||
self.physics_thread=physics.into_worker();
|
self.physics_thread=physics.into_worker();
|
||||||
|
|
||||||
|
//graphics.load_user_settings(&self.user_settings);
|
||||||
self.generate_model_graphics(device,queue,indexed_model_instances);
|
self.generate_model_graphics(device,queue,indexed_model_instances);
|
||||||
//manual reset
|
//manual reset
|
||||||
}else{
|
}else{
|
||||||
@ -1030,7 +1041,8 @@ impl framework::Example for GlobalState {
|
|||||||
_queue: &wgpu::Queue,
|
_queue: &wgpu::Queue,
|
||||||
) {
|
) {
|
||||||
self.graphics.depth_view = Self::create_depth_texture(config, device);
|
self.graphics.depth_view = Self::create_depth_texture(config, device);
|
||||||
self.graphics.camera.set_screen_size(glam::uvec2(config.width, config.height));
|
self.graphics.camera.screen_size=glam::uvec2(config.width, config.height);
|
||||||
|
self.graphics.load_user_settings(&self.user_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(
|
fn render(
|
||||||
|
@ -175,7 +175,7 @@ impl PhysicsCamera {
|
|||||||
Self{
|
Self{
|
||||||
offset,
|
offset,
|
||||||
angles: glam::DVec2::ZERO,
|
angles: glam::DVec2::ZERO,
|
||||||
sensitivity: glam::dvec2(1.0/16384.0,1.0/16384.0),
|
sensitivity: glam::dvec2(1.0/1024.0,1.0/1024.0),
|
||||||
mouse:MouseState{pos:glam::IVec2::ZERO,time:-1},//escape initialization hell divide by zero
|
mouse:MouseState{pos:glam::IVec2::ZERO,time:-1},//escape initialization hell divide by zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -617,6 +617,10 @@ impl PhysicsState {
|
|||||||
println!("Physics Objects: {}",self.models.len());
|
println!("Physics Objects: {}",self.models.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_user_settings(&mut self,user_settings:&crate::settings::UserSettings){
|
||||||
|
self.camera.sensitivity=user_settings.calculate_sensitivity();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_mode(&self,mode_id:u32)->Option<&crate::model::ModeDescription>{
|
pub fn get_mode(&self,mode_id:u32)->Option<&crate::model::ModeDescription>{
|
||||||
if let Some(&mode)=self.mode_from_mode_id.get(&mode_id){
|
if let Some(&mode)=self.mode_from_mode_id.get(&mode_id){
|
||||||
self.modes.get(mode)
|
self.modes.get(mode)
|
||||||
|
Loading…
Reference in New Issue
Block a user