Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e0a514aa5 |
@@ -5,11 +5,14 @@ use vrtue::scene::{Event, Scene};
|
|||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate gfx_device_gl;
|
extern crate gfx_device_gl;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
extern crate piston;
|
||||||
extern crate piston_window;
|
extern crate piston_window;
|
||||||
|
|
||||||
|
use self::piston::input::{Button, Input, Key};
|
||||||
use self::piston_window::{PistonWindow, Window, WindowSettings};
|
use self::piston_window::{PistonWindow, Window, WindowSettings};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
env_logger::init().expect("env logger");
|
env_logger::init().expect("env logger");
|
||||||
let mut vr = if env::var("NO_VR").is_ok() {
|
let mut vr = if env::var("NO_VR").is_ok() {
|
||||||
@@ -41,7 +44,8 @@ pub fn main() {
|
|||||||
// handle window events
|
// handle window events
|
||||||
while let Some(ev) = window.poll_event() {
|
while let Some(ev) = window.poll_event() {
|
||||||
match ev {
|
match ev {
|
||||||
piston_window::Input::Text(_) => break 'main,
|
Input::Press(Button::Keyboard(Key::Space)) |
|
||||||
|
Input::Press(Button::Keyboard(Key::Escape)) => break'main,
|
||||||
_ => debug!("\t{:?}", ev)
|
_ => debug!("\t{:?}", ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ uniform b_constants {
|
|||||||
uvec4 anim;
|
uvec4 anim;
|
||||||
float R1;
|
float R1;
|
||||||
float R2;
|
float R2;
|
||||||
|
float R3;
|
||||||
};
|
};
|
||||||
uniform b_locals {
|
uniform b_locals {
|
||||||
mat4 camera;
|
|
||||||
uint millis;
|
uint millis;
|
||||||
float treadmill_x;
|
float treadmill_x;
|
||||||
float treadmill_y;
|
float treadmill_y;
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ uniform b_constants {
|
|||||||
uvec4 anim;
|
uvec4 anim;
|
||||||
float R1;
|
float R1;
|
||||||
float R2;
|
float R2;
|
||||||
|
float R3;
|
||||||
};
|
};
|
||||||
uniform b_locals {
|
uniform b_locals {
|
||||||
mat4 camera;
|
|
||||||
uint millis;
|
uint millis;
|
||||||
float treadmill_x;
|
float treadmill_x;
|
||||||
float treadmill_y;
|
float treadmill_y;
|
||||||
@@ -35,8 +35,8 @@ void main() {
|
|||||||
|
|
||||||
vec2 thetaphi = vec2(TWO_PI_CIRC * (a_pos.x + treadmill_x),
|
vec2 thetaphi = vec2(TWO_PI_CIRC * (a_pos.x + treadmill_x),
|
||||||
TWO_PI_CIRC * (a_pos.y + treadmill_y));
|
TWO_PI_CIRC * (a_pos.y + treadmill_y));
|
||||||
float height = R1 * TWO_PI_CIRC;
|
float height = R2 * 4 * TWO_PI_CIRC;
|
||||||
vec3 normal = vec3(toroid(thetaphi, 0, height, height));
|
vec3 normal = vec3(toroid(thetaphi, 0, height, height)) *
|
||||||
gl_Position = u_matrix * camera *
|
vec3(R2 / R3, 1.0, 1.0);
|
||||||
vec4(toroid(thetaphi, R1, R2, R1) + a_pos.z * normal, 1.0);
|
gl_Position = u_matrix * vec4(toroid(thetaphi, R1, R2, R3) + a_pos.z * normal, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ extern crate gfx;
|
|||||||
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_window;
|
extern crate piston_window;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
@@ -19,13 +20,14 @@ use gfx::tex;
|
|||||||
use gfx::traits::FactoryExt;
|
use gfx::traits::FactoryExt;
|
||||||
use self::na::ToHomogeneous;
|
use self::na::ToHomogeneous;
|
||||||
use self::num_traits::identities::One;
|
use self::num_traits::identities::One;
|
||||||
|
use self::piston::input::{Button, Input, Key};
|
||||||
|
|
||||||
//const R1: f32 = 4096.0;
|
|
||||||
//const R2: f32 = 1024.0;
|
|
||||||
//const R1: f32 = 4.0;
|
|
||||||
//const R2: f32 = 1.0;
|
|
||||||
const R1: f32 = 256.0;
|
const R1: f32 = 256.0;
|
||||||
const R2: f32 = 64.0;
|
const R2: f32 = 64.0;
|
||||||
|
const R3: f32 = 128.0;
|
||||||
|
const PI: f32 = ::std::f32::consts::PI;
|
||||||
|
const TWO_PI: f32 = 2.0 * PI;
|
||||||
|
const TWO_PI_CIRC: f32 = TWO_PI / 256.0;
|
||||||
|
|
||||||
gfx_defines! {
|
gfx_defines! {
|
||||||
vertex Vertex {
|
vertex Vertex {
|
||||||
@@ -38,10 +40,10 @@ gfx_defines! {
|
|||||||
anim: [u32; 4] = "anim",
|
anim: [u32; 4] = "anim",
|
||||||
r1: f32 = "R1",
|
r1: f32 = "R1",
|
||||||
r2: f32 = "R2",
|
r2: f32 = "R2",
|
||||||
|
r3: f32 = "R3",
|
||||||
}
|
}
|
||||||
|
|
||||||
constant Locals {
|
constant Locals {
|
||||||
camera: [[f32; 4]; 4] = "camera",
|
|
||||||
millis: u32 = "millis",
|
millis: u32 = "millis",
|
||||||
treadmill_x: f32 = "treadmill_x",
|
treadmill_x: f32 = "treadmill_x",
|
||||||
treadmill_y: f32 = "treadmill_y",
|
treadmill_y: f32 = "treadmill_y",
|
||||||
@@ -76,8 +78,7 @@ fn get_model(world: &model::World) -> (Vec<Vertex>, Vec<u32>) {
|
|||||||
10 | 11 | 12 => 1.0,
|
10 | 11 | 12 => 1.0,
|
||||||
_ => 0.0,
|
_ => 0.0,
|
||||||
};
|
};
|
||||||
let rf = (((r + 90) % 256) as i16 - 128) as f32;
|
let (rf, cf) = (r as f32, c as f32);
|
||||||
let cf = (((c + 144) % 256) as i16 - 128) as f32;
|
|
||||||
if alt == 0.0 {
|
if alt == 0.0 {
|
||||||
verticies.extend_from_slice(
|
verticies.extend_from_slice(
|
||||||
&[Vertex { pos: [ cf + 0., -rf - 1., 0. ], uv: [0., 0.], tileidx: tileidx },
|
&[Vertex { pos: [ cf + 0., -rf - 1., 0. ], uv: [0., 0.], tileidx: tileidx },
|
||||||
@@ -133,6 +134,8 @@ pub struct WorldScene<D: gfx::Device,
|
|||||||
start_time: SystemTime,
|
start_time: SystemTime,
|
||||||
treadmills: (f32, f32),
|
treadmills: (f32, f32),
|
||||||
pads: BTreeMap<u32, (TrackMode, Option<openvr_sys::VRControllerState_t>)>,
|
pads: BTreeMap<u32, (TrackMode, Option<openvr_sys::VRControllerState_t>)>,
|
||||||
|
|
||||||
|
pos: (u8, u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
||||||
@@ -147,7 +150,8 @@ impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
|||||||
let constants = factory.create_constant_buffer(1);
|
let constants = factory.create_constant_buffer(1);
|
||||||
encoder.update_constant_buffer(&constants, &Constants { anim: ANIMDATA,
|
encoder.update_constant_buffer(&constants, &Constants { anim: ANIMDATA,
|
||||||
r1: R1,
|
r1: R1,
|
||||||
r2: R2 });
|
r2: R2,
|
||||||
|
r3: R3});
|
||||||
|
|
||||||
WorldScene {
|
WorldScene {
|
||||||
pso: factory.create_pipeline_simple(VERTEX_SHADER_SRC,
|
pso: factory.create_pipeline_simple(VERTEX_SHADER_SRC,
|
||||||
@@ -167,8 +171,19 @@ impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
|||||||
start_time: SystemTime::now(),
|
start_time: SystemTime::now(),
|
||||||
treadmills: (0.0, 0.0),
|
treadmills: (0.0, 0.0),
|
||||||
pads: BTreeMap::new(),
|
pads: BTreeMap::new(),
|
||||||
|
|
||||||
|
pos: (90, 144),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn toroid((x, y): (u8, u8), r1: f32, r2: f32, r3: f32) -> na::Vector3<f32>
|
||||||
|
{
|
||||||
|
let x: f32 = TWO_PI_CIRC * x as f32;
|
||||||
|
let y: f32 = TWO_PI_CIRC * y as f32;
|
||||||
|
na::Vector3::<f32>::new(r3 * -1.0f32 * x.sin(), // use r3 instead of r2 for "deflated" torus
|
||||||
|
(r1 + r2 * x.cos()) * y.cos(),
|
||||||
|
(r1 + r2 * x.cos()) * y.sin())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ANIMDATA: [u32; 4] =
|
const ANIMDATA: [u32; 4] =
|
||||||
@@ -196,6 +211,22 @@ impl<D: gfx::Device,
|
|||||||
Vr(Untouch { dev_idx, .. }) => {
|
Vr(Untouch { dev_idx, .. }) => {
|
||||||
self.pads.remove(&dev_idx);
|
self.pads.remove(&dev_idx);
|
||||||
},
|
},
|
||||||
|
Piston(Input::Press(Button::Keyboard(Key::Left))) => {
|
||||||
|
self.pos = (self.pos.0.wrapping_sub(1), self.pos.1);
|
||||||
|
println!("x: {}, y: {}", self.pos.0, self.pos.1);
|
||||||
|
},
|
||||||
|
Piston(Input::Press(Button::Keyboard(Key::Right))) => {
|
||||||
|
self.pos = (self.pos.0.wrapping_add(1), self.pos.1);
|
||||||
|
println!("x: {}, y: {}", self.pos.0, self.pos.1);
|
||||||
|
},
|
||||||
|
Piston(Input::Press(Button::Keyboard(Key::Up))) => {
|
||||||
|
self.pos = (self.pos.0, self.pos.1.wrapping_sub(1));
|
||||||
|
println!("x: {}, y: {}", self.pos.0, self.pos.1);
|
||||||
|
},
|
||||||
|
Piston(Input::Press(Button::Keyboard(Key::Down))) => {
|
||||||
|
self.pos = (self.pos.0, self.pos.1.wrapping_add(1));
|
||||||
|
println!("x: {}, y: {}", self.pos.0, self.pos.1);
|
||||||
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,7 +254,7 @@ impl<D: gfx::Device,
|
|||||||
},
|
},
|
||||||
TrackMode::Press => {
|
TrackMode::Press => {
|
||||||
let rot = na::Vector3::new(0.0, 0.0, 0.0);
|
let rot = na::Vector3::new(0.0, 0.0, 0.0);
|
||||||
let speed = R2 * 0.01;
|
let speed = R2 * 0.005;
|
||||||
if state.rAxis[0].x > 0.5 {
|
if state.rAxis[0].x > 0.5 {
|
||||||
self.camera = na::Similarity3::new(na::Vector3::new(-speed, 0.0, 0.0),
|
self.camera = na::Similarity3::new(na::Vector3::new(-speed, 0.0, 0.0),
|
||||||
rot, 1.0).to_homogeneous() * self.camera;
|
rot, 1.0).to_homogeneous() * self.camera;
|
||||||
@@ -248,8 +279,7 @@ impl<D: gfx::Device,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
encoder.update_constant_buffer(&self.locals, &Locals { camera: *(self.camera).as_ref(),
|
encoder.update_constant_buffer(&self.locals, &Locals { millis: millis,
|
||||||
millis: millis,
|
|
||||||
treadmill_x: self.treadmills.0,
|
treadmill_x: self.treadmills.0,
|
||||||
treadmill_y: self.treadmills.1 });
|
treadmill_y: self.treadmills.1 });
|
||||||
}
|
}
|
||||||
@@ -274,9 +304,14 @@ impl<D: gfx::Device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn origin(&self) -> na::Matrix4<f32> {
|
fn origin(&self) -> na::Matrix4<f32> {
|
||||||
na::Similarity3::new(na::Vector3::new(0.0, R1 - R2, 0.0),
|
let (x, y) = (self.pos.0, self.pos.1);
|
||||||
na::Vector3::new(0.0, 0.0, 0.0), 1.0).to_homogeneous()
|
let eye = Self::toroid((x, y), R1, R2, R3);
|
||||||
|
let looktgt = Self::toroid((x, y.wrapping_add(1)), R1, R2, R3);
|
||||||
|
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(),
|
||||||
|
looktgt.as_point(),
|
||||||
|
&normal,
|
||||||
|
).to_homogeneous()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ impl ViewRoot<gfx_device_gl::Device, ColorFormat, DepthFormat> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If running without VR, just draw from some default projection near the scene origin
|
// If running without VR, just draw from some default projection near the scene origin
|
||||||
let head_mat = na::Similarity3::new(na::Vector3::new(0.0, -1.0, 0.0),
|
let head_mat = na::Similarity3::new(na::Vector3::new(0.0, -1.5, 0.0),
|
||||||
na::Vector3::new(0.0, 0.0, 0.0),
|
na::Vector3::new(0.0, 0.0, 0.0),
|
||||||
1.0).to_homogeneous();
|
1.0).to_homogeneous();
|
||||||
let proj_mat = na::PerspectiveMatrix3::new(1.0, 90.0, NEAR, FAR).to_matrix();
|
let proj_mat = na::PerspectiveMatrix3::new(1.0, 90.0, NEAR, FAR).to_matrix();
|
||||||
|
|||||||
Reference in New Issue
Block a user