hotkeys for torus radius, camera reset

This commit is contained in:
2016-10-21 18:59:34 -07:00
parent 73ac584ca4
commit 11a16e092f
3 changed files with 52 additions and 18 deletions

View File

@@ -29,7 +29,6 @@ pub fn main() {
let mut aux_command = window.factory.create_command_buffer(); let mut aux_command = window.factory.create_command_buffer();
let mut scene = scenes::world::WorldScene::new(&mut window.device, let mut scene = scenes::world::WorldScene::new(&mut window.device,
&mut window.factory, &mut window.factory,
&mut window.encoder,
&mut aux_command); &mut aux_command);
let view = view::ViewRoot::<gfx_device_gl::Device, view::ColorFormat, view::DepthFormat> let view = view::ViewRoot::<gfx_device_gl::Device, view::ColorFormat, view::DepthFormat>
::create_view(&mut window, &mut vr); ::create_view(&mut window, &mut vr);

View File

@@ -6,11 +6,11 @@ use world as model;
use world::HasMap; use world::HasMap;
extern crate gfx; extern crate gfx;
extern crate memmap;
extern crate nalgebra as na; extern crate nalgebra as na;
extern crate num_traits; extern crate num_traits;
extern crate openvr_sys; extern crate openvr_sys;
extern crate piston; extern crate piston;
extern crate piston_window;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::marker::PhantomData; use std::marker::PhantomData;
@@ -121,7 +121,9 @@ pub struct WorldScene<D: gfx::Device,
F: gfx::Factory<D::Resources>> { F: gfx::Factory<D::Resources>> {
pso: gfx::PipelineState<D::Resources, pipe::Meta>, pso: gfx::PipelineState<D::Resources, pipe::Meta>,
camera: na::Matrix4<f32>, camera: na::Matrix4<f32>,
constants: gfx::handle::Buffer<D::Resources, Constants>, constants: Constants,
constants_buffer: gfx::handle::Buffer<D::Resources, Constants>,
constants_dirty: bool,
locals: gfx::handle::Buffer<D::Resources, Locals>, locals: gfx::handle::Buffer<D::Resources, Locals>,
atlas: gfx::handle::ShaderResourceView<D::Resources, atlas: gfx::handle::ShaderResourceView<D::Resources,
<view::ColorFormat as gfx::format::Formatted>::View>, <view::ColorFormat as gfx::format::Formatted>::View>,
@@ -143,26 +145,21 @@ pub struct WorldScene<D: gfx::Device,
impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> { impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
pub fn new(device: &mut D, pub fn new(device: &mut D,
factory: &mut F, factory: &mut F,
encoder: &mut gfx::Encoder<D::Resources, D::CommandBuffer>,
aux_command: &mut <D as gfx::Device>::CommandBuffer) -> WorldScene<D, F> { aux_command: &mut <D as gfx::Device>::CommandBuffer) -> WorldScene<D, F> {
let worldmap = get_data_model(); let worldmap = get_data_model();
let (model, model_idx) = get_model(&worldmap); let (model, model_idx) = get_model(&worldmap);
let (vertex_buffer, slice) = let (vertex_buffer, slice) =
factory.create_vertex_buffer_with_slice(&model, &model_idx[..]); factory.create_vertex_buffer_with_slice(&model, &model_idx[..]);
let constants = factory.create_constant_buffer(1);
encoder.update_constant_buffer(&constants, &Constants { anim: ANIMDATA,
r1: R1,
r2: R2,
r3: R3});
WorldScene { WorldScene {
pso: factory.create_pipeline_simple(VERTEX_SHADER_SRC, pso: factory.create_pipeline_simple(VERTEX_SHADER_SRC,
FRAGMENT_SHADER_SRC, FRAGMENT_SHADER_SRC,
pipe::new()) pipe::new())
.expect("create pipeline"), .expect("create pipeline"),
camera: na::Matrix4::one(), camera: na::Matrix4::one(),
constants: constants, constants: Constants { anim: ANIMDATA, r1: R1, r2: R2, r3: R3},
constants_buffer: factory.create_constant_buffer(1),
constants_dirty: true,
locals: factory.create_constant_buffer(1), locals: factory.create_constant_buffer(1),
atlas: tile::get_tiles::<_, _, view::ColorFormat>(device, factory, aux_command), atlas: tile::get_tiles::<_, _, view::ColorFormat>(device, factory, aux_command),
sampler: factory.create_sampler(tex::SamplerInfo::new(tex::FilterMethod::Jrd, sampler: factory.create_sampler(tex::SamplerInfo::new(tex::FilterMethod::Jrd,
@@ -204,6 +201,7 @@ impl<D: gfx::Device,
use scene::Event::*; use scene::Event::*;
use vr::Event::*; use vr::Event::*;
match event { match event {
// treadmill / camera movement registration
Vr(Touch { dev_idx, .. }) => { Vr(Touch { dev_idx, .. }) => {
self.pads.insert(dev_idx, (TrackMode::Touch, None)); self.pads.insert(dev_idx, (TrackMode::Touch, None));
}, },
@@ -216,6 +214,16 @@ impl<D: gfx::Device,
Vr(Untouch { dev_idx, .. }) => { Vr(Untouch { dev_idx, .. }) => {
self.pads.remove(&dev_idx); self.pads.remove(&dev_idx);
}, },
// treadmill / camera reset
Piston(Input::Press(Button::Keyboard(Key::Backspace))) => {
self.treadmills = (0.0, 0.0);
},
Piston(Input::Press(Button::Keyboard(Key::D0))) => {
self.camera = na::Matrix4::one();
},
// player movement
Piston(Input::Press(Button::Keyboard(Key::Up))) => { Piston(Input::Press(Button::Keyboard(Key::Up))) => {
self.lat = self.lat.wrapping_sub(1); self.lat = self.lat.wrapping_sub(1);
}, },
@@ -228,6 +236,28 @@ impl<D: gfx::Device,
Piston(Input::Press(Button::Keyboard(Key::Right))) => { Piston(Input::Press(Button::Keyboard(Key::Right))) => {
self.lng = self.lng.wrapping_add(1); self.lng = self.lng.wrapping_add(1);
}, },
// scale adjustment
Piston(Input::Press(Button::Keyboard(Key::Q))) => {
self.constants = Constants { r1: R1 / 2.0, r2: R2 / 2.0, r3: R3 / 2.0, ..self.constants };
self.constants_dirty = true;
},
Piston(Input::Press(Button::Keyboard(Key::D1))) => {
self.constants = Constants { r1: R1, r2: R2, r3: R3, ..self.constants };
self.constants_dirty = true;
},
Piston(Input::Press(Button::Keyboard(Key::D2))) => {
self.constants = Constants { r1: R1 * 2.0, r2: R2 * 2.0, r3: R3 * 2.0, ..self.constants };
self.constants_dirty = true;
},
Piston(Input::Press(Button::Keyboard(Key::D3))) => {
self.constants = Constants { r1: R1 * 4.0, r2: R2 * 4.0, r3: R3 * 4.0, ..self.constants };
self.constants_dirty = true;
},
Piston(Input::Press(Button::Keyboard(Key::D4))) => {
self.constants = Constants { r1: R1 * 16.0, r2: R2 * 16.0, r3: R3 * 16.0, ..self.constants };
self.constants_dirty = true;
},
_ => () _ => ()
} }
} }
@@ -280,6 +310,11 @@ impl<D: gfx::Device,
} }
} }
if self.constants_dirty {
self.constants_dirty = false;
encoder.update_constant_buffer(&self.constants_buffer, &self.constants);
}
encoder.update_constant_buffer(&self.locals, &Locals { millis: millis, encoder.update_constant_buffer(&self.locals, &Locals { millis: millis,
treadmill_x: self.treadmills.0, treadmill_x: self.treadmills.0,
treadmill_y: self.treadmills.1 }); treadmill_y: self.treadmills.1 });
@@ -295,7 +330,7 @@ impl<D: gfx::Device,
let pipe = pipe::Data { let pipe = pipe::Data {
vbuf: self.vbuf.clone(), vbuf: self.vbuf.clone(),
trans: trans.clone(), trans: trans.clone(),
constants: self.constants.clone(), constants: self.constants_buffer.clone(),
locals: self.locals.clone(), locals: self.locals.clone(),
atlas: (self.atlas.clone(), self.sampler.clone()), atlas: (self.atlas.clone(), self.sampler.clone()),
pixcolor: target.clone(), pixcolor: target.clone(),
@@ -305,10 +340,11 @@ impl<D: gfx::Device,
} }
fn origin(&self) -> na::Matrix4<f32> { fn origin(&self) -> na::Matrix4<f32> {
let (y, x) = (self.lat as f32 + 0.5, self.lng as f32 + 0.5); let (r1, r2, r3) = (self.constants.r1, self.constants.r2, self.constants.r3);
let eye = Self::toroid((x, y), R1, R2, R3); let (y, x) = (self.lat as f32 + 0.5, self.lng as f32 + 0.5); // center of tile
let looktgt = Self::toroid((x, y - 1.0), R1, R2, R3); let eye = Self::toroid((x, y), r1, r2, r3);
let normal = Self::toroid((x, y), 0.0, R2, R2) * na::Vector3::new(R2 / R3, 1.0, 1.0); let looktgt = Self::toroid((x, y - 1.0), r1, r2, r3); // look ahead = north
let normal = Self::toroid((x, y), 0.0, r2, r2) * na::Vector3::new(r2 / r3, 1.0, 1.0);
self.camera * na::Isometry3::look_at_rh(eye.as_point(), self.camera * na::Isometry3::look_at_rh(eye.as_point(),
looktgt.as_point(), looktgt.as_point(),
&normal, &normal,
@@ -316,7 +352,6 @@ impl<D: gfx::Device,
} }
} }
extern crate memmap;
fn get_data_model() -> model::World { fn get_data_model() -> model::World {
use self::memmap::{Mmap, Protection}; use self::memmap::{Mmap, Protection};
use std::mem::transmute; use std::mem::transmute;

View File

@@ -16,7 +16,7 @@ pub type ColorFormat = gfx::format::Srgba8;
pub type DepthFormat = gfx::format::DepthStencil; pub type DepthFormat = gfx::format::DepthStencil;
const NEAR: f32 = 0.01; const NEAR: f32 = 0.01;
const FAR: f32 = 1000.0; const FAR: f32 = 3072.0;
gfx_constant_struct! { gfx_constant_struct! {
Trans { Trans {