properly parameterize world torus radii
This commit is contained in:
@@ -17,8 +17,12 @@ use std::time::SystemTime;
|
||||
|
||||
use gfx::tex;
|
||||
use gfx::traits::FactoryExt;
|
||||
use self::na::ToHomogeneous;
|
||||
use self::num_traits::identities::One;
|
||||
|
||||
const R1: f32 = 4096.0;
|
||||
const R2: f32 = 1024.0;
|
||||
|
||||
gfx_defines! {
|
||||
vertex Vertex {
|
||||
pos: [f32; 3] = "a_pos",
|
||||
@@ -26,10 +30,15 @@ gfx_defines! {
|
||||
tileidx: u32 = "a_tileidx",
|
||||
}
|
||||
|
||||
constant Constants {
|
||||
anim: u32 = "anim",
|
||||
r1: f32 = "R1",
|
||||
r2: f32 = "R2",
|
||||
}
|
||||
|
||||
constant Locals {
|
||||
camera: [[f32; 4]; 4] = "camera",
|
||||
millis: u32 = "millis",
|
||||
anim: u32 = "anim",
|
||||
treadmill_x: f32 = "treadmill_x",
|
||||
treadmill_y: f32 = "treadmill_y",
|
||||
}
|
||||
@@ -37,6 +46,7 @@ gfx_defines! {
|
||||
pipeline pipe {
|
||||
vbuf: gfx::VertexBuffer<Vertex> = (),
|
||||
trans: gfx::ConstantBuffer<::view::Trans> = "b_trans",
|
||||
constants: gfx::ConstantBuffer<Constants> = "b_constants",
|
||||
locals: gfx::ConstantBuffer<Locals> = "b_locals",
|
||||
atlas: gfx::TextureSampler<[f32; 4]> = "t_atlas",
|
||||
pixcolor: gfx::RenderTarget<::view::ColorFormat> = "pixcolor",
|
||||
@@ -79,6 +89,7 @@ pub struct WorldScene<D: gfx::Device,
|
||||
F: gfx::Factory<D::Resources>> {
|
||||
pso: gfx::PipelineState<D::Resources, pipe::Meta>,
|
||||
camera: na::Matrix4<f32>,
|
||||
constants: gfx::handle::Buffer<D::Resources, Constants>,
|
||||
locals: gfx::handle::Buffer<D::Resources, Locals>,
|
||||
atlas: gfx::handle::ShaderResourceView<D::Resources,
|
||||
<view::ColorFormat as gfx::format::Formatted>::View>,
|
||||
@@ -94,17 +105,24 @@ pub struct WorldScene<D: gfx::Device,
|
||||
}
|
||||
|
||||
impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
||||
pub fn new(factory: &mut F) -> WorldScene<D, F> {
|
||||
pub fn new(factory: &mut F,
|
||||
encoder: &mut gfx::Encoder<D::Resources, D::CommandBuffer>) -> WorldScene<D, F> {
|
||||
let (model, model_idx) = get_model(&get_data_model());
|
||||
let (vertex_buffer, slice) =
|
||||
factory.create_vertex_buffer_with_slice(&model, &model_idx[..]);
|
||||
|
||||
let constants = factory.create_constant_buffer(1);
|
||||
encoder.update_constant_buffer(&constants, &Constants { anim: ANIMDATA[0],
|
||||
r1: R1,
|
||||
r2: R2 });
|
||||
|
||||
WorldScene {
|
||||
pso: factory.create_pipeline_simple(VERTEX_SHADER_SRC,
|
||||
FRAGMENT_SHADER_SRC,
|
||||
pipe::new())
|
||||
.expect("create pipeline"),
|
||||
camera: na::Matrix4::one(),
|
||||
constants: constants,
|
||||
locals: factory.create_constant_buffer(1),
|
||||
atlas: tile::get_tiles::<_, _, view::ColorFormat>(factory),
|
||||
sampler: factory.create_sampler(tex::SamplerInfo::new(tex::FilterMethod::Scale,
|
||||
@@ -171,19 +189,19 @@ impl<D: gfx::Device,
|
||||
if ydiff.abs() > THRESHOLD { self.treadmills.1 += SCALE * ydiff; }
|
||||
},
|
||||
TrackMode::PRESS => {
|
||||
use self::na::ToHomogeneous;
|
||||
let rot = na::Vector3::new(0.0, 0.0, 0.0);
|
||||
let speed = R2 * 0.01;
|
||||
if state.rAxis[0].x > 0.5 {
|
||||
self.camera = na::Similarity3::new(na::Vector3::new(-0.5, 0.0, 0.0),
|
||||
self.camera = na::Similarity3::new(na::Vector3::new(-speed, 0.0, 0.0),
|
||||
rot, 1.0).to_homogeneous() * self.camera;
|
||||
} if state.rAxis[0].x < -0.5 {
|
||||
self.camera = na::Similarity3::new(na::Vector3::new( 0.5, 0.0, 0.0),
|
||||
self.camera = na::Similarity3::new(na::Vector3::new( speed, 0.0, 0.0),
|
||||
rot, 1.0).to_homogeneous() * self.camera;
|
||||
} if state.rAxis[0].y > 0.5 {
|
||||
self.camera = na::Similarity3::new(na::Vector3::new( 0.0, -5.0, 0.0),
|
||||
self.camera = na::Similarity3::new(na::Vector3::new( 0.0, -speed, 0.0),
|
||||
rot, 1.0).to_homogeneous() * self.camera;
|
||||
} if state.rAxis[0].y < -0.5 {
|
||||
self.camera = na::Similarity3::new(na::Vector3::new( 0.0, 5.0, 0.0),
|
||||
self.camera = na::Similarity3::new(na::Vector3::new( 0.0, speed, 0.0),
|
||||
rot, 1.0).to_homogeneous() * self.camera;
|
||||
}
|
||||
},
|
||||
@@ -199,7 +217,6 @@ impl<D: gfx::Device,
|
||||
|
||||
encoder.update_constant_buffer(&self.locals, &Locals { camera: *(self.camera).as_ref(),
|
||||
millis: millis,
|
||||
anim: ANIMDATA[0],
|
||||
treadmill_x: self.treadmills.0,
|
||||
treadmill_y: self.treadmills.1 });
|
||||
}
|
||||
@@ -214,6 +231,7 @@ impl<D: gfx::Device,
|
||||
let pipe = pipe::Data {
|
||||
vbuf: self.vbuf.clone(),
|
||||
trans: trans.clone(),
|
||||
constants: self.constants.clone(),
|
||||
locals: self.locals.clone(),
|
||||
atlas: (self.atlas.clone(), self.sampler.clone()),
|
||||
pixcolor: target.clone(),
|
||||
@@ -221,6 +239,12 @@ impl<D: gfx::Device,
|
||||
};
|
||||
encoder.draw(&self.slice, &self.pso, &pipe);
|
||||
}
|
||||
|
||||
fn origin(&self) -> na::Matrix4<f32> {
|
||||
na::Similarity3::new(na::Vector3::new(0.0, R1 - R2, 0.0),
|
||||
na::Vector3::new(0.0, 0.0, 0.0), 1.0).to_homogeneous()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extern crate memmap;
|
||||
@@ -252,10 +276,15 @@ const VERTEX_SHADER_SRC: &'static [u8] = br#"
|
||||
uniform b_trans {
|
||||
mat4 u_matrix;
|
||||
};
|
||||
uniform b_constants {
|
||||
//uvec4 animdata;
|
||||
uint animdata;
|
||||
float R1;
|
||||
float R2;
|
||||
};
|
||||
uniform b_locals {
|
||||
mat4 camera;
|
||||
uint millis;
|
||||
uint animdata;
|
||||
float treadmill_x;
|
||||
float treadmill_y;
|
||||
};
|
||||
@@ -264,21 +293,19 @@ const VERTEX_SHADER_SRC: &'static [u8] = br#"
|
||||
v_uv = a_uv;
|
||||
v_tileidx = a_tileidx;
|
||||
float TWO_PI_CIRC = 2 * PI / 256.0;
|
||||
float R = 1024.0;
|
||||
float R2 = 128.0;
|
||||
|
||||
gl_Position = u_matrix * camera * vec4(R2 * -1.0 * sin(TWO_PI_CIRC * (a_pos.x + treadmill_x)),
|
||||
(R + R2 * cos(TWO_PI_CIRC * (a_pos.x + treadmill_x))) * cos(TWO_PI_CIRC * (a_pos.z + treadmill_y)),
|
||||
(R + R2 * cos(TWO_PI_CIRC * (a_pos.x + treadmill_x))) * sin(TWO_PI_CIRC * (a_pos.z + treadmill_y)),
|
||||
(R1 + R2 * cos(TWO_PI_CIRC * (a_pos.x + treadmill_x))) * cos(TWO_PI_CIRC * (a_pos.z + treadmill_y)),
|
||||
(R1 + R2 * cos(TWO_PI_CIRC * (a_pos.x + treadmill_x))) * sin(TWO_PI_CIRC * (a_pos.z + treadmill_y)),
|
||||
1.0);
|
||||
|
||||
/*
|
||||
float which = (1.0 + sin(float(millis) / 5000.)) / 2.0;
|
||||
gl_Position = u_matrix * vec4(a_pos.x,
|
||||
R * cos(TWO_PI_CIRC * a_pos.z),
|
||||
which * a_pos.z +
|
||||
((1.0-which) * R * sin(TWO_PI_CIRC * a_pos.z)),
|
||||
1.0);
|
||||
gl_Position = u_matrix * camera * vec4(a_pos.x,
|
||||
R1 * cos(TWO_PI_CIRC * a_pos.z),
|
||||
which * a_pos.z +
|
||||
((1.0-which) * R1 * sin(TWO_PI_CIRC * a_pos.z)),
|
||||
1.0);
|
||||
*/
|
||||
}
|
||||
"#;
|
||||
@@ -290,11 +317,15 @@ const FRAGMENT_SHADER_SRC: &'static [u8] = br#"
|
||||
flat in uint v_tileidx;
|
||||
out vec4 pixcolor;
|
||||
uniform sampler2D t_atlas;
|
||||
uniform b_constants {
|
||||
//uvec4 animdata;
|
||||
uint animdata;
|
||||
float R1;
|
||||
float R2;
|
||||
};
|
||||
uniform b_locals {
|
||||
mat4 camera;
|
||||
uint millis;
|
||||
//uvec4 animdata;
|
||||
uint animdata;
|
||||
float treadmill_x;
|
||||
float treadmill_y;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user