13 | 13 |
// use bencode::Bencode;
|
14 | 14 |
|
15 | 15 |
fn sample() -> model::Model {
|
16 | |
model::Model::load_from_file("data/test/cube.model").unwrap()
|
| 16 |
let file = std::env::args().nth(1)
|
| 17 |
.unwrap_or("data/test/cube.model".to_string());
|
| 18 |
model::Model::load_from_file(&file).unwrap()
|
17 | 19 |
}
|
18 | 20 |
|
19 | 21 |
const VERTEX_SHADER: &'static str = r#"
|
|
44 | 46 |
let md = sample();
|
45 | 47 |
let display = WindowBuilder::new()
|
46 | 48 |
.with_title(format!("utymen"))
|
| 49 |
.with_depth_buffer(24)
|
47 | 50 |
.build_glium()
|
48 | 51 |
.unwrap();
|
49 | 52 |
let vbuf = md.get_vbuf(&display);
|
|
54 | 57 |
FRAGMENT_SHADER,
|
55 | 58 |
None).unwrap();
|
56 | 59 |
|
57 | |
|
58 | 60 |
let mut px = 0f32;
|
59 | |
let mut py = 0f32;
|
60 | |
let mut t = 0f32;
|
| 61 |
let mut py = 0.02f32;
|
| 62 |
let mut rt = 0f32;
|
61 | 63 |
let dx = 0.001;
|
62 | 64 |
let sx = 0.01f32;
|
| 65 |
|
63 | 66 |
loop {
|
64 | |
t += 0.01;
|
65 | 67 |
let mut target = display.draw();
|
66 | 68 |
|
67 | 69 |
let perspective = {
|
|
79 | 81 |
[ 0.0 , f , 0.0 , 0.0],
|
80 | 82 |
[ 0.0 , 0.0, (zfar+znear)/(zfar-znear) , 1.0],
|
81 | 83 |
[ 0.0 , 0.0, -(2.0*zfar*znear)/(zfar-znear), 0.0],
|
82 | |
]
|
| 84 |
]
|
83 | 85 |
};
|
| 86 |
|
84 | 87 |
let uniforms = uniform! {
|
85 | 88 |
perspective: perspective,
|
86 | |
matrix: [ [sx, 0.0, 0.0, 0.0],
|
87 | |
[0.0, t.cos() * sx, -t.sin() * sx, 0.0],
|
88 | |
[0.0, t.sin() * sx, t.cos() * sx, 0.0],
|
89 | |
[px, 0.0, py, sx]
|
| 89 |
matrix: [ [ rt.cos() * sx, 0.0, -rt.sin() * sx, 0.0 ],
|
| 90 |
[ 0.0, sx, 0.0, 0.0 ],
|
| 91 |
[ rt.sin() * sx, 0.0, rt.cos() * sx, 0.0 ],
|
| 92 |
[ px, 0.0, py, sx ]
|
90 | 93 |
]
|
91 | 94 |
};
|
92 | |
// let params = glium::DrawParameters {
|
93 | |
// depth: glium::Depth {
|
94 | |
// test: glium::draw_parameters::DepthTest::IfLess,
|
95 | |
// write: true,
|
96 | |
// .. Default::default()
|
97 | |
// },
|
98 | |
// .. Default::default()
|
99 | |
// };
|
100 | |
target.clear_color(0.0, 0.0, 0.0, 1.0);
|
| 95 |
|
| 96 |
let params = glium::DrawParameters {
|
| 97 |
depth: glium::Depth {
|
| 98 |
test: glium::draw_parameters::DepthTest::IfLess,
|
| 99 |
write: true,
|
| 100 |
.. Default::default()
|
| 101 |
},
|
| 102 |
.. Default::default()
|
| 103 |
};
|
| 104 |
|
| 105 |
target.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0);
|
101 | 106 |
target.draw(&vbuf,
|
102 | 107 |
&idxs,
|
103 | 108 |
&program,
|
104 | 109 |
&uniforms,
|
105 | |
&Default::default()).unwrap();
|
| 110 |
¶ms).unwrap();
|
106 | 111 |
target.finish().unwrap();
|
| 112 |
|
107 | 113 |
for ev in display.poll_events() {
|
108 | 114 |
match ev {
|
109 | 115 |
Event::Closed => return,
|
110 | 116 |
Event::KeyboardInput(_, 9, _) => return,
|
| 117 |
Event::KeyboardInput(_, 24, _) => {
|
| 118 |
rt -= 0.1;
|
| 119 |
},
|
111 | 120 |
Event::KeyboardInput(_, 25, _) => {
|
112 | 121 |
py -= dx;
|
| 122 |
},
|
| 123 |
Event::KeyboardInput(_, 26, _) => {
|
| 124 |
rt += 0.1;
|
113 | 125 |
},
|
114 | 126 |
Event::KeyboardInput(_, 38, _) => {
|
115 | 127 |
px -= dx;
|