gdritter repos utmyen / 37c1005
Not quite working yet, but getting closer Getty Ritter 8 years ago
3 changed file(s) with 26 addition(s) and 9 deletion(s). Collapse all Expand all
1 struct Graphics {
2 disp: Display,
3 }
4
5 impl Graphics {
6 fn run(Self) {
7 }
8 }
33 extern crate glium;
44 extern crate image;
55
6 // mod adnot;
7 mod bencode;
86 mod model;
97
108 use glium::{DisplayBuild, Program, Surface};
1412
1513 fn sample() -> model::Model {
1614 let file = std::env::args().nth(1)
17 .unwrap_or("data/test/cube.model".to_string());
15 .unwrap_or("data/test/monkey.utm".to_string());
1816 model::Model::load_from_file(&file).unwrap()
1917 }
2018
6767 pub bytes: vec::IntoIter<u8>,
6868 }
6969
70 #[test]
71 fn reader_tests() {
72 assert!(Reader::from_slice(&[0x00]).read_twip() == Ok(-32.0));
73 assert!(Reader::from_slice(&[0x00]).read_prefix_int() == Ok(0x00));
74 assert!(Reader::from_slice(&[0x7f]).read_prefix_int() == Ok(0x7f));
75 assert!(Reader::from_slice(&[0x80,0xff]).read_prefix_int() == Ok(0xff));
76 }
77
7078 impl Reader {
79 fn from_slice(lst: &[u8]) -> Self {
80 Reader { bytes: lst.to_vec().into_iter() }
81 }
7182 /// This gets the next byte, or fails if it's out of input.
7283 fn next(&mut self) -> Result<u8, String> {
7384 Ok(try!(self.bytes.next().ok_or("out of input")))
116127 fn continue_prefix_int(&mut self, mut left: u8, upper: u8) -> Result<u64, String> {
117128 let mut ret = upper as u64;
118129 while left > 0 {
119 left -= 0;
130 left -= 1;
120131 ret = (ret << 8) | try!(self.next()) as u64;
121132 }
122133 Ok(ret)
125136 /// This reads a single V3D: three twips for the x/y/z, three twips
126137 /// for the normal, and two ratios for the uv coords.
127138 fn read_v3d(&mut self) -> Result<V3D, String> {
128 Ok(V3D { pos: [ try!(self.read_twip()),
129 try!(self.read_twip()),
130 try!(self.read_twip()) ],
139 Ok(V3D { pos: [ try!(self.read_twip()) * 0.1,
140 try!(self.read_twip()) * 0.1,
141 try!(self.read_twip()) * 0.1],
131142 nrm: [ try!(self.read_twip()),
132143 try!(self.read_twip()),
133144 try!(self.read_twip()) ],
143154 {
144155 let ct = try!(self.read_prefix_int());
145156 let mut ret = Vec::with_capacity(ct as usize);
146 for i in 0..ct {
147 ret[i as usize] = try!(reader(self))
157 for _ in 0..ct {
158 ret.push(try!(reader(self)))
148159 }
149160 Ok(ret)
150161 }