implement fov
This commit is contained in:
@@ -9,8 +9,7 @@ pub struct Graphics{
|
|||||||
}
|
}
|
||||||
impl Graphics{
|
impl Graphics{
|
||||||
pub fn new(device:wgpu::Device,queue:wgpu::Queue,config:wgpu::SurfaceConfiguration)->Self{
|
pub fn new(device:wgpu::Device,queue:wgpu::Queue,config:wgpu::SurfaceConfiguration)->Self{
|
||||||
let mut graphics=strafesnet_graphics::graphics::GraphicsState::new(&device,&queue,&config);
|
let graphics=strafesnet_graphics::graphics::GraphicsState::new(&device,&queue,&config);
|
||||||
graphics.resize(&device,&config,glam::Vec2::ONE);
|
|
||||||
Self{
|
Self{
|
||||||
graphics,
|
graphics,
|
||||||
device,
|
device,
|
||||||
@@ -22,11 +21,11 @@ impl Graphics{
|
|||||||
self.graphics.clear();
|
self.graphics.clear();
|
||||||
self.graphics.generate_models(&self.device,&self.queue,map);
|
self.graphics.generate_models(&self.device,&self.queue,map);
|
||||||
}
|
}
|
||||||
pub fn resize(&mut self,surface:&wgpu::Surface<'_>,size:glam::UVec2){
|
pub fn resize(&mut self,surface:&wgpu::Surface<'_>,size:glam::UVec2,fov:glam::Vec2){
|
||||||
self.config.width=size.x.max(1);
|
self.config.width=size.x.max(1);
|
||||||
self.config.height=size.y.max(1);
|
self.config.height=size.y.max(1);
|
||||||
surface.configure(&self.device,&self.config);
|
surface.configure(&self.device,&self.config);
|
||||||
self.graphics.resize(&self.device,&self.config,glam::Vec2::ONE);
|
self.graphics.resize(&self.device,&self.config,fov);
|
||||||
}
|
}
|
||||||
pub fn render(&mut self,surface:&wgpu::Surface<'_>,pos:glam::Vec3,angles:glam::Vec2){
|
pub fn render(&mut self,surface:&wgpu::Surface<'_>,pos:glam::Vec3,angles:glam::Vec2){
|
||||||
//this has to go deeper somehow
|
//this has to go deeper somehow
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ impl PlaybackState{
|
|||||||
fn push_setting(&mut self,event:&v0::SettingEvent){
|
fn push_setting(&mut self,event:&v0::SettingEvent){
|
||||||
match event{
|
match event{
|
||||||
v0::SettingEvent::FieldOfView(setting_event_field_of_view)=>{
|
v0::SettingEvent::FieldOfView(setting_event_field_of_view)=>{
|
||||||
self.fov_y=setting_event_field_of_view.fov;
|
self.fov_y=(setting_event_field_of_view.fov*0.5).to_radians().tan();
|
||||||
},
|
},
|
||||||
v0::SettingEvent::Sensitivity(setting_event_sensitivity)=>{
|
v0::SettingEvent::Sensitivity(setting_event_sensitivity)=>{
|
||||||
self.sens_x=setting_event_sensitivity.sensitivity;
|
self.sens_x=setting_event_sensitivity.sensitivity;
|
||||||
@@ -207,4 +207,16 @@ impl PlaybackState{
|
|||||||
v0::EventType::Setting=>self.push_setting(&bot.timelines().setting_events[event_index].event),
|
v0::EventType::Setting=>self.push_setting(&bot.timelines().setting_events[event_index].event),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn get_fov_slope_y(&self)->f64{
|
||||||
|
let zoom_enabled=self.game_controls.contains(v0::GameControls::Zoom);
|
||||||
|
if zoom_enabled{self.fov_y*0.2}else{self.fov_y}
|
||||||
|
}
|
||||||
|
pub fn get_sensitivity(&self)->(f64,f64){
|
||||||
|
if self.absolute_sensitivity_enabled{
|
||||||
|
(self.sens_x,self.sens_x*self.vertical_sensitivity_multipler)
|
||||||
|
}else{
|
||||||
|
let sens_x=self.sens_x*self.get_fov_slope_y()/128.0;
|
||||||
|
(sens_x,sens_x*self.vertical_sensitivity_multipler)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ impl<'a> PlayerWorker<'a>{
|
|||||||
self.graphics_thread.render(&self.surface,pos,angles);
|
self.graphics_thread.render(&self.surface,pos,angles);
|
||||||
},
|
},
|
||||||
Instruction::Resize(physical_size)=>{
|
Instruction::Resize(physical_size)=>{
|
||||||
self.graphics_thread.resize(&self.surface,glam::uvec2(physical_size.width,physical_size.height));
|
let fov_y=self.playback_head.state().get_fov_slope_y();
|
||||||
|
let fov_x=fov_y*physical_size.width as f64/physical_size.height as f64;
|
||||||
|
self.graphics_thread.resize(&self.surface,glam::uvec2(physical_size.width,physical_size.height),glam::vec2(fov_x as f32,fov_y as f32));
|
||||||
},
|
},
|
||||||
Instruction::ChangeMap(complete_map)=>{
|
Instruction::ChangeMap(complete_map)=>{
|
||||||
self.graphics_thread.change_map(&complete_map);
|
self.graphics_thread.change_map(&complete_map);
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ impl Graphics{
|
|||||||
self.graphics.render(&self.surface,pos,angles);
|
self.graphics.render(&self.surface,pos,angles);
|
||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn resize(&mut self,width:u32,height:u32){
|
pub fn resize(&mut self,width:u32,height:u32,fov_x:f32,fov_y:f32){
|
||||||
self.graphics.resize(&self.surface,[width,height].into());
|
self.graphics.resize(&self.surface,[width,height].into(),[fov_x as f32,fov_y as f32].into());
|
||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn change_map(&mut self,map:&CompleteMap){
|
pub fn change_map(&mut self,map:&CompleteMap){
|
||||||
@@ -161,4 +161,8 @@ impl PlaybackHead{
|
|||||||
let time_offset=time::from_float(time_offset).unwrap();
|
let time_offset=time::from_float(time_offset).unwrap();
|
||||||
self.head.seek_backward(time_offset);
|
self.head.seek_backward(time_offset);
|
||||||
}
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_fov_slope_y(&self)->f64{
|
||||||
|
self.head.state().get_fov_slope_y()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ const bot = new CompleteBot(new Uint8Array(await b.arrayBuffer()));
|
|||||||
const map = new CompleteMap(new Uint8Array(await m.arrayBuffer()));
|
const map = new CompleteMap(new Uint8Array(await m.arrayBuffer()));
|
||||||
const playback = new PlaybackHead(0);
|
const playback = new PlaybackHead(0);
|
||||||
|
|
||||||
|
// Initialize playback (fill playback state from bot)
|
||||||
|
playback.advance_time(bot, 0);
|
||||||
|
|
||||||
graphics.change_map(map);
|
graphics.change_map(map);
|
||||||
|
|
||||||
// HUD
|
// HUD
|
||||||
@@ -111,7 +114,9 @@ requestAnimationFrame(animate);
|
|||||||
function resize() {
|
function resize() {
|
||||||
canvas.width = canvas.clientWidth;
|
canvas.width = canvas.clientWidth;
|
||||||
canvas.height = canvas.clientHeight;
|
canvas.height = canvas.clientHeight;
|
||||||
graphics.resize(canvas.width, canvas.height);
|
const fov_y = playback.get_fov_slope_y();
|
||||||
|
const fov_x = (fov_y * canvas.width) / canvas.height;
|
||||||
|
graphics.resize(canvas.width, canvas.height, fov_x, fov_y);
|
||||||
}
|
}
|
||||||
window.addEventListener("resize", resize);
|
window.addEventListener("resize", resize);
|
||||||
resize();
|
resize();
|
||||||
|
|||||||
Reference in New Issue
Block a user